UNPKG

graphql

Version:

A Query Language and Runtime which can target any service.

52 lines (41 loc) 1.55 kB
/* @flow */ /** * Copyright (c) 2015, Facebook, Inc. * 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. */ 'use strict'; var _Object$defineProperty = require('babel-runtime/core-js/object/define-property')['default']; var _Object$keys = require('babel-runtime/core-js/object/keys')['default']; _Object$defineProperty(exports, '__esModule', { value: true }); exports['default'] = NoOutputTypesAsInputArgs; var _error = require('../../error'); var _definition = require('../definition'); function NoOutputTypesAsInputArgs(context) { var schema = context.getSchema(); var typeMap = schema.getTypeMap(); var errors = []; _Object$keys(typeMap).forEach(function (typeName) { var type = typeMap[typeName]; if (!(type instanceof _definition.GraphQLInputObjectType)) { return; } var fields = type.getFields(); _Object$keys(fields).forEach(function (fieldName) { var field = fields[fieldName]; if (!(0, _definition.isInputType)(field.type)) { errors.push(outputArgError(type, field)); } }); }); return errors.length > 0 ? errors : null; } function outputArgError(type, field) { return new _error.GraphQLError('Input field ' + type.name + '.' + field.name + ' has type ' + ('' + field.type + ', which is not an input type!')); } module.exports = exports['default'];