Skip to content

Unify optional callbacks validation #1411

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

Merged
merged 1 commit into from
Jul 29, 2018

Conversation

IvanGoncharov
Copy link
Member

No description provided.

Copy link
Contributor

@mjmahone mjmahone left a comment

Choose a reason for hiding this comment

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

The actual error message changes seem great!

@@ -757,11 +756,6 @@ function isPlainObj(obj) {
return obj && typeof obj === 'object' && !Array.isArray(obj);
}

// If a resolver is defined, it must be a function.
function isValidResolver(resolver: mixed): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep isValidResolver? I'm not totally sure what the advantage of inlining it is

Copy link
Member Author

@IvanGoncharov IvanGoncharov Jul 29, 2018

Choose a reason for hiding this comment

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

One reason would be that you can't share it without changing the name since isTypeOf not a resolver. Plus it also confusing since null and undefined are not valid resolvers but an explicit absence of resolver.

So the best name that I come up is isOptionalFunction which is the same as to just write resolver == null || typeof resolver === 'function'.
I think it's better to stay explicit.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a reasonable argument. I'm convinced.

);
}
invariant(
config.resolveType == null || typeof config.resolveType === 'function',
Copy link
Contributor

Choose a reason for hiding this comment

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

All of these could now become isValidResolver

@IvanGoncharov IvanGoncharov merged commit 3124fa3 into graphql:master Jul 29, 2018
@IvanGoncharov IvanGoncharov deleted the isMaybeFunction branch August 6, 2018 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants