UNPKG

@platformos/pos-cli

Version:

Manage your platformOS application

35 lines (32 loc) 1.05 kB
/** * Copyright (c) 2019 GraphQL Contributors * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ import { typeFromAST } from 'graphql'; /** * Provided a schema and a document, produces a `variableToType` Object. */ export default 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; } }); } } }); return variableToType; }