UNPKG

@platformos/pos-cli

Version:

Manage your platformOS application

43 lines (37 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = collectVariables; var _graphql = require("graphql"); /** * 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. */ /** * Provided a schema and a document, produces a `variableToType` Object. */ 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 = (0, _graphql.typeFromAST)(schema, type); if (inputType) { variableToType[variable.name.value] = inputType; } }); } } }); return variableToType; }