-
Notifications
You must be signed in to change notification settings - Fork 2k
Remove definition iteration from 'ExecutableDefinitions' rule #1466
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,11 @@ | |
import type { ASTValidationContext } from '../ValidationContext'; | ||
import { GraphQLError } from '../../error/GraphQLError'; | ||
import { Kind } from '../../language/kinds'; | ||
import { isExecutableDefinitionNode } from '../../language/predicates'; | ||
import { | ||
isDefinitionNode, | ||
isExecutableDefinitionNode, | ||
} from '../../language/predicates'; | ||
import type { ASTNode } from '../../language/ast'; | ||
import type { ASTVisitor } from '../../language/visitor'; | ||
|
||
export function nonExecutableDefinitionMessage(defName: string): string { | ||
|
@@ -27,23 +31,26 @@ export function ExecutableDefinitions( | |
context: ASTValidationContext, | ||
): ASTVisitor { | ||
return { | ||
Document(node) { | ||
for (const definition of node.definitions) { | ||
if (!isExecutableDefinitionNode(definition)) { | ||
enter(node) { | ||
if (isDefinitionNode(node)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can combine these into a single if statement:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually no, since you need to return false if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah you're right, I missed the |
||
if (!isExecutableDefinitionNode(node)) { | ||
context.reportError( | ||
new GraphQLError( | ||
nonExecutableDefinitionMessage( | ||
definition.kind === Kind.SCHEMA_DEFINITION || | ||
definition.kind === Kind.SCHEMA_EXTENSION | ||
? 'schema' | ||
: definition.name.value, | ||
isSchemaNode(node) ? 'schema' : node.name.value, | ||
), | ||
[definition], | ||
node, | ||
), | ||
); | ||
} | ||
return false; | ||
} | ||
return false; | ||
}, | ||
}; | ||
} | ||
|
||
function isSchemaNode(node: ASTNode): boolean %checks { | ||
return ( | ||
node.kind === Kind.SCHEMA_DEFINITION || node.kind === Kind.SCHEMA_EXTENSION | ||
); | ||
} |
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.
@mjmahone I was searching for non-SDL examples of iterating over all definition pattern and found this 😄