Skip to content
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

Merged
merged 2 commits into from
Jan 3, 2022

Conversation

pcmanus
Copy link
Contributor

@pcmanus pcmanus commented Dec 14, 2021

This is a rebased and modified version of apollographql/apollo-server#3914. The differences with that earlier PR are that:

  1. it provides a tad more test coverage, but also use tests that don't reuse existing fixtures (I happen to think that having common fixtures reused by all tests is not a good idea, and that has created issues in the past, so I'm advocating from moving away from doing so).
  2. the fix is slightly different because:
  • it doesn't log an error in 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.
  • it uses a return null instead of a break: 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 what return null does. Using break 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 with null values (I added tests that show it's the case).

@pcmanus
Copy link
Contributor Author

pcmanus commented Dec 16, 2021

@trevor-scheer wouldn't mind your opinion here since you followed earlier iterations of this.

Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines +1679 to +1702
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}` };
}
}
});
Copy link
Member

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 };

@pcmanus pcmanus merged commit da621ae into apollographql:version-0.x Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Federation: Undefined behaviour and INTERNAL_SERVER_ERROR when returning external types that do not exist
3 participants