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

Add resolver validation options for Interface and Union types #698

Merged

Conversation

reconbot
Copy link
Contributor

@reconbot reconbot commented Mar 28, 2018

TODO:

  • If this PR is a new feature, reference an issue where a consensus about the design was reached.

No consensus yet, but this is a precursor to closing #616 and removes an internal TODO. Exact validation options are up for debate.

  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change. Include a description of your change, link to PR (always) and issue (if applicable). Add your CHANGELOG entry under vNEXT. Do not create a new version number for your change yourself.
  • requireResolversForResolveType will require a resolveType() method for Interface and Union types. This can be passed in with the field resolvers as __resolveType()

This doesn't do anything on graphql@0.11 because it provides a default resolveType. That's ok.

@ghost ghost added the feature New addition or enhancement to existing solutions label Mar 28, 2018
@reconbot reconbot force-pushed the interface-union-resolver-validation branch from 8de28e7 to 7ff7f66 Compare March 28, 2018 19:52
@ghost ghost added the feature New addition or enhancement to existing solutions label Mar 28, 2018

// If we have any union or interface types throw if no there is no resolveType or isTypeOf resolvers
if (requireResolversForResolveType) {
checkForResolveTypeResolver(schema);
Copy link
Contributor

@benjamn benjamn Mar 28, 2018

Choose a reason for hiding this comment

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

What if we inverted the option so that a missing resolveType caused a warning by default, but you could pass resolverValidationOptions.allowMissingResolveType (or something like that) to disable the warning?

I'm worried no one is going to know they should start passing requireResolversForResolveType: true, so they won't ever see this warning.

@reconbot
Copy link
Contributor Author

reconbot commented Mar 28, 2018 via email

@benjamn
Copy link
Contributor

benjamn commented Mar 28, 2018

What if passing requireResolversForResolveType makes it throw on failure (like this PR does), but you get a warning (at least in development?) if you don't pass that option, and the only way to silence the error is to pass requireResolversForResolveType: false?

@reconbot
Copy link
Contributor Author

reconbot commented Mar 28, 2018 via email

@reconbot reconbot force-pushed the interface-union-resolver-validation branch from e794e55 to 08ef12f Compare March 28, 2018 23:56
@reconbot
Copy link
Contributor Author

How's this? I added the warning, unsurprisingly it spams the test suite a bit.

@reconbot reconbot force-pushed the interface-union-resolver-validation branch from 08ef12f to b49f74a Compare March 29, 2018 00:13
@stubailo
Copy link
Contributor

For what it's worth, when we used to have all the validations turned on back in the day but they felt restricting to many (most?) people.

@reconbot reconbot force-pushed the interface-union-resolver-validation branch 2 times, most recently from c0792ff to d7feecb Compare April 1, 2018 16:14
@reconbot
Copy link
Contributor Author

reconbot commented Apr 1, 2018

rebased off of master and squashed my commits, lmk if there's anything else that needs to happen on this as I want to get working on #616

@zfoster
Copy link

zfoster commented Apr 4, 2018

Very interested in this getting merged in. Is this now just waiting on conflicts being resolved?

- Warns when it is not disabled
- Throws when it's enabled
@reconbot reconbot force-pushed the interface-union-resolver-validation branch from d7feecb to bd8858a Compare April 5, 2018 12:11
@reconbot
Copy link
Contributor Author

reconbot commented Apr 5, 2018

I've rebased the changes again.

@vepanimas
Copy link

@reconbot @benjamn what if all types that implement an interface have their own isTypeof method? It will generate an error but IMHO it should not because all types are correctly resolved at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New addition or enhancement to existing solutions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants