Skip to content

Conversation

IvanGoncharov
Copy link
Member

@IvanGoncharov IvanGoncharov commented Aug 9, 2018

For SDL validation rules I need to distinguish type definition node from type extension nodes.
+ I saw same in couple other projects, e.g. relay:
https://github.com/facebook/relay/blob/04aac482538b83548c25e878205ecc1a581bcb25/packages/graphql-compiler/core/GraphQLSchemaUtils.js#L198-L203

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.

I think you have just this one error.

I do think we want these utilities, so I'm happy if we add them. And I don't see any issues with how you've named them: it's pretty straightforward and easy to guess correctly once you know one of them exists.

import type { ASTNode } from './ast';
import { Kind } from './kinds';

export function isDefinitionNode(node: ASTNode): boolean %checks {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a big fan of these! We hit them a lot, and it's nice to be able to filter through definitions to just get Executable or TypeSystem definitions!

definition.kind !== Kind.OPERATION_DEFINITION &&
definition.kind !== Kind.FRAGMENT_DEFINITION
) {
if (!isExecutableDefinitionNode(node)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The flow error here is because you're asking if the Document is an ExecutableDefinitionNode rather than asking if the definition is.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mjmahone Fixed. Thanks.

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.

Looks great! Thanks for pulling these out.

@IvanGoncharov IvanGoncharov merged commit 4fd9260 into graphql:master Aug 10, 2018
@IvanGoncharov IvanGoncharov deleted the addNodePredicates branch August 10, 2018 14:50
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