Sha256: 22697355924bba60c6ced78c77c42da85bf3a61dbbb4c2cba0da2115a7cf624c
Contents?: true
Size: 1.01 KB
Versions: 26
Compression:
Stored size: 1.01 KB
Contents
import { GraphQLError } from '../../error/GraphQLError.mjs'; import { print } from '../../language/printer.mjs'; import { isInputType } from '../../type/definition.mjs'; import { typeFromAST } from '../../utilities/typeFromAST.mjs'; /** * Variables are input types * * A GraphQL operation is only valid if all the variables it defines are of * input types (scalar, enum, or input object). * * See https://spec.graphql.org/draft/#sec-Variables-Are-Input-Types */ export function VariablesAreInputTypesRule(context) { return { VariableDefinition(node) { const type = typeFromAST(context.getSchema(), node.type); if (type !== undefined && !isInputType(type)) { const variableName = node.variable.name.value; const typeName = print(node.type); context.reportError( new GraphQLError( `Variable "$${variableName}" cannot be non-input type "${typeName}".`, { nodes: node.type, }, ), ); } }, }; }
Version data entries
26 entries across 26 versions & 1 rubygems