UNPKG

graphql-language-service-utils

Version:
24 lines 1.02 kB
import { typeFromAST, GraphQLFloat, Kind, } from 'graphql'; export function collectVariables(schema, documentAST) { const variableToType = Object.create(null); documentAST.definitions.forEach(definition => { if (definition.kind === 'OperationDefinition') { const variableDefinitions = definition.variableDefinitions; if (variableDefinitions) { variableDefinitions.forEach(({ variable, type }) => { const inputType = typeFromAST(schema, type); if (inputType) { variableToType[variable.name.value] = inputType; } else if (type.kind === Kind.NAMED_TYPE) { if (type.name.value === 'Float') { variableToType[variable.name.value] = GraphQLFloat; } } }); } } }); return variableToType; } //# sourceMappingURL=collectVariables.js.map