Throw on undefined root fields#632
Conversation
84c3974 to
d8db64e
Compare
| const isDefaultResolverUsed = | ||
| resolveFn === exeContext.fieldResolver || fieldName === "__typename"; | ||
|
|
||
| if (resolveFn === exeContext.fieldResolver) { |
There was a problem hiding this comment.
There is one tricky use-case breaking with this change. Technically executor can work without custom resolvers at all - only with default resolver (e.g. with projects like Grats)
I.e. you can pass some instance as rootValue and it's methods act as resolvers. This case is handled by default resolver. See:
https://github.com/user1736/graphitation/blob/d8db64e68d5728f7de149bf009a2f66350df6ede/packages/supermassive/src/executeWithoutSchema.ts#L2348-L2350
We should account for this case and only throw if there is no "source":
| if (resolveFn === exeContext.fieldResolver) { | |
| if (resolveFn === exeContext.fieldResolver && typeof source === "undefined") { |
| const isRootField = | ||
| parentTypeName === "Mutation" || parentTypeName === "Query"; |
There was a problem hiding this comment.
Subscription? Alternatively we can just check path.length === 0 once
There was a problem hiding this comment.
Subscriptions have a separate execution and this function is not called there.
As for the path, it's probably not what you think it is. For example, for new test cases I get:
{
"prev": undefined,
"key": "downloadFile",
"typename": "Mutation"
}There was a problem hiding this comment.
Ah, right, path is an array is in graphql-js, we changed it to linked list for perf I guess. In our case it's just !path.prev. But whatever, this works too.
d8db64e to
2c35ba6
Compare
Introduces a change that makes execution throw if you try to run a query/mutation without definition.