Spaces:
Paused
Paused
Download node_modules/graphql/validation/rules/LoneAnonymousOperationRule.mjs from sam522/GenAI_Course: direct link, hf CLI and curl.
- Browser
- Download file 947 Bytes
-
https://huggingface.co/spaces/sam522/GenAI_Course/resolve/2fd35fe0dbbccdd816285ca3b098a170940cfdef/node_modules/graphql/validation/rules/LoneAnonymousOperationRule.mjs
- Command line
-
hf download hf://spaces/sam522/GenAI_Course@2fd35fe0dbbccdd816285ca3b098a170940cfdef/node_modules/graphql/validation/rules/LoneAnonymousOperationRule.mjs
-
curl -L -o LoneAnonymousOperationRule.mjs https://huggingface.co/spaces/sam522/GenAI_Course/resolve/2fd35fe0dbbccdd816285ca3b098a170940cfdef/node_modules/graphql/validation/rules/LoneAnonymousOperationRule.mjs
947 Bytes
| import { GraphQLError } from '../../error/GraphQLError.mjs'; | |
| import { Kind } from '../../language/kinds.mjs'; | |
| /** | |
| * Lone anonymous operation | |
| * | |
| * A GraphQL document is only valid if when it contains an anonymous operation | |
| * (the query short-hand) that it contains only that one operation definition. | |
| * | |
| * See https://spec.graphql.org/draft/#sec-Lone-Anonymous-Operation | |
| */ | |
| export function LoneAnonymousOperationRule(context) { | |
| let operationCount = 0; | |
| return { | |
| Document(node) { | |
| operationCount = node.definitions.filter( | |
| (definition) => definition.kind === Kind.OPERATION_DEFINITION, | |
| ).length; | |
| }, | |
| OperationDefinition(node) { | |
| if (!node.name && operationCount > 1) { | |
| context.reportError( | |
| new GraphQLError( | |
| 'This anonymous operation must be the only defined operation.', | |
| { | |
| nodes: node, | |
| }, | |
| ), | |
| ); | |
| } | |
| }, | |
| }; | |
| } | |