-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure error resolving an entity don't impact resolvable ones (for version-0.x
branch)
#1305
Conversation
@trevor-scheer wouldn't mind your opinion here since you followed earlier iterations of this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
addResolversToSchema(serviceMap['S1'].schema, { | ||
T1: { | ||
__resolveReference(ref) { | ||
return s1_data[ref.id]; | ||
}, | ||
}, | ||
}); | ||
|
||
addResolversToSchema(serviceMap['S2'].schema, { | ||
Query: { | ||
getT1s() { | ||
return [{id: 0}, {id: 1}, {id: 2}]; | ||
}, | ||
}, | ||
T1: { | ||
__resolveReference(ref) { | ||
// the ref has already the id and f1 is a require is triggered, and we resolve f2 below | ||
return ref; | ||
}, | ||
f2(o) { | ||
return o.f1 === null ? null : { a: `t1:${o.f1}` }; | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing wrong here, but these resolvers can be added to the fixture object itself i.e.
const s1 = { name, typeDefs, resolvers };
Fixes apollographql#376 Co-authored-by: Sylvain Lebresne <[email protected]>
This is a rebased and modified version of apollographql/apollo-server#3914. The differences with that earlier PR are that:
executeSelectionSet
anymore: the reasoning (explained in a comment in the code) is that another error has already been logged and that error has more context, so adding a new error is redundant and I think it's confusing because that particular error lacks context and so doesn't really tell you what the problem is. So at best, you happen to know it's just a consequence of a previous error and ignore it, but better not have it then.return null
instead of abreak
: I personally think that it's unreasonable that when you require a non-nullable field then you may actually have to resolve without that required field. If you knew how to do that, then you wouldn't a@require
for that field in the first place. So if you can't get all the requires of fetch (and thus, in particular, of a@require
), then I think we should simply not do that fetch for the entity at all, which is whatreturn null
does. Usingbreak
instead means we'd attempt the fetch nonetheless but with only parts of the inputs present. Note that if a required field is nullable, then this code don't get trigger and we correctly do the fetch withnull
values (I added tests that show it's the case).