-
-
Notifications
You must be signed in to change notification settings - Fork 816
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
Add resolver validation options for Interface and Union types #698
Conversation
8de28e7
to
7ff7f66
Compare
src/schemaGenerator.ts
Outdated
|
||
// If we have any union or interface types throw if no there is no resolveType or isTypeOf resolvers | ||
if (requireResolversForResolveType) { | ||
checkForResolveTypeResolver(schema); |
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.
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.
I'd much rather throw than log because logging in a production can be
complated. This library has examples of both. I think all validations
should be on by default but that's a major change.
…On Wed, Mar 28, 2018, 6:56 PM Ben Newman ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/schemaGenerator.ts
<#698 (comment)>
:
> @@ -460,6 +463,24 @@ function addResolveFunctionsToSchema(
}
});
});
+
+ // If we have any union or interface types throw if no there is no resolveType or isTypeOf resolvers
+ if (requireResolversForResolveType) {
+ checkForResolveTypeResolver(schema);
What if we inverted the option so that a missing resolveType caused a
warning, 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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#698 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABlbudittDHFKGe7slJ2BGgZCMeAdYVks5tjBUrgaJpZM4S-vzu>
.
|
What if passing |
That's an interesting pattern. I kind of like it.
…On Wed, Mar 28, 2018, 7:15 PM Ben Newman ***@***.***> wrote:
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?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#698 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABlbtkxZc0R5sDIcEx1xxX6jGjoKMPKks5tjBmegaJpZM4S-vzu>
.
|
e794e55
to
08ef12f
Compare
How's this? I added the warning, unsurprisingly it spams the test suite a bit. |
08ef12f
to
b49f74a
Compare
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. |
c0792ff
to
d7feecb
Compare
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 |
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
d7feecb
to
bd8858a
Compare
I've rebased the changes again. |
TODO:
No consensus yet, but this is a precursor to closing #616 and removes an internal TODO. Exact validation options are up for debate.
requireResolversForResolveType
will require aresolveType()
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.