├── LICENSE ├── PATENTS ├── README.md ├── error ├── GraphQLError.js ├── GraphQLError.js.flow ├── GraphQLError.js.map ├── formatError.js ├── formatError.js.flow ├── formatError.js.map ├── index.js ├── index.js.flow ├── index.js.map ├── locatedError.js ├── locatedError.js.flow ├── locatedError.js.map ├── syntaxError.js ├── syntaxError.js.flow └── syntaxError.js.map ├── execution ├── execute.js ├── execute.js.flow ├── execute.js.map ├── index.js ├── index.js.flow ├── index.js.map ├── values.js ├── values.js.flow └── values.js.map ├── graphql.js ├── graphql.js.flow ├── graphql.js.map ├── index.js ├── index.js.flow ├── index.js.map ├── jsutils ├── find.js ├── find.js.flow ├── find.js.map ├── invariant.js ├── invariant.js.flow ├── invariant.js.map ├── isNullish.js ├── isNullish.js.flow ├── isNullish.js.map ├── keyMap.js ├── keyMap.js.flow ├── keyMap.js.map ├── keyValMap.js ├── keyValMap.js.flow ├── keyValMap.js.map ├── quotedOrList.js ├── quotedOrList.js.flow ├── quotedOrList.js.map ├── suggestionList.js ├── suggestionList.js.flow └── suggestionList.js.map ├── language ├── ast.js ├── ast.js.flow ├── ast.js.map ├── index.js ├── index.js.flow ├── index.js.map ├── kinds.js ├── kinds.js.flow ├── kinds.js.map ├── lexer.js ├── lexer.js.flow ├── lexer.js.map ├── location.js ├── location.js.flow ├── location.js.map ├── parser.js ├── parser.js.flow ├── parser.js.map ├── printer.js ├── printer.js.flow ├── printer.js.map ├── source.js ├── source.js.flow ├── source.js.map ├── visitor.js ├── visitor.js.flow └── visitor.js.map ├── package.json ├── type ├── definition.js ├── definition.js.flow ├── definition.js.map ├── directives.js ├── directives.js.flow ├── directives.js.map ├── index.js ├── index.js.flow ├── index.js.map ├── introspection.js ├── introspection.js.flow ├── introspection.js.map ├── scalars.js ├── scalars.js.flow ├── scalars.js.map ├── schema.js ├── schema.js.flow └── schema.js.map ├── utilities ├── TypeInfo.js ├── TypeInfo.js.flow ├── TypeInfo.js.map ├── assertValidName.js ├── assertValidName.js.flow ├── assertValidName.js.map ├── astFromValue.js ├── astFromValue.js.flow ├── astFromValue.js.map ├── buildASTSchema.js ├── buildASTSchema.js.flow ├── buildASTSchema.js.map ├── buildClientSchema.js ├── buildClientSchema.js.flow ├── buildClientSchema.js.map ├── concatAST.js ├── concatAST.js.flow ├── concatAST.js.map ├── extendSchema.js ├── extendSchema.js.flow ├── extendSchema.js.map ├── getOperationAST.js ├── getOperationAST.js.flow ├── getOperationAST.js.map ├── index.js ├── index.js.flow ├── index.js.map ├── introspectionQuery.js ├── introspectionQuery.js.flow ├── introspectionQuery.js.map ├── isValidJSValue.js ├── isValidJSValue.js.flow ├── isValidJSValue.js.map ├── isValidLiteralValue.js ├── isValidLiteralValue.js.flow ├── isValidLiteralValue.js.map ├── schemaPrinter.js ├── schemaPrinter.js.flow ├── schemaPrinter.js.map ├── separateOperations.js ├── separateOperations.js.flow ├── separateOperations.js.map ├── typeComparators.js ├── typeComparators.js.flow ├── typeComparators.js.map ├── typeFromAST.js ├── typeFromAST.js.flow ├── typeFromAST.js.map ├── valueFromAST.js ├── valueFromAST.js.flow └── valueFromAST.js.map └── validation ├── index.js ├── index.js.flow ├── index.js.map ├── rules ├── ArgumentsOfCorrectType.js ├── ArgumentsOfCorrectType.js.flow ├── ArgumentsOfCorrectType.js.map ├── DefaultValuesOfCorrectType.js ├── DefaultValuesOfCorrectType.js.flow ├── DefaultValuesOfCorrectType.js.map ├── FieldsOnCorrectType.js ├── FieldsOnCorrectType.js.flow ├── FieldsOnCorrectType.js.map ├── FragmentsOnCompositeTypes.js ├── FragmentsOnCompositeTypes.js.flow ├── FragmentsOnCompositeTypes.js.map ├── KnownArgumentNames.js ├── KnownArgumentNames.js.flow ├── KnownArgumentNames.js.map ├── KnownDirectives.js ├── KnownDirectives.js.flow ├── KnownDirectives.js.map ├── KnownFragmentNames.js ├── KnownFragmentNames.js.flow ├── KnownFragmentNames.js.map ├── KnownTypeNames.js ├── KnownTypeNames.js.flow ├── KnownTypeNames.js.map ├── LoneAnonymousOperation.js ├── LoneAnonymousOperation.js.flow ├── LoneAnonymousOperation.js.map ├── NoFragmentCycles.js ├── NoFragmentCycles.js.flow ├── NoFragmentCycles.js.map ├── NoUndefinedVariables.js ├── NoUndefinedVariables.js.flow ├── NoUndefinedVariables.js.map ├── NoUnusedFragments.js ├── NoUnusedFragments.js.flow ├── NoUnusedFragments.js.map ├── NoUnusedVariables.js ├── NoUnusedVariables.js.flow ├── NoUnusedVariables.js.map ├── OverlappingFieldsCanBeMerged.js ├── OverlappingFieldsCanBeMerged.js.flow ├── OverlappingFieldsCanBeMerged.js.map ├── PossibleFragmentSpreads.js ├── PossibleFragmentSpreads.js.flow ├── PossibleFragmentSpreads.js.map ├── ProvidedNonNullArguments.js ├── ProvidedNonNullArguments.js.flow ├── ProvidedNonNullArguments.js.map ├── ScalarLeafs.js ├── ScalarLeafs.js.flow ├── ScalarLeafs.js.map ├── UniqueArgumentNames.js ├── UniqueArgumentNames.js.flow ├── UniqueArgumentNames.js.map ├── UniqueFragmentNames.js ├── UniqueFragmentNames.js.flow ├── UniqueFragmentNames.js.map ├── UniqueInputFieldNames.js ├── UniqueInputFieldNames.js.flow ├── UniqueInputFieldNames.js.map ├── UniqueOperationNames.js ├── UniqueOperationNames.js.flow ├── UniqueOperationNames.js.map ├── UniqueVariableNames.js ├── UniqueVariableNames.js.flow ├── UniqueVariableNames.js.map ├── VariablesAreInputTypes.js ├── VariablesAreInputTypes.js.flow ├── VariablesAreInputTypes.js.map ├── VariablesInAllowedPosition.js ├── VariablesInAllowedPosition.js.flow └── VariablesInAllowedPosition.js.map ├── specifiedRules.js ├── specifiedRules.js.flow ├── specifiedRules.js.map ├── validate.js ├── validate.js.flow └── validate.js.map /LICENSE: -------------------------------------------------------------------------------- 1 | BSD License 2 | 3 | For GraphQL software 4 | 5 | Copyright (c) 2015, Facebook, Inc. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name Facebook nor the names of its contributors may be used to 18 | endorse or promote products derived from this software without specific 19 | prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /PATENTS: -------------------------------------------------------------------------------- 1 | Additional Grant of Patent Rights Version 2 2 | 3 | "Software" means the GraphQL software distributed by Facebook, Inc. 4 | 5 | Facebook, Inc. (“Facebook”) hereby grants to each recipient of the Software (“you”) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (subject to the termination provision below) license under any Necessary Claims, to make, have made, use, sell, offer to sell, import, and otherwise transfer the Software. For avoidance of doubt, no license is granted under Facebook’s rights in any patent claims that are infringed by (i) modifications to the Software made by you or any third party or (ii) the Software in combination with any software or other technology. 6 | 7 | The license granted hereunder will terminate, automatically and without notice, if you (or any of your subsidiaries, corporate affiliates or agents) initiate directly or indirectly, or take a direct financial interest in, any Patent Assertion: (i) against Facebook or any of its subsidiaries or corporate affiliates, (ii) against any party if such Patent Assertion arises in whole or in part from any software, technology, product or service of Facebook or any of its subsidiaries or corporate affiliates, or (iii) against any party relating to the Software. Notwithstanding the foregoing, if Facebook or any of its subsidiaries or corporate affiliates files a lawsuit alleging patent infringement against you in the first instance, and you respond by filing a patent infringement counterclaim in that lawsuit against that party that is unrelated to the Software, the license granted hereunder will not terminate under section (i) of this paragraph due to such counterclaim. 8 | 9 | A “Necessary Claim” is a claim of a patent owned by Facebook that is necessarily infringed by the Software standing alone. 10 | 11 | A “Patent Assertion” is any lawsuit or other action alleging direct, indirect, or contributory infringement or inducement to infringe any patent, including a cross-claim or counterclaim. 12 | -------------------------------------------------------------------------------- /error/formatError.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.formatError = formatError; 7 | 8 | var _invariant = require('../jsutils/invariant'); 9 | 10 | var _invariant2 = _interopRequireDefault(_invariant); 11 | 12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 13 | 14 | /** 15 | * Given a GraphQLError, format it according to the rules described by the 16 | * Response Format, Errors section of the GraphQL Specification. 17 | */ 18 | function formatError(error) { 19 | (0, _invariant2.default)(error, 'Received null or undefined error.'); 20 | return { 21 | message: error.message, 22 | locations: error.locations 23 | }; 24 | } 25 | /** 26 | * Copyright (c) 2015, Facebook, Inc. 27 | * All rights reserved. 28 | * 29 | * This source code is licensed under the BSD-style license found in the 30 | * LICENSE file in the root directory of this source tree. An additional grant 31 | * of patent rights can be found in the PATENTS file in the same directory. 32 | */ 33 | //# sourceMappingURL=formatError.js.map 34 | -------------------------------------------------------------------------------- /error/formatError.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import invariant from '../jsutils/invariant'; 12 | import type { GraphQLError } from './GraphQLError'; 13 | 14 | 15 | /** 16 | * Given a GraphQLError, format it according to the rules described by the 17 | * Response Format, Errors section of the GraphQL Specification. 18 | */ 19 | export function formatError(error: GraphQLError): GraphQLFormattedError { 20 | invariant(error, 'Received null or undefined error.'); 21 | return { 22 | message: error.message, 23 | locations: error.locations 24 | }; 25 | } 26 | 27 | export type GraphQLFormattedError = { 28 | message: string, 29 | locations: ?Array 30 | }; 31 | 32 | export type GraphQLErrorLocation = { 33 | line: number, 34 | column: number 35 | }; 36 | -------------------------------------------------------------------------------- /error/formatError.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["error/formatError.js"],"names":[],"mappings":";;;;;QAkBgB;;AARhB;;;;;;;;;;AAQO,SAAS,WAAT,CAAqB,KAArB,EAAiE;AACtE,2BAAU,KAAV,EAAiB,mCAAjB,EADsE;AAEtE,SAAO;AACL,aAAS,MAAM,OAAN;AACT,eAAW,MAAM,SAAN;GAFb,CAFsE;CAAjE","file":"error/formatError.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport invariant from '../jsutils/invariant';\nimport type { GraphQLError } from './GraphQLError';\n\n\n/**\n * Given a GraphQLError, format it according to the rules described by the\n * Response Format, Errors section of the GraphQL Specification.\n */\nexport function formatError(error: GraphQLError): GraphQLFormattedError {\n invariant(error, 'Received null or undefined error.');\n return {\n message: error.message,\n locations: error.locations\n };\n}\n\nexport type GraphQLFormattedError = {\n message: string,\n locations: ?Array\n};\n\nexport type GraphQLErrorLocation = {\n line: number,\n column: number\n};\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /error/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | 7 | var _GraphQLError = require('./GraphQLError'); 8 | 9 | Object.defineProperty(exports, 'GraphQLError', { 10 | enumerable: true, 11 | get: function get() { 12 | return _GraphQLError.GraphQLError; 13 | } 14 | }); 15 | 16 | var _syntaxError = require('./syntaxError'); 17 | 18 | Object.defineProperty(exports, 'syntaxError', { 19 | enumerable: true, 20 | get: function get() { 21 | return _syntaxError.syntaxError; 22 | } 23 | }); 24 | 25 | var _locatedError = require('./locatedError'); 26 | 27 | Object.defineProperty(exports, 'locatedError', { 28 | enumerable: true, 29 | get: function get() { 30 | return _locatedError.locatedError; 31 | } 32 | }); 33 | 34 | var _formatError = require('./formatError'); 35 | 36 | Object.defineProperty(exports, 'formatError', { 37 | enumerable: true, 38 | get: function get() { 39 | return _formatError.formatError; 40 | } 41 | }); 42 | //# sourceMappingURL=index.js.map 43 | -------------------------------------------------------------------------------- /error/index.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | export { GraphQLError } from './GraphQLError'; 12 | export { syntaxError } from './syntaxError'; 13 | export { locatedError } from './locatedError'; 14 | export { formatError } from './formatError'; 15 | -------------------------------------------------------------------------------- /error/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["error/index.js"],"names":[],"mappings":";;;;;;;;;;;yBAUS;;;;;;;;;wBACA;;;;;;;;;yBACA;;;;;;;;;wBACA","file":"error/index.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nexport { GraphQLError } from './GraphQLError';\nexport { syntaxError } from './syntaxError';\nexport { locatedError } from './locatedError';\nexport { formatError } from './formatError';\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /error/locatedError.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.locatedError = locatedError; 7 | 8 | var _GraphQLError = require('./GraphQLError'); 9 | 10 | /** 11 | * Given an arbitrary Error, presumably thrown while attempting to execute a 12 | * GraphQL operation, produce a new GraphQLError aware of the location in the 13 | * document responsible for the original Error. 14 | */ 15 | function locatedError(originalError, nodes, path) { 16 | // Note: this uses a brand-check to support GraphQL errors originating from 17 | // other contexts. 18 | if (originalError && originalError.locations) { 19 | return originalError; 20 | } 21 | 22 | var message = originalError ? originalError.message || String(originalError) : 'An unknown error occurred.'; 23 | return new _GraphQLError.GraphQLError(message, nodes, undefined, undefined, path, originalError); 24 | } 25 | /** 26 | * Copyright (c) 2015, Facebook, Inc. 27 | * All rights reserved. 28 | * 29 | * This source code is licensed under the BSD-style license found in the 30 | * LICENSE file in the root directory of this source tree. An additional grant 31 | * of patent rights can be found in the PATENTS file in the same directory. 32 | */ 33 | //# sourceMappingURL=locatedError.js.map 34 | -------------------------------------------------------------------------------- /error/locatedError.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import { GraphQLError } from './GraphQLError'; 12 | 13 | 14 | /** 15 | * Given an arbitrary Error, presumably thrown while attempting to execute a 16 | * GraphQL operation, produce a new GraphQLError aware of the location in the 17 | * document responsible for the original Error. 18 | */ 19 | export function locatedError( 20 | originalError: ?Error, 21 | nodes: Array<*>, 22 | path: Array 23 | ): GraphQLError { 24 | // Note: this uses a brand-check to support GraphQL errors originating from 25 | // other contexts. 26 | if (originalError && originalError.locations) { 27 | return (originalError: any); 28 | } 29 | 30 | const message = originalError ? 31 | originalError.message || String(originalError) : 32 | 'An unknown error occurred.'; 33 | return new GraphQLError( 34 | message, 35 | nodes, 36 | undefined, 37 | undefined, 38 | path, 39 | originalError 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /error/locatedError.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["error/locatedError.js"],"names":[],"mappings":";;;;;QAkBgB;;AARhB;;;;;;;AAQO,SAAS,YAAT,CACL,aADK,EAEL,KAFK,EAGL,IAHK,EAIS;;;AAGd,MAAI,iBAAiB,cAAc,SAAd,EAAyB;AAC5C,WAAQ,aAAR,CAD4C;GAA9C;;AAIA,MAAM,UAAU,gBACd,cAAc,OAAd,IAAyB,OAAO,aAAP,CAAzB,GACA,4BAFc,CAPF;AAUd,SAAO,+BACL,OADK,EAEL,KAFK,EAGL,SAHK,EAIL,SAJK,EAKL,IALK,EAML,aANK,CAAP,CAVc;CAJT","file":"error/locatedError.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport { GraphQLError } from './GraphQLError';\n\n\n/**\n * Given an arbitrary Error, presumably thrown while attempting to execute a\n * GraphQL operation, produce a new GraphQLError aware of the location in the\n * document responsible for the original Error.\n */\nexport function locatedError(\n originalError: ?Error,\n nodes: Array<*>,\n path: Array\n): GraphQLError {\n // Note: this uses a brand-check to support GraphQL errors originating from\n // other contexts.\n if (originalError && originalError.locations) {\n return (originalError: any);\n }\n\n const message = originalError ?\n originalError.message || String(originalError) :\n 'An unknown error occurred.';\n return new GraphQLError(\n message,\n nodes,\n undefined,\n undefined,\n path,\n originalError\n );\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /error/syntaxError.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.syntaxError = syntaxError; 7 | 8 | var _location = require('../language/location'); 9 | 10 | var _GraphQLError = require('./GraphQLError'); 11 | 12 | /** 13 | * Produces a GraphQLError representing a syntax error, containing useful 14 | * descriptive information about the syntax error's position in the source. 15 | */ 16 | 17 | /** 18 | * Copyright (c) 2015, Facebook, Inc. 19 | * All rights reserved. 20 | * 21 | * This source code is licensed under the BSD-style license found in the 22 | * LICENSE file in the root directory of this source tree. An additional grant 23 | * of patent rights can be found in the PATENTS file in the same directory. 24 | */ 25 | 26 | function syntaxError(source, position, description) { 27 | var location = (0, _location.getLocation)(source, position); 28 | var error = new _GraphQLError.GraphQLError('Syntax Error ' + source.name + ' (' + location.line + ':' + location.column + ') ' + description + '\n\n' + highlightSourceAtLocation(source, location), undefined, source, [position]); 29 | return error; 30 | } 31 | 32 | /** 33 | * Render a helpful description of the location of the error in the GraphQL 34 | * Source document. 35 | */ 36 | function highlightSourceAtLocation(source, location) { 37 | var line = location.line; 38 | var prevLineNum = (line - 1).toString(); 39 | var lineNum = line.toString(); 40 | var nextLineNum = (line + 1).toString(); 41 | var padLen = nextLineNum.length; 42 | var lines = source.body.split(/\r\n|[\n\r]/g); 43 | return (line >= 2 ? lpad(padLen, prevLineNum) + ': ' + lines[line - 2] + '\n' : '') + lpad(padLen, lineNum) + ': ' + lines[line - 1] + '\n' + Array(2 + padLen + location.column).join(' ') + '^\n' + (line < lines.length ? lpad(padLen, nextLineNum) + ': ' + lines[line] + '\n' : ''); 44 | } 45 | 46 | function lpad(len, str) { 47 | return Array(len - str.length + 1).join(' ') + str; 48 | } 49 | //# sourceMappingURL=syntaxError.js.map 50 | -------------------------------------------------------------------------------- /error/syntaxError.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import { getLocation } from '../language/location'; 12 | import type { Source } from '../language/source'; 13 | import { GraphQLError } from './GraphQLError'; 14 | 15 | /** 16 | * Produces a GraphQLError representing a syntax error, containing useful 17 | * descriptive information about the syntax error's position in the source. 18 | */ 19 | export function syntaxError( 20 | source: Source, 21 | position: number, 22 | description: string 23 | ): GraphQLError { 24 | const location = getLocation(source, position); 25 | const error = new GraphQLError( 26 | `Syntax Error ${source.name} (${location.line}:${location.column}) ` + 27 | description + '\n\n' + highlightSourceAtLocation(source, location), 28 | undefined, 29 | source, 30 | [ position ] 31 | ); 32 | return error; 33 | } 34 | 35 | /** 36 | * Render a helpful description of the location of the error in the GraphQL 37 | * Source document. 38 | */ 39 | function highlightSourceAtLocation(source, location) { 40 | const line = location.line; 41 | const prevLineNum = (line - 1).toString(); 42 | const lineNum = line.toString(); 43 | const nextLineNum = (line + 1).toString(); 44 | const padLen = nextLineNum.length; 45 | const lines = source.body.split(/\r\n|[\n\r]/g); 46 | return ( 47 | (line >= 2 ? 48 | lpad(padLen, prevLineNum) + ': ' + lines[line - 2] + '\n' : '') + 49 | lpad(padLen, lineNum) + ': ' + lines[line - 1] + '\n' + 50 | Array(2 + padLen + location.column).join(' ') + '^\n' + 51 | (line < lines.length ? 52 | lpad(padLen, nextLineNum) + ': ' + lines[line] + '\n' : '') 53 | ); 54 | } 55 | 56 | function lpad(len, str) { 57 | return Array(len - str.length + 1).join(' ') + str; 58 | } 59 | -------------------------------------------------------------------------------- /execution/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | 7 | var _execute = require('./execute'); 8 | 9 | Object.defineProperty(exports, 'execute', { 10 | enumerable: true, 11 | get: function get() { 12 | return _execute.execute; 13 | } 14 | }); 15 | //# sourceMappingURL=index.js.map 16 | -------------------------------------------------------------------------------- /execution/index.js.flow: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | export { execute } from './execute'; 11 | -------------------------------------------------------------------------------- /execution/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["execution/index.js"],"names":[],"mappings":";;;;;;;;;;;oBASS","file":"execution/index.js","sourcesContent":["/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nexport { execute } from './execute';\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /graphql.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.graphql = graphql; 7 | 8 | var _source = require('./language/source'); 9 | 10 | var _parser = require('./language/parser'); 11 | 12 | var _validate = require('./validation/validate'); 13 | 14 | var _execute = require('./execution/execute'); 15 | 16 | /** 17 | * This is the primary entry point function for fulfilling GraphQL operations 18 | * by parsing, validating, and executing a GraphQL document along side a 19 | * GraphQL schema. 20 | * 21 | * More sophisticated GraphQL servers, such as those which persist queries, 22 | * may wish to separate the validation and execution phases to a static time 23 | * tooling step, and a server runtime step. 24 | * 25 | * schema: 26 | * The GraphQL type system to use when validating and executing a query. 27 | * requestString: 28 | * A GraphQL language formatted string representing the requested operation. 29 | * rootValue: 30 | * The value provided as the first argument to resolver functions on the top 31 | * level type (e.g. the query object type). 32 | * variableValues: 33 | * A mapping of variable name to runtime value to use for all variables 34 | * defined in the requestString. 35 | * operationName: 36 | * The name of the operation to use if requestString contains multiple 37 | * possible operations. Can be omitted if requestString contains only 38 | * one operation. 39 | */ 40 | 41 | /** 42 | * Copyright (c) 2015, Facebook, Inc. 43 | * All rights reserved. 44 | * 45 | * This source code is licensed under the BSD-style license found in the 46 | * LICENSE file in the root directory of this source tree. An additional grant 47 | * of patent rights can be found in the PATENTS file in the same directory. 48 | */ 49 | 50 | function graphql(schema, requestString, rootValue, contextValue, variableValues, operationName) { 51 | return new Promise(function (resolve) { 52 | var source = new _source.Source(requestString || '', 'GraphQL request'); 53 | var documentAST = (0, _parser.parse)(source); 54 | var validationErrors = (0, _validate.validate)(schema, documentAST); 55 | if (validationErrors.length > 0) { 56 | resolve({ errors: validationErrors }); 57 | } else { 58 | resolve((0, _execute.execute)(schema, documentAST, rootValue, contextValue, variableValues, operationName)); 59 | } 60 | }).catch(function (error) { 61 | return { errors: [error] }; 62 | }); 63 | } 64 | 65 | /** 66 | * The result of a GraphQL parse, validation and execution. 67 | * 68 | * `data` is the result of a successful execution of the query. 69 | * `errors` is included when any errors occurred as a non-empty array. 70 | */ 71 | //# sourceMappingURL=graphql.js.map 72 | -------------------------------------------------------------------------------- /graphql.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import { Source } from './language/source'; 12 | import { parse } from './language/parser'; 13 | import { validate } from './validation/validate'; 14 | import { execute } from './execution/execute'; 15 | import type { GraphQLError } from './error/GraphQLError'; 16 | import type { GraphQLSchema } from './type/schema'; 17 | 18 | 19 | /** 20 | * This is the primary entry point function for fulfilling GraphQL operations 21 | * by parsing, validating, and executing a GraphQL document along side a 22 | * GraphQL schema. 23 | * 24 | * More sophisticated GraphQL servers, such as those which persist queries, 25 | * may wish to separate the validation and execution phases to a static time 26 | * tooling step, and a server runtime step. 27 | * 28 | * schema: 29 | * The GraphQL type system to use when validating and executing a query. 30 | * requestString: 31 | * A GraphQL language formatted string representing the requested operation. 32 | * rootValue: 33 | * The value provided as the first argument to resolver functions on the top 34 | * level type (e.g. the query object type). 35 | * variableValues: 36 | * A mapping of variable name to runtime value to use for all variables 37 | * defined in the requestString. 38 | * operationName: 39 | * The name of the operation to use if requestString contains multiple 40 | * possible operations. Can be omitted if requestString contains only 41 | * one operation. 42 | */ 43 | export function graphql( 44 | schema: GraphQLSchema, 45 | requestString: string, 46 | rootValue?: mixed, 47 | contextValue?: mixed, 48 | variableValues?: ?{[key: string]: mixed}, 49 | operationName?: ?string 50 | ): Promise { 51 | return new Promise(resolve => { 52 | const source = new Source(requestString || '', 'GraphQL request'); 53 | const documentAST = parse(source); 54 | const validationErrors = validate(schema, documentAST); 55 | if (validationErrors.length > 0) { 56 | resolve({ errors: validationErrors }); 57 | } else { 58 | resolve( 59 | execute( 60 | schema, 61 | documentAST, 62 | rootValue, 63 | contextValue, 64 | variableValues, 65 | operationName 66 | ) 67 | ); 68 | } 69 | }).catch(error => { 70 | return { errors: [ error ] }; 71 | }); 72 | } 73 | 74 | /** 75 | * The result of a GraphQL parse, validation and execution. 76 | * 77 | * `data` is the result of a successful execution of the query. 78 | * `errors` is included when any errors occurred as a non-empty array. 79 | */ 80 | type GraphQLResult = { 81 | data?: ?Object; 82 | errors?: Array; 83 | } 84 | -------------------------------------------------------------------------------- /jsutils/find.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.default = find; 7 | 8 | /** 9 | * Copyright (c) 2015, Facebook, Inc. 10 | * All rights reserved. 11 | * 12 | * This source code is licensed under the BSD-style license found in the 13 | * LICENSE file in the root directory of this source tree. An additional grant 14 | * of patent rights can be found in the PATENTS file in the same directory. 15 | */ 16 | 17 | function find(list, predicate) { 18 | for (var i = 0; i < list.length; i++) { 19 | if (predicate(list[i])) { 20 | return list[i]; 21 | } 22 | } 23 | } 24 | //# sourceMappingURL=find.js.map 25 | -------------------------------------------------------------------------------- /jsutils/find.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | export default function find( 12 | list: Array, 13 | predicate: (item: T) => boolean 14 | ): ?T { 15 | for (let i = 0; i < list.length; i++) { 16 | if (predicate(list[i])) { 17 | return list[i]; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jsutils/find.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["jsutils/find.js"],"names":[],"mappings":";;;;;kBAUwB;;;;;;;;;;;AAAT,SAAS,IAAT,CACb,IADa,EAEb,SAFa,EAGT;AACJ,OAAK,IAAI,IAAI,CAAJ,EAAO,IAAI,KAAK,MAAL,EAAa,GAAjC,EAAsC;AACpC,QAAI,UAAU,KAAK,CAAL,CAAV,CAAJ,EAAwB;AACtB,aAAO,KAAK,CAAL,CAAP,CADsB;KAAxB;GADF;CAJa","file":"jsutils/find.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nexport default function find(\n list: Array,\n predicate: (item: T) => boolean\n): ?T {\n for (let i = 0; i < list.length; i++) {\n if (predicate(list[i])) {\n return list[i];\n }\n }\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /jsutils/invariant.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.default = invariant; 7 | 8 | /** 9 | * Copyright (c) 2015, Facebook, Inc. 10 | * All rights reserved. 11 | * 12 | * This source code is licensed under the BSD-style license found in the 13 | * LICENSE file in the root directory of this source tree. An additional grant 14 | * of patent rights can be found in the PATENTS file in the same directory. 15 | */ 16 | 17 | function invariant(condition, message) { 18 | if (!condition) { 19 | throw new Error(message); 20 | } 21 | } 22 | //# sourceMappingURL=invariant.js.map 23 | -------------------------------------------------------------------------------- /jsutils/invariant.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | export default function invariant(condition: mixed, message: string) { 12 | if (!condition) { 13 | throw new Error(message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jsutils/invariant.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["jsutils/invariant.js"],"names":[],"mappings":";;;;;kBAUwB;;;;;;;;;;;AAAT,SAAS,SAAT,CAAmB,SAAnB,EAAqC,OAArC,EAAsD;AACnE,MAAI,CAAC,SAAD,EAAY;AACd,UAAM,IAAI,KAAJ,CAAU,OAAV,CAAN,CADc;GAAhB;CADa","file":"jsutils/invariant.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nexport default function invariant(condition: mixed, message: string) {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /jsutils/isNullish.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.default = isNullish; 7 | 8 | /** 9 | * Copyright (c) 2015, Facebook, Inc. 10 | * All rights reserved. 11 | * 12 | * This source code is licensed under the BSD-style license found in the 13 | * LICENSE file in the root directory of this source tree. An additional grant 14 | * of patent rights can be found in the PATENTS file in the same directory. 15 | */ 16 | 17 | /** 18 | * Returns true if a value is null, undefined, or NaN. 19 | */ 20 | function isNullish(value) { 21 | return value === null || value === undefined || value !== value; 22 | } 23 | //# sourceMappingURL=isNullish.js.map 24 | -------------------------------------------------------------------------------- /jsutils/isNullish.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | /** 12 | * Returns true if a value is null, undefined, or NaN. 13 | */ 14 | export default function isNullish(value: mixed): boolean { 15 | return value === null || value === undefined || value !== value; 16 | } 17 | -------------------------------------------------------------------------------- /jsutils/isNullish.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["jsutils/isNullish.js"],"names":[],"mappings":";;;;;kBAawB;;;;;;;;;;;;;;AAAT,SAAS,SAAT,CAAmB,KAAnB,EAA0C;AACvD,SAAO,UAAU,IAAV,IAAkB,UAAU,SAAV,IAAuB,UAAU,KAAV,CADO;CAA1C","file":"jsutils/isNullish.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/**\n * Returns true if a value is null, undefined, or NaN.\n */\nexport default function isNullish(value: mixed): boolean {\n return value === null || value === undefined || value !== value;\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /jsutils/keyMap.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.default = keyMap; 7 | 8 | /** 9 | * Copyright (c) 2015, Facebook, Inc. 10 | * All rights reserved. 11 | * 12 | * This source code is licensed under the BSD-style license found in the 13 | * LICENSE file in the root directory of this source tree. An additional grant 14 | * of patent rights can be found in the PATENTS file in the same directory. 15 | */ 16 | 17 | /** 18 | * Creates a keyed JS object from an array, given a function to produce the keys 19 | * for each value in the array. 20 | * 21 | * This provides a convenient lookup for the array items if the key function 22 | * produces unique results. 23 | * 24 | * const phoneBook = [ 25 | * { name: 'Jon', num: '555-1234' }, 26 | * { name: 'Jenny', num: '867-5309' } 27 | * ] 28 | * 29 | * // { Jon: { name: 'Jon', num: '555-1234' }, 30 | * // Jenny: { name: 'Jenny', num: '867-5309' } } 31 | * const entriesByName = keyMap( 32 | * phoneBook, 33 | * entry => entry.name 34 | * ) 35 | * 36 | * // { name: 'Jenny', num: '857-6309' } 37 | * const jennyEntry = entriesByName['Jenny'] 38 | * 39 | */ 40 | function keyMap(list, keyFn) { 41 | return list.reduce(function (map, item) { 42 | return map[keyFn(item)] = item, map; 43 | }, {}); 44 | } 45 | //# sourceMappingURL=keyMap.js.map 46 | -------------------------------------------------------------------------------- /jsutils/keyMap.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | /** 12 | * Creates a keyed JS object from an array, given a function to produce the keys 13 | * for each value in the array. 14 | * 15 | * This provides a convenient lookup for the array items if the key function 16 | * produces unique results. 17 | * 18 | * const phoneBook = [ 19 | * { name: 'Jon', num: '555-1234' }, 20 | * { name: 'Jenny', num: '867-5309' } 21 | * ] 22 | * 23 | * // { Jon: { name: 'Jon', num: '555-1234' }, 24 | * // Jenny: { name: 'Jenny', num: '867-5309' } } 25 | * const entriesByName = keyMap( 26 | * phoneBook, 27 | * entry => entry.name 28 | * ) 29 | * 30 | * // { name: 'Jenny', num: '857-6309' } 31 | * const jennyEntry = entriesByName['Jenny'] 32 | * 33 | */ 34 | export default function keyMap( 35 | list: Array, 36 | keyFn: (item: T) => string 37 | ): {[key: string]: T} { 38 | return list.reduce((map, item) => ((map[keyFn(item)] = item), map), {}); 39 | } 40 | -------------------------------------------------------------------------------- /jsutils/keyMap.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["jsutils/keyMap.js"],"names":[],"mappings":";;;;;kBAiCwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAT,SAAS,MAAT,CACb,IADa,EAEb,KAFa,EAGO;AACpB,SAAO,KAAK,MAAL,CAAY,UAAC,GAAD,EAAM,IAAN;WAAgB,GAAC,CAAI,MAAM,IAAN,CAAJ,IAAmB,IAAnB,EAA0B,GAA3B;GAAhB,EAAiD,EAA7D,CAAP,CADoB;CAHP","file":"jsutils/keyMap.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/**\n * Creates a keyed JS object from an array, given a function to produce the keys\n * for each value in the array.\n *\n * This provides a convenient lookup for the array items if the key function\n * produces unique results.\n *\n * const phoneBook = [\n * { name: 'Jon', num: '555-1234' },\n * { name: 'Jenny', num: '867-5309' }\n * ]\n *\n * // { Jon: { name: 'Jon', num: '555-1234' },\n * // Jenny: { name: 'Jenny', num: '867-5309' } }\n * const entriesByName = keyMap(\n * phoneBook,\n * entry => entry.name\n * )\n *\n * // { name: 'Jenny', num: '857-6309' }\n * const jennyEntry = entriesByName['Jenny']\n *\n */\nexport default function keyMap(\n list: Array,\n keyFn: (item: T) => string\n): {[key: string]: T} {\n return list.reduce((map, item) => ((map[keyFn(item)] = item), map), {});\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /jsutils/keyValMap.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.default = keyValMap; 7 | 8 | /** 9 | * Copyright (c) 2015, Facebook, Inc. 10 | * All rights reserved. 11 | * 12 | * This source code is licensed under the BSD-style license found in the 13 | * LICENSE file in the root directory of this source tree. An additional grant 14 | * of patent rights can be found in the PATENTS file in the same directory. 15 | */ 16 | 17 | /** 18 | * Creates a keyed JS object from an array, given a function to produce the keys 19 | * and a function to produce the values from each item in the array. 20 | * 21 | * const phoneBook = [ 22 | * { name: 'Jon', num: '555-1234' }, 23 | * { name: 'Jenny', num: '867-5309' } 24 | * ] 25 | * 26 | * // { Jon: '555-1234', Jenny: '867-5309' } 27 | * const phonesByName = keyValMap( 28 | * phoneBook, 29 | * entry => entry.name, 30 | * entry => entry.num 31 | * ) 32 | * 33 | */ 34 | function keyValMap(list, keyFn, valFn) { 35 | return list.reduce(function (map, item) { 36 | return map[keyFn(item)] = valFn(item), map; 37 | }, {}); 38 | } 39 | //# sourceMappingURL=keyValMap.js.map 40 | -------------------------------------------------------------------------------- /jsutils/keyValMap.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | /** 12 | * Creates a keyed JS object from an array, given a function to produce the keys 13 | * and a function to produce the values from each item in the array. 14 | * 15 | * const phoneBook = [ 16 | * { name: 'Jon', num: '555-1234' }, 17 | * { name: 'Jenny', num: '867-5309' } 18 | * ] 19 | * 20 | * // { Jon: '555-1234', Jenny: '867-5309' } 21 | * const phonesByName = keyValMap( 22 | * phoneBook, 23 | * entry => entry.name, 24 | * entry => entry.num 25 | * ) 26 | * 27 | */ 28 | export default function keyValMap( 29 | list: Array, 30 | keyFn: (item: T) => string, 31 | valFn: (item: T) => V 32 | ): {[key: string]: V} { 33 | return list.reduce( 34 | (map, item) => ((map[keyFn(item)] = valFn(item)), map), 35 | {} 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /jsutils/keyValMap.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["jsutils/keyValMap.js"],"names":[],"mappings":";;;;;kBA2BwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAT,SAAS,SAAT,CACb,IADa,EAEb,KAFa,EAGb,KAHa,EAIO;AACpB,SAAO,KAAK,MAAL,CACL,UAAC,GAAD,EAAM,IAAN;WAAgB,GAAC,CAAI,MAAM,IAAN,CAAJ,IAAmB,MAAM,IAAN,CAAnB,EAAiC,GAAlC;GAAhB,EACA,EAFK,CAAP,CADoB;CAJP","file":"jsutils/keyValMap.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/**\n * Creates a keyed JS object from an array, given a function to produce the keys\n * and a function to produce the values from each item in the array.\n *\n * const phoneBook = [\n * { name: 'Jon', num: '555-1234' },\n * { name: 'Jenny', num: '867-5309' }\n * ]\n *\n * // { Jon: '555-1234', Jenny: '867-5309' }\n * const phonesByName = keyValMap(\n * phoneBook,\n * entry => entry.name,\n * entry => entry.num\n * )\n *\n */\nexport default function keyValMap(\n list: Array,\n keyFn: (item: T) => string,\n valFn: (item: T) => V\n): {[key: string]: V} {\n return list.reduce(\n (map, item) => ((map[keyFn(item)] = valFn(item)), map),\n {}\n );\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /jsutils/quotedOrList.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.default = quotedOrList; 7 | 8 | /** 9 | * Copyright (c) 2015, Facebook, Inc. 10 | * All rights reserved. 11 | * 12 | * This source code is licensed under the BSD-style license found in the 13 | * LICENSE file in the root directory of this source tree. An additional grant 14 | * of patent rights can be found in the PATENTS file in the same directory. 15 | */ 16 | 17 | var MAX_LENGTH = 5; 18 | 19 | /** 20 | * Given [ A, B, C ] return '"A", "B", or "C"'. 21 | */ 22 | function quotedOrList(items) { 23 | var selected = items.slice(0, MAX_LENGTH); 24 | return selected.map(function (item) { 25 | return '"' + item + '"'; 26 | }).reduce(function (list, quoted, index) { 27 | return list + (selected.length > 2 ? ', ' : ' ') + (index === selected.length - 1 ? 'or ' : '') + quoted; 28 | }); 29 | } 30 | //# sourceMappingURL=quotedOrList.js.map 31 | -------------------------------------------------------------------------------- /jsutils/quotedOrList.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | const MAX_LENGTH = 5; 12 | 13 | /** 14 | * Given [ A, B, C ] return '"A", "B", or "C"'. 15 | */ 16 | export default function quotedOrList(items: Array): string { 17 | const selected = items.slice(0, MAX_LENGTH); 18 | return selected 19 | .map(item => `"${item}"`) 20 | .reduce((list, quoted, index) => 21 | list + 22 | (selected.length > 2 ? ', ' : ' ') + 23 | (index === selected.length - 1 ? 'or ' : '') + 24 | quoted 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /jsutils/quotedOrList.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["jsutils/quotedOrList.js"],"names":[],"mappings":";;;;;kBAewB;;;;;;;;;;;AALxB,IAAM,aAAa,CAAb;;;;;AAKS,SAAS,YAAT,CAAsB,KAAtB,EAAoD;AACjE,MAAM,WAAW,MAAM,KAAN,CAAY,CAAZ,EAAe,UAAf,CAAX,CAD2D;AAEjE,SAAO,SACJ,GADI,CACA;iBAAY;GAAZ,CADA,CAEJ,MAFI,CAEG,UAAC,IAAD,EAAO,MAAP,EAAe,KAAf;WACN,QACC,SAAS,MAAT,GAAkB,CAAlB,GAAsB,IAAtB,GAA6B,GAA7B,CADD,IAEC,UAAU,SAAS,MAAT,GAAkB,CAAlB,GAAsB,KAAhC,GAAwC,EAAxC,CAFD,GAGA,MAHA;GADM,CAFV,CAFiE;CAApD","file":"jsutils/quotedOrList.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nconst MAX_LENGTH = 5;\n\n/**\n * Given [ A, B, C ] return '\"A\", \"B\", or \"C\"'.\n */\nexport default function quotedOrList(items: Array): string {\n const selected = items.slice(0, MAX_LENGTH);\n return selected\n .map(item => `\"${item}\"`)\n .reduce((list, quoted, index) =>\n list +\n (selected.length > 2 ? ', ' : ' ') +\n (index === selected.length - 1 ? 'or ' : '') +\n quoted\n );\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /jsutils/suggestionList.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.default = suggestionList; 7 | 8 | /** 9 | * Copyright (c) 2015, Facebook, Inc. 10 | * All rights reserved. 11 | * 12 | * This source code is licensed under the BSD-style license found in the 13 | * LICENSE file in the root directory of this source tree. An additional grant 14 | * of patent rights can be found in the PATENTS file in the same directory. 15 | */ 16 | 17 | /** 18 | * Given an invalid input string and a list of valid options, returns a filtered 19 | * list of valid options sorted based on their similarity with the input. 20 | */ 21 | function suggestionList(input, options) { 22 | var optionsByDistance = Object.create(null); 23 | var oLength = options.length; 24 | var inputThreshold = input.length / 2; 25 | for (var i = 0; i < oLength; i++) { 26 | var distance = lexicalDistance(input, options[i]); 27 | var threshold = Math.max(inputThreshold, options[i].length / 2, 1); 28 | if (distance <= threshold) { 29 | optionsByDistance[options[i]] = distance; 30 | } 31 | } 32 | return Object.keys(optionsByDistance).sort(function (a, b) { 33 | return optionsByDistance[a] - optionsByDistance[b]; 34 | }); 35 | } 36 | 37 | /** 38 | * Computes the lexical distance between strings A and B. 39 | * 40 | * The "distance" between two strings is given by counting the minimum number 41 | * of edits needed to transform string A into string B. An edit can be an 42 | * insertion, deletion, or substitution of a single character, or a swap of two 43 | * adjacent characters. 44 | * 45 | * This distance can be useful for detecting typos in input or sorting 46 | * 47 | * @param {string} a 48 | * @param {string} b 49 | * @return {int} distance in number of edits 50 | */ 51 | function lexicalDistance(a, b) { 52 | var i = undefined; 53 | var j = undefined; 54 | var d = []; 55 | var aLength = a.length; 56 | var bLength = b.length; 57 | 58 | for (i = 0; i <= aLength; i++) { 59 | d[i] = [i]; 60 | } 61 | 62 | for (j = 1; j <= bLength; j++) { 63 | d[0][j] = j; 64 | } 65 | 66 | for (i = 1; i <= aLength; i++) { 67 | for (j = 1; j <= bLength; j++) { 68 | var cost = a[i - 1] === b[j - 1] ? 0 : 1; 69 | 70 | d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost); 71 | 72 | if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) { 73 | d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + cost); 74 | } 75 | } 76 | } 77 | 78 | return d[aLength][bLength]; 79 | } 80 | //# sourceMappingURL=suggestionList.js.map 81 | -------------------------------------------------------------------------------- /jsutils/suggestionList.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | /** 12 | * Given an invalid input string and a list of valid options, returns a filtered 13 | * list of valid options sorted based on their similarity with the input. 14 | */ 15 | export default function suggestionList( 16 | input: string, 17 | options: Array 18 | ): Array { 19 | const optionsByDistance = Object.create(null); 20 | const oLength = options.length; 21 | const inputThreshold = input.length / 2; 22 | for (let i = 0; i < oLength; i++) { 23 | const distance = lexicalDistance(input, options[i]); 24 | const threshold = Math.max(inputThreshold, options[i].length / 2, 1); 25 | if (distance <= threshold) { 26 | optionsByDistance[options[i]] = distance; 27 | } 28 | } 29 | return Object.keys(optionsByDistance).sort( 30 | (a , b) => optionsByDistance[a] - optionsByDistance[b] 31 | ); 32 | } 33 | 34 | /** 35 | * Computes the lexical distance between strings A and B. 36 | * 37 | * The "distance" between two strings is given by counting the minimum number 38 | * of edits needed to transform string A into string B. An edit can be an 39 | * insertion, deletion, or substitution of a single character, or a swap of two 40 | * adjacent characters. 41 | * 42 | * This distance can be useful for detecting typos in input or sorting 43 | * 44 | * @param {string} a 45 | * @param {string} b 46 | * @return {int} distance in number of edits 47 | */ 48 | function lexicalDistance(a, b) { 49 | let i; 50 | let j; 51 | const d = []; 52 | const aLength = a.length; 53 | const bLength = b.length; 54 | 55 | for (i = 0; i <= aLength; i++) { 56 | d[i] = [ i ]; 57 | } 58 | 59 | for (j = 1; j <= bLength; j++) { 60 | d[0][j] = j; 61 | } 62 | 63 | for (i = 1; i <= aLength; i++) { 64 | for (j = 1; j <= bLength; j++) { 65 | const cost = a[i - 1] === b[j - 1] ? 0 : 1; 66 | 67 | d[i][j] = Math.min( 68 | d[i - 1][j] + 1, 69 | d[i][j - 1] + 1, 70 | d[i - 1][j - 1] + cost 71 | ); 72 | 73 | if (i > 1 && j > 1 && 74 | a[i - 1] === b[j - 2] && 75 | a[i - 2] === b[j - 1]) { 76 | d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + cost); 77 | } 78 | } 79 | } 80 | 81 | return d[aLength][bLength]; 82 | } 83 | -------------------------------------------------------------------------------- /language/ast.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //# sourceMappingURL=ast.js.map 3 | -------------------------------------------------------------------------------- /language/ast.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":[],"names":[],"mappings":"","file":"language/ast.js","sourcesContent":[],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /language/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.BREAK = exports.visitWithTypeInfo = exports.visitInParallel = exports.visit = exports.Source = exports.print = exports.parseValue = exports.parse = exports.TokenKind = exports.createLexer = exports.Kind = exports.getLocation = undefined; 7 | 8 | var _location = require('./location'); 9 | 10 | Object.defineProperty(exports, 'getLocation', { 11 | enumerable: true, 12 | get: function get() { 13 | return _location.getLocation; 14 | } 15 | }); 16 | 17 | var _lexer = require('./lexer'); 18 | 19 | Object.defineProperty(exports, 'createLexer', { 20 | enumerable: true, 21 | get: function get() { 22 | return _lexer.createLexer; 23 | } 24 | }); 25 | Object.defineProperty(exports, 'TokenKind', { 26 | enumerable: true, 27 | get: function get() { 28 | return _lexer.TokenKind; 29 | } 30 | }); 31 | 32 | var _parser = require('./parser'); 33 | 34 | Object.defineProperty(exports, 'parse', { 35 | enumerable: true, 36 | get: function get() { 37 | return _parser.parse; 38 | } 39 | }); 40 | Object.defineProperty(exports, 'parseValue', { 41 | enumerable: true, 42 | get: function get() { 43 | return _parser.parseValue; 44 | } 45 | }); 46 | 47 | var _printer = require('./printer'); 48 | 49 | Object.defineProperty(exports, 'print', { 50 | enumerable: true, 51 | get: function get() { 52 | return _printer.print; 53 | } 54 | }); 55 | 56 | var _source = require('./source'); 57 | 58 | Object.defineProperty(exports, 'Source', { 59 | enumerable: true, 60 | get: function get() { 61 | return _source.Source; 62 | } 63 | }); 64 | 65 | var _visitor = require('./visitor'); 66 | 67 | Object.defineProperty(exports, 'visit', { 68 | enumerable: true, 69 | get: function get() { 70 | return _visitor.visit; 71 | } 72 | }); 73 | Object.defineProperty(exports, 'visitInParallel', { 74 | enumerable: true, 75 | get: function get() { 76 | return _visitor.visitInParallel; 77 | } 78 | }); 79 | Object.defineProperty(exports, 'visitWithTypeInfo', { 80 | enumerable: true, 81 | get: function get() { 82 | return _visitor.visitWithTypeInfo; 83 | } 84 | }); 85 | Object.defineProperty(exports, 'BREAK', { 86 | enumerable: true, 87 | get: function get() { 88 | return _visitor.BREAK; 89 | } 90 | }); 91 | 92 | var _kinds = require('./kinds'); 93 | 94 | var Kind = _interopRequireWildcard(_kinds); 95 | 96 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } 97 | 98 | exports.Kind = Kind; 99 | //# sourceMappingURL=index.js.map 100 | -------------------------------------------------------------------------------- /language/index.js.flow: -------------------------------------------------------------------------------- 1 | /** @flow 2 | * Copyright (c) 2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | export { getLocation } from './location'; 11 | import * as Kind from './kinds'; 12 | export { Kind }; 13 | export { createLexer, TokenKind } from './lexer'; 14 | export { parse, parseValue } from './parser'; 15 | export { print } from './printer'; 16 | export { Source } from './source'; 17 | export { visit, visitInParallel, visitWithTypeInfo, BREAK } from './visitor'; 18 | -------------------------------------------------------------------------------- /language/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["language/index.js"],"names":[],"mappings":";;;;;;;;;;;;qBASS;;;;;;;;;kBAGA;;;;;;kBAAa;;;;;;;;;mBACb;;;;;;mBAAO;;;;;;;;;oBACP;;;;;;;;;mBACA;;;;;;;;;oBACA;;;;;;oBAAO;;;;;;oBAAiB;;;;;;oBAAmB;;;;AANpD;;IAAY;;;;QACH","file":"language/index.js","sourcesContent":["/** @flow\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nexport { getLocation } from './location';\nimport * as Kind from './kinds';\nexport { Kind };\nexport { createLexer, TokenKind } from './lexer';\nexport { parse, parseValue } from './parser';\nexport { print } from './printer';\nexport { Source } from './source';\nexport { visit, visitInParallel, visitWithTypeInfo, BREAK } from './visitor';\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /language/kinds.js.flow: -------------------------------------------------------------------------------- 1 | /** @flow 2 | * Copyright (c) 2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // Name 11 | 12 | export const NAME = 'Name'; 13 | 14 | // Document 15 | 16 | export const DOCUMENT = 'Document'; 17 | export const OPERATION_DEFINITION = 'OperationDefinition'; 18 | export const VARIABLE_DEFINITION = 'VariableDefinition'; 19 | export const VARIABLE = 'Variable'; 20 | export const SELECTION_SET = 'SelectionSet'; 21 | export const FIELD = 'Field'; 22 | export const ARGUMENT = 'Argument'; 23 | 24 | // Fragments 25 | 26 | export const FRAGMENT_SPREAD = 'FragmentSpread'; 27 | export const INLINE_FRAGMENT = 'InlineFragment'; 28 | export const FRAGMENT_DEFINITION = 'FragmentDefinition'; 29 | 30 | // Values 31 | 32 | export const INT = 'IntValue'; 33 | export const FLOAT = 'FloatValue'; 34 | export const STRING = 'StringValue'; 35 | export const BOOLEAN = 'BooleanValue'; 36 | export const ENUM = 'EnumValue'; 37 | export const LIST = 'ListValue'; 38 | export const OBJECT = 'ObjectValue'; 39 | export const OBJECT_FIELD = 'ObjectField'; 40 | 41 | // Directives 42 | 43 | export const DIRECTIVE = 'Directive'; 44 | 45 | // Types 46 | 47 | export const NAMED_TYPE = 'NamedType'; 48 | export const LIST_TYPE = 'ListType'; 49 | export const NON_NULL_TYPE = 'NonNullType'; 50 | 51 | // Type System Definitions 52 | 53 | export const SCHEMA_DEFINITION = 'SchemaDefinition'; 54 | export const OPERATION_TYPE_DEFINITION = 'OperationTypeDefinition'; 55 | 56 | // Type Definitions 57 | 58 | export const SCALAR_TYPE_DEFINITION = 'ScalarTypeDefinition'; 59 | export const OBJECT_TYPE_DEFINITION = 'ObjectTypeDefinition'; 60 | export const FIELD_DEFINITION = 'FieldDefinition'; 61 | export const INPUT_VALUE_DEFINITION = 'InputValueDefinition'; 62 | export const INTERFACE_TYPE_DEFINITION = 'InterfaceTypeDefinition'; 63 | export const UNION_TYPE_DEFINITION = 'UnionTypeDefinition'; 64 | export const ENUM_TYPE_DEFINITION = 'EnumTypeDefinition'; 65 | export const ENUM_VALUE_DEFINITION = 'EnumValueDefinition'; 66 | export const INPUT_OBJECT_TYPE_DEFINITION = 'InputObjectTypeDefinition'; 67 | 68 | // Type Extensions 69 | 70 | export const TYPE_EXTENSION_DEFINITION = 'TypeExtensionDefinition'; 71 | 72 | // Directive Definitions 73 | 74 | export const DIRECTIVE_DEFINITION = 'DirectiveDefinition'; 75 | -------------------------------------------------------------------------------- /language/location.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.getLocation = getLocation; 7 | 8 | /** 9 | * Takes a Source and a UTF-8 character offset, and returns the corresponding 10 | * line and column as a SourceLocation. 11 | */ 12 | 13 | /** 14 | * Copyright (c) 2015, Facebook, Inc. 15 | * All rights reserved. 16 | * 17 | * This source code is licensed under the BSD-style license found in the 18 | * LICENSE file in the root directory of this source tree. An additional grant 19 | * of patent rights can be found in the PATENTS file in the same directory. 20 | */ 21 | 22 | function getLocation(source, position) { 23 | var lineRegexp = /\r\n|[\n\r]/g; 24 | var line = 1; 25 | var column = position + 1; 26 | var match = undefined; 27 | while ((match = lineRegexp.exec(source.body)) && match.index < position) { 28 | line += 1; 29 | column = position + 1 - (match.index + match[0].length); 30 | } 31 | return { line: line, column: column }; 32 | } 33 | 34 | /** 35 | * Represents a location in a Source. 36 | */ 37 | //# sourceMappingURL=location.js.map 38 | -------------------------------------------------------------------------------- /language/location.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { Source } from './source'; 12 | 13 | /** 14 | * Represents a location in a Source. 15 | */ 16 | type SourceLocation = { 17 | line: number; 18 | column: number; 19 | } 20 | 21 | /** 22 | * Takes a Source and a UTF-8 character offset, and returns the corresponding 23 | * line and column as a SourceLocation. 24 | */ 25 | export function getLocation(source: Source, position: number): SourceLocation { 26 | const lineRegexp = /\r\n|[\n\r]/g; 27 | let line = 1; 28 | let column = position + 1; 29 | let match; 30 | while ((match = lineRegexp.exec(source.body)) && match.index < position) { 31 | line += 1; 32 | column = position + 1 - (match.index + match[0].length); 33 | } 34 | return { line, column }; 35 | } 36 | -------------------------------------------------------------------------------- /language/location.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["language/location.js"],"names":[],"mappings":";;;;;QAwBgB;;;;;;;;;;;;;;;;AAAT,SAAS,WAAT,CAAqB,MAArB,EAAqC,QAArC,EAAuE;AAC5E,MAAM,aAAa,cAAb,CADsE;AAE5E,MAAI,OAAO,CAAP,CAFwE;AAG5E,MAAI,SAAS,WAAW,CAAX,CAH+D;AAI5E,MAAI,iBAAJ,CAJ4E;AAK5E,SAAO,CAAC,QAAQ,WAAW,IAAX,CAAgB,OAAO,IAAP,CAAxB,CAAD,IAA0C,MAAM,KAAN,GAAc,QAAd,EAAwB;AACvE,YAAQ,CAAR,CADuE;AAEvE,aAAS,WAAW,CAAX,IAAgB,MAAM,KAAN,GAAc,MAAM,CAAN,EAAS,MAAT,CAA9B,CAF8D;GAAzE;AAIA,SAAO,EAAE,UAAF,EAAQ,cAAR,EAAP,CAT4E;CAAvE","file":"language/location.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { Source } from './source';\n\n/**\n * Represents a location in a Source.\n */\ntype SourceLocation = {\n line: number;\n column: number;\n}\n\n/**\n * Takes a Source and a UTF-8 character offset, and returns the corresponding\n * line and column as a SourceLocation.\n */\nexport function getLocation(source: Source, position: number): SourceLocation {\n const lineRegexp = /\\r\\n|[\\n\\r]/g;\n let line = 1;\n let column = position + 1;\n let match;\n while ((match = lineRegexp.exec(source.body)) && match.index < position) {\n line += 1;\n column = position + 1 - (match.index + match[0].length);\n }\n return { line, column };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /language/source.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | 7 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 8 | 9 | /** 10 | * Copyright (c) 2015, Facebook, Inc. 11 | * All rights reserved. 12 | * 13 | * This source code is licensed under the BSD-style license found in the 14 | * LICENSE file in the root directory of this source tree. An additional grant 15 | * of patent rights can be found in the PATENTS file in the same directory. 16 | */ 17 | 18 | /** 19 | * A representation of source input to GraphQL. The name is optional, 20 | * but is mostly useful for clients who store GraphQL documents in 21 | * source files; for example, if the GraphQL input is in a file Foo.graphql, 22 | * it might be useful for name to be "Foo.graphql". 23 | */ 24 | 25 | var Source = exports.Source = function Source(body, name) { 26 | _classCallCheck(this, Source); 27 | 28 | this.body = body; 29 | this.name = name || 'GraphQL'; 30 | }; 31 | //# sourceMappingURL=source.js.map 32 | -------------------------------------------------------------------------------- /language/source.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | /** 12 | * A representation of source input to GraphQL. The name is optional, 13 | * but is mostly useful for clients who store GraphQL documents in 14 | * source files; for example, if the GraphQL input is in a file Foo.graphql, 15 | * it might be useful for name to be "Foo.graphql". 16 | */ 17 | export class Source { 18 | body: string; 19 | name: string; 20 | 21 | constructor(body: string, name?: string) { 22 | this.body = body; 23 | this.name = name || 'GraphQL'; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /language/source.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["language/source.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;IAgBa,0BAIX,gBAAY,IAAZ,EAA0B,IAA1B,EAAyC;;;AACvC,OAAK,IAAL,GAAY,IAAZ,CADuC;AAEvC,OAAK,IAAL,GAAY,QAAQ,SAAR,CAF2B;CAAzC","file":"language/source.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/**\n * A representation of source input to GraphQL. The name is optional,\n * but is mostly useful for clients who store GraphQL documents in\n * source files; for example, if the GraphQL input is in a file Foo.graphql,\n * it might be useful for name to be \"Foo.graphql\".\n */\nexport class Source {\n body: string;\n name: string;\n\n constructor(body: string, name?: string) {\n this.body = body;\n this.name = name || 'GraphQL';\n }\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flow-graphql", 3 | "version": "0.7.0", 4 | "description": "flow typed grapgql", 5 | "contributors": [ 6 | "Lee Byron (http://leebyron.com/)", 7 | "Nicholas Schrock ", 8 | "Daniel Schafer " 9 | ], 10 | "license": "BSD-3-Clause", 11 | "main": "index.js", 12 | "homepage": "https://github.com/iamchenxin/flow-graphql", 13 | "bugs": { 14 | "url": "https://github.com/iamchenxin/flow-graphql/issues" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/iamchenxin/flow-graphql.git" 19 | }, 20 | "babel": { 21 | "presets": [ 22 | "es2015" 23 | ], 24 | "plugins": [ 25 | "syntax-async-functions", 26 | "transform-class-properties", 27 | "transform-flow-strip-types", 28 | "transform-object-rest-spread", 29 | "transform-regenerator", 30 | "transform-runtime" 31 | ] 32 | }, 33 | "scripts": { 34 | "build": "babel src --ignore __tests__ --out-dir ./ && gulp flow" 35 | }, 36 | "files": [ 37 | "LICENSE", 38 | "README.md", 39 | "index.js", 40 | "index.js.flow", 41 | "index.js.map", 42 | "graphql.js", 43 | "graphql.js.flow", 44 | "graphql.js.map", 45 | "error/", 46 | "execution/", 47 | "jsutils/", 48 | "language/", 49 | "type/", 50 | "utilities/", 51 | "validation/" 52 | ], 53 | "dependencies": { 54 | "iterall": "1.0.2" 55 | }, 56 | "devDependencies": { 57 | "babel-cli": "6.10.1", 58 | "babel-eslint": "6.1.0", 59 | "babel-plugin-check-es2015-constants": "6.8.0", 60 | "babel-plugin-syntax-async-functions": "6.8.0", 61 | "babel-plugin-transform-class-properties": "6.10.2", 62 | "babel-plugin-transform-es2015-arrow-functions": "6.8.0", 63 | "babel-plugin-transform-es2015-block-scoped-functions": "6.8.0", 64 | "babel-plugin-transform-es2015-block-scoping": "6.10.1", 65 | "babel-plugin-transform-es2015-classes": "6.9.0", 66 | "babel-plugin-transform-es2015-computed-properties": "6.8.0", 67 | "babel-plugin-transform-es2015-destructuring": "6.9.0", 68 | "babel-plugin-transform-es2015-duplicate-keys": "6.8.0", 69 | "babel-plugin-transform-es2015-function-name": "6.9.0", 70 | "babel-plugin-transform-es2015-literals": "6.8.0", 71 | "babel-plugin-transform-es2015-modules-commonjs": "6.10.3", 72 | "babel-plugin-transform-es2015-object-super": "6.8.0", 73 | "babel-plugin-transform-es2015-parameters": "6.9.0", 74 | "babel-plugin-transform-es2015-shorthand-properties": "6.8.0", 75 | "babel-plugin-transform-es2015-spread": "6.8.0", 76 | "babel-plugin-transform-es2015-template-literals": "6.8.0", 77 | "babel-plugin-transform-flow-strip-types": "6.8.0", 78 | "babel-plugin-transform-object-rest-spread": "6.8.0", 79 | "babel-plugin-transform-regenerator": "6.9.0", 80 | "babel-preset-fbjs": "^2.0.0", 81 | "eslint": "3.1.1", 82 | "eslint-plugin-babel": "3.3.0", 83 | "eslint-plugin-flow-vars": "^0.4.0", 84 | "eslint-plugin-flowtype": "2.3.1", 85 | "flow-bin": "0.32.0" 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /type/index.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | // GraphQL Schema definition 12 | export { GraphQLSchema } from './schema'; 13 | 14 | export { 15 | // Predicates 16 | isType, 17 | isInputType, 18 | isOutputType, 19 | isLeafType, 20 | isCompositeType, 21 | isAbstractType, 22 | 23 | // Un-modifiers 24 | getNullableType, 25 | getNamedType, 26 | 27 | // Definitions 28 | GraphQLScalarType, 29 | GraphQLObjectType, 30 | GraphQLInterfaceType, 31 | GraphQLUnionType, 32 | GraphQLEnumType, 33 | GraphQLInputObjectType, 34 | GraphQLList, 35 | GraphQLNonNull, 36 | } from './definition'; 37 | 38 | export { 39 | // "Enum" of Directive Locations 40 | DirectiveLocation, 41 | 42 | // Directives Definition 43 | GraphQLDirective, 44 | 45 | // Built-in Directives defined by the Spec 46 | specifiedDirectives, 47 | GraphQLIncludeDirective, 48 | GraphQLSkipDirective, 49 | GraphQLDeprecatedDirective, 50 | 51 | // Constant Deprecation Reason 52 | DEFAULT_DEPRECATION_REASON, 53 | } from './directives'; 54 | 55 | // Common built-in scalar instances. 56 | export { 57 | GraphQLInt, 58 | GraphQLFloat, 59 | GraphQLString, 60 | GraphQLBoolean, 61 | GraphQLID, 62 | } from './scalars'; 63 | 64 | export { 65 | // "Enum" of Type Kinds 66 | TypeKind, 67 | 68 | // GraphQL Types for introspection. 69 | __Schema, 70 | __Directive, 71 | __DirectiveLocation, 72 | __Type, 73 | __Field, 74 | __InputValue, 75 | __EnumValue, 76 | __TypeKind, 77 | 78 | // Meta-field definitions. 79 | SchemaMetaFieldDef, 80 | TypeMetaFieldDef, 81 | TypeNameMetaFieldDef, 82 | } from './introspection'; 83 | 84 | export type { 85 | OperationDefinition, 86 | Field, 87 | FragmentDefinition, 88 | Value, 89 | GraphQLType, 90 | GraphQLInputType, 91 | GraphQLOutputType, 92 | GraphQLLeafType, 93 | GraphQLCompositeType, 94 | GraphQLAbstractType, 95 | GraphQLNullableType, 96 | GraphQLNamedType, 97 | GraphQLScalarTypeConfig, 98 | GraphQLObjectTypeConfig, 99 | GraphQLTypeResolveFn, 100 | GraphQLIsTypeOfFn, 101 | GraphQLFieldResolveFn, 102 | GraphQLResolveInfo, 103 | GraphQLFieldConfig, 104 | GraphQLFieldConfigArgumentMap, 105 | GraphQLArgumentConfig, 106 | GraphQLFieldConfigMap, 107 | GraphQLFieldDefinition, 108 | GraphQLArgument, 109 | GraphQLFieldDefinitionMap, 110 | GraphQLInterfaceTypeConfig, 111 | GraphQLUnionTypeConfig, 112 | GraphQLEnumTypeConfig, 113 | GraphQLEnumValueConfigMap, 114 | GraphQLEnumValueConfig, 115 | GraphQLEnumValueDefinition, 116 | InputObjectConfig, 117 | InputObjectFieldConfig, 118 | InputObjectConfigFieldMap, 119 | InputObjectField, 120 | InputObjectFieldMap 121 | } from './definition'; 122 | -------------------------------------------------------------------------------- /type/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["type/index.js"],"names":[],"mappings":";;;;;;;;;;;mBAWS;;;;;;;;;uBAIP;;;;;;uBACA;;;;;;uBACA;;;;;;uBACA;;;;;;uBACA;;;;;;uBACA;;;;;;uBAGA;;;;;;uBACA;;;;;;uBAGA;;;;;;uBACA;;;;;;uBACA;;;;;;uBACA;;;;;;uBACA;;;;;;uBACA;;;;;;uBACA;;;;;;uBACA;;;;;;;;;uBAKA;;;;;;uBAGA;;;;;;uBAGA;;;;;;uBACA;;;;;;uBACA;;;;;;uBACA;;;;;;uBAGA;;;;;;;;;oBAKA;;;;;;oBACA;;;;;;oBACA;;;;;;oBACA;;;;;;oBACA;;;;;;;;;0BAKA;;;;;;0BAGA;;;;;;0BACA;;;;;;0BACA;;;;;;0BACA;;;;;;0BACA;;;;;;0BACA;;;;;;0BACA;;;;;;0BACA;;;;;;0BAGA;;;;;;0BACA;;;;;;0BACA","file":"type/index.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n// GraphQL Schema definition\nexport { GraphQLSchema } from './schema';\n\nexport {\n // Predicates\n isType,\n isInputType,\n isOutputType,\n isLeafType,\n isCompositeType,\n isAbstractType,\n\n // Un-modifiers\n getNullableType,\n getNamedType,\n\n // Definitions\n GraphQLScalarType,\n GraphQLObjectType,\n GraphQLInterfaceType,\n GraphQLUnionType,\n GraphQLEnumType,\n GraphQLInputObjectType,\n GraphQLList,\n GraphQLNonNull,\n} from './definition';\n\nexport {\n // \"Enum\" of Directive Locations\n DirectiveLocation,\n\n // Directives Definition\n GraphQLDirective,\n\n // Built-in Directives defined by the Spec\n specifiedDirectives,\n GraphQLIncludeDirective,\n GraphQLSkipDirective,\n GraphQLDeprecatedDirective,\n\n // Constant Deprecation Reason\n DEFAULT_DEPRECATION_REASON,\n} from './directives';\n\n// Common built-in scalar instances.\nexport {\n GraphQLInt,\n GraphQLFloat,\n GraphQLString,\n GraphQLBoolean,\n GraphQLID,\n} from './scalars';\n\nexport {\n // \"Enum\" of Type Kinds\n TypeKind,\n\n // GraphQL Types for introspection.\n __Schema,\n __Directive,\n __DirectiveLocation,\n __Type,\n __Field,\n __InputValue,\n __EnumValue,\n __TypeKind,\n\n // Meta-field definitions.\n SchemaMetaFieldDef,\n TypeMetaFieldDef,\n TypeNameMetaFieldDef,\n} from './introspection';\n\nexport type {\n OperationDefinition,\n Field,\n FragmentDefinition,\n Value,\n GraphQLType,\n GraphQLInputType,\n GraphQLOutputType,\n GraphQLLeafType,\n GraphQLCompositeType,\n GraphQLAbstractType,\n GraphQLNullableType,\n GraphQLNamedType,\n GraphQLScalarTypeConfig,\n GraphQLObjectTypeConfig,\n GraphQLTypeResolveFn,\n GraphQLIsTypeOfFn,\n GraphQLFieldResolveFn,\n GraphQLResolveInfo,\n GraphQLFieldConfig,\n GraphQLFieldConfigArgumentMap,\n GraphQLArgumentConfig,\n GraphQLFieldConfigMap,\n GraphQLFieldDefinition,\n GraphQLArgument,\n GraphQLFieldDefinitionMap,\n GraphQLInterfaceTypeConfig,\n GraphQLUnionTypeConfig,\n GraphQLEnumTypeConfig,\n GraphQLEnumValueConfigMap,\n GraphQLEnumValueConfig,\n GraphQLEnumValueDefinition,\n InputObjectConfig,\n InputObjectFieldConfig,\n InputObjectConfigFieldMap,\n InputObjectField,\n InputObjectFieldMap\n} from './definition';\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /utilities/assertValidName.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.assertValidName = assertValidName; 7 | 8 | var _invariant = require('../jsutils/invariant'); 9 | 10 | var _invariant2 = _interopRequireDefault(_invariant); 11 | 12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 13 | 14 | var NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/; 15 | 16 | // Helper to assert that provided names are valid. 17 | 18 | /** 19 | * Copyright (c) 2015, Facebook, Inc. 20 | * All rights reserved. 21 | * 22 | * This source code is licensed under the BSD-style license found in the 23 | * LICENSE file in the root directory of this source tree. An additional grant 24 | * of patent rights can be found in the PATENTS file in the same directory. 25 | */ 26 | 27 | function assertValidName(name) { 28 | (0, _invariant2.default)(NAME_RX.test(name), 'Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "' + name + '" does not.'); 29 | } 30 | //# sourceMappingURL=assertValidName.js.map 31 | -------------------------------------------------------------------------------- /utilities/assertValidName.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import invariant from '../jsutils/invariant'; 12 | 13 | 14 | const NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/; 15 | 16 | // Helper to assert that provided names are valid. 17 | export function assertValidName(name: string): void { 18 | invariant( 19 | NAME_RX.test(name), 20 | `Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "${name}" does not.` 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /utilities/assertValidName.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["utilities/assertValidName.js"],"names":[],"mappings":";;;;;QAgBgB;;AANhB;;;;;;AAGA,IAAM,UAAU,0BAAV;;;;;;;;;;;;;AAGC,SAAS,eAAT,CAAyB,IAAzB,EAA6C;AAClD,2BACE,QAAQ,IAAR,CAAa,IAAb,CADF,wDAEsD,oBAFtD,EADkD;CAA7C","file":"utilities/assertValidName.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport invariant from '../jsutils/invariant';\n\n\nconst NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/;\n\n// Helper to assert that provided names are valid.\nexport function assertValidName(name: string): void {\n invariant(\n NAME_RX.test(name),\n `Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but \"${name}\" does not.`\n );\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /utilities/concatAST.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.concatAST = concatAST; 7 | 8 | /** 9 | * Provided a collection of ASTs, presumably each from different files, 10 | * concatenate the ASTs together into batched AST, useful for validating many 11 | * GraphQL source files which together represent one conceptual application. 12 | */ 13 | function concatAST(asts) { 14 | var batchDefinitions = []; 15 | for (var i = 0; i < asts.length; i++) { 16 | var definitions = asts[i].definitions; 17 | for (var j = 0; j < definitions.length; j++) { 18 | batchDefinitions.push(definitions[j]); 19 | } 20 | } 21 | return { 22 | kind: 'Document', 23 | definitions: batchDefinitions 24 | }; 25 | } 26 | /** 27 | * Copyright (c) 2015, Facebook, Inc. 28 | * All rights reserved. 29 | * 30 | * This source code is licensed under the BSD-style license found in the 31 | * LICENSE file in the root directory of this source tree. An additional grant 32 | * of patent rights can be found in the PATENTS file in the same directory. 33 | */ 34 | //# sourceMappingURL=concatAST.js.map 35 | -------------------------------------------------------------------------------- /utilities/concatAST.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { Document } from '../language/ast'; 12 | 13 | 14 | /** 15 | * Provided a collection of ASTs, presumably each from different files, 16 | * concatenate the ASTs together into batched AST, useful for validating many 17 | * GraphQL source files which together represent one conceptual application. 18 | */ 19 | export function concatAST(asts: Array): Document { 20 | const batchDefinitions = []; 21 | for (let i = 0; i < asts.length; i++) { 22 | const definitions = asts[i].definitions; 23 | for (let j = 0; j < definitions.length; j++) { 24 | batchDefinitions.push(definitions[j]); 25 | } 26 | } 27 | return { 28 | kind: 'Document', 29 | definitions: batchDefinitions, 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /utilities/concatAST.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["utilities/concatAST.js"],"names":[],"mappings":";;;;;QAkBgB;;;;;;;AAAT,SAAS,SAAT,CAAmB,IAAnB,EAAoD;AACzD,MAAM,mBAAmB,EAAnB,CADmD;AAEzD,OAAK,IAAI,IAAI,CAAJ,EAAO,IAAI,KAAK,MAAL,EAAa,GAAjC,EAAsC;AACpC,QAAM,cAAc,KAAK,CAAL,EAAQ,WAAR,CADgB;AAEpC,SAAK,IAAI,IAAI,CAAJ,EAAO,IAAI,YAAY,MAAZ,EAAoB,GAAxC,EAA6C;AAC3C,uBAAiB,IAAjB,CAAsB,YAAY,CAAZ,CAAtB,EAD2C;KAA7C;GAFF;AAMA,SAAO;AACL,UAAM,UAAN;AACA,iBAAa,gBAAb;GAFF,CARyD;CAApD","file":"utilities/concatAST.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { Document } from '../language/ast';\n\n\n/**\n * Provided a collection of ASTs, presumably each from different files,\n * concatenate the ASTs together into batched AST, useful for validating many\n * GraphQL source files which together represent one conceptual application.\n */\nexport function concatAST(asts: Array): Document {\n const batchDefinitions = [];\n for (let i = 0; i < asts.length; i++) {\n const definitions = asts[i].definitions;\n for (let j = 0; j < definitions.length; j++) {\n batchDefinitions.push(definitions[j]);\n }\n }\n return {\n kind: 'Document',\n definitions: batchDefinitions,\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /utilities/getOperationAST.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.getOperationAST = getOperationAST; 7 | 8 | var _kinds = require('../language/kinds'); 9 | 10 | /** 11 | * Returns an operation AST given a document AST and optionally an operation 12 | * name. If a name is not provided, an operation is only returned if only one is 13 | * provided in the document. 14 | */ 15 | function getOperationAST(documentAST, operationName) { 16 | var operation = null; 17 | for (var i = 0; i < documentAST.definitions.length; i++) { 18 | var definition = documentAST.definitions[i]; 19 | if (definition.kind === _kinds.OPERATION_DEFINITION) { 20 | if (!operationName) { 21 | // If no operation name was provided, only return an Operation if there 22 | // is one defined in the document. Upon encountering the second, return 23 | // null. 24 | if (operation) { 25 | return null; 26 | } 27 | operation = definition; 28 | } else if (definition.name && definition.name.value === operationName) { 29 | return definition; 30 | } 31 | } 32 | } 33 | return operation; 34 | } 35 | /** 36 | * Copyright (c) 2015, Facebook, Inc. 37 | * All rights reserved. 38 | * 39 | * This source code is licensed under the BSD-style license found in the 40 | * LICENSE file in the root directory of this source tree. An additional grant 41 | * of patent rights can be found in the PATENTS file in the same directory. 42 | */ 43 | //# sourceMappingURL=getOperationAST.js.map 44 | -------------------------------------------------------------------------------- /utilities/getOperationAST.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import { OPERATION_DEFINITION } from '../language/kinds'; 12 | import type { Document, OperationDefinition } from '../language/ast'; 13 | 14 | 15 | /** 16 | * Returns an operation AST given a document AST and optionally an operation 17 | * name. If a name is not provided, an operation is only returned if only one is 18 | * provided in the document. 19 | */ 20 | export function getOperationAST( 21 | documentAST: Document, 22 | operationName: ?string 23 | ): ?OperationDefinition { 24 | let operation = null; 25 | for (let i = 0; i < documentAST.definitions.length; i++) { 26 | const definition = documentAST.definitions[i]; 27 | if (definition.kind === OPERATION_DEFINITION) { 28 | if (!operationName) { 29 | // If no operation name was provided, only return an Operation if there 30 | // is one defined in the document. Upon encountering the second, return 31 | // null. 32 | if (operation) { 33 | return null; 34 | } 35 | operation = definition; 36 | } else if (definition.name && definition.name.value === operationName) { 37 | return definition; 38 | } 39 | } 40 | } 41 | return operation; 42 | } 43 | -------------------------------------------------------------------------------- /utilities/getOperationAST.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["utilities/getOperationAST.js"],"names":[],"mappings":";;;;;QAmBgB;;AAThB;;;;;;;AASO,SAAS,eAAT,CACL,WADK,EAEL,aAFK,EAGiB;AACtB,MAAI,YAAY,IAAZ,CADkB;AAEtB,OAAK,IAAI,IAAI,CAAJ,EAAO,IAAI,YAAY,WAAZ,CAAwB,MAAxB,EAAgC,GAApD,EAAyD;AACvD,QAAM,aAAa,YAAY,WAAZ,CAAwB,CAAxB,CAAb,CADiD;AAEvD,QAAI,WAAW,IAAX,gCAAJ,EAA8C;AAC5C,UAAI,CAAC,aAAD,EAAgB;;;;AAIlB,YAAI,SAAJ,EAAe;AACb,iBAAO,IAAP,CADa;SAAf;AAGA,oBAAY,UAAZ,CAPkB;OAApB,MAQO,IAAI,WAAW,IAAX,IAAmB,WAAW,IAAX,CAAgB,KAAhB,KAA0B,aAA1B,EAAyC;AACrE,eAAO,UAAP,CADqE;OAAhE;KATT;GAFF;AAgBA,SAAO,SAAP,CAlBsB;CAHjB","file":"utilities/getOperationAST.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport { OPERATION_DEFINITION } from '../language/kinds';\nimport type { Document, OperationDefinition } from '../language/ast';\n\n\n/**\n * Returns an operation AST given a document AST and optionally an operation\n * name. If a name is not provided, an operation is only returned if only one is\n * provided in the document.\n */\nexport function getOperationAST(\n documentAST: Document,\n operationName: ?string\n): ?OperationDefinition {\n let operation = null;\n for (let i = 0; i < documentAST.definitions.length; i++) {\n const definition = documentAST.definitions[i];\n if (definition.kind === OPERATION_DEFINITION) {\n if (!operationName) {\n // If no operation name was provided, only return an Operation if there\n // is one defined in the document. Upon encountering the second, return\n // null.\n if (operation) {\n return null;\n }\n operation = definition;\n } else if (definition.name && definition.name.value === operationName) {\n return definition;\n }\n }\n }\n return operation;\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /utilities/index.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | // The GraphQL query recommended for a full schema introspection. 12 | export { introspectionQuery } from './introspectionQuery'; 13 | 14 | // Gets the target Operation from a Document 15 | export { getOperationAST } from './getOperationAST'; 16 | 17 | // Build a GraphQLSchema from an introspection result. 18 | export { buildClientSchema } from './buildClientSchema'; 19 | 20 | // Build a GraphQLSchema from GraphQL Schema language. 21 | export { buildASTSchema, buildSchema } from './buildASTSchema'; 22 | 23 | // Extends an existing GraphQLSchema from a parsed GraphQL Schema language AST. 24 | export { extendSchema } from './extendSchema'; 25 | 26 | // Print a GraphQLSchema to GraphQL Schema language. 27 | export { printSchema, printIntrospectionSchema } from './schemaPrinter'; 28 | 29 | // Create a GraphQLType from a GraphQL language AST. 30 | export { typeFromAST } from './typeFromAST'; 31 | 32 | // Create a JavaScript value from a GraphQL language AST. 33 | export { valueFromAST } from './valueFromAST'; 34 | 35 | // Create a GraphQL language AST from a JavaScript value. 36 | export { astFromValue } from './astFromValue'; 37 | 38 | // A helper to use within recursive-descent visitors which need to be aware of 39 | // the GraphQL type system. 40 | export { TypeInfo } from './TypeInfo'; 41 | 42 | // Determine if JavaScript values adhere to a GraphQL type. 43 | export { isValidJSValue } from './isValidJSValue'; 44 | 45 | // Determine if AST values adhere to a GraphQL type. 46 | export { isValidLiteralValue } from './isValidLiteralValue'; 47 | 48 | // Concatenates multiple AST together. 49 | export { concatAST } from './concatAST'; 50 | 51 | // Separates an AST into an AST per Operation. 52 | export { separateOperations } from './separateOperations'; 53 | 54 | // Comparators for types 55 | export { 56 | isEqualType, 57 | isTypeSubTypeOf, 58 | doTypesOverlap 59 | } from './typeComparators'; 60 | 61 | // Asserts that a string is a valid GraphQL name 62 | export { assertValidName } from './assertValidName'; 63 | -------------------------------------------------------------------------------- /utilities/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["utilities/index.js"],"names":[],"mappings":";;;;;;;;;;;+BAWS;;;;;;;;;4BAGA;;;;;;;;;8BAGA;;;;;;;;;2BAGA;;;;;;2BAAgB;;;;;;;;;yBAGhB;;;;;;;;;0BAGA;;;;;;0BAAa;;;;;;;;;wBAGb;;;;;;;;;yBAGA;;;;;;;;;yBAGA;;;;;;;;;qBAIA;;;;;;;;;2BAGA;;;;;;;;;gCAGA;;;;;;;;;sBAGA;;;;;;;;;+BAGA;;;;;;;;;4BAIP;;;;;;4BACA;;;;;;4BACA;;;;;;;;;4BAIO","file":"utilities/index.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n// The GraphQL query recommended for a full schema introspection.\nexport { introspectionQuery } from './introspectionQuery';\n\n// Gets the target Operation from a Document\nexport { getOperationAST } from './getOperationAST';\n\n// Build a GraphQLSchema from an introspection result.\nexport { buildClientSchema } from './buildClientSchema';\n\n// Build a GraphQLSchema from GraphQL Schema language.\nexport { buildASTSchema, buildSchema } from './buildASTSchema';\n\n// Extends an existing GraphQLSchema from a parsed GraphQL Schema language AST.\nexport { extendSchema } from './extendSchema';\n\n// Print a GraphQLSchema to GraphQL Schema language.\nexport { printSchema, printIntrospectionSchema } from './schemaPrinter';\n\n// Create a GraphQLType from a GraphQL language AST.\nexport { typeFromAST } from './typeFromAST';\n\n// Create a JavaScript value from a GraphQL language AST.\nexport { valueFromAST } from './valueFromAST';\n\n// Create a GraphQL language AST from a JavaScript value.\nexport { astFromValue } from './astFromValue';\n\n// A helper to use within recursive-descent visitors which need to be aware of\n// the GraphQL type system.\nexport { TypeInfo } from './TypeInfo';\n\n// Determine if JavaScript values adhere to a GraphQL type.\nexport { isValidJSValue } from './isValidJSValue';\n\n// Determine if AST values adhere to a GraphQL type.\nexport { isValidLiteralValue } from './isValidLiteralValue';\n\n// Concatenates multiple AST together.\nexport { concatAST } from './concatAST';\n\n// Separates an AST into an AST per Operation.\nexport { separateOperations } from './separateOperations';\n\n// Comparators for types\nexport {\n isEqualType,\n isTypeSubTypeOf,\n doTypesOverlap\n} from './typeComparators';\n\n// Asserts that a string is a valid GraphQL name\nexport { assertValidName } from './assertValidName';\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /utilities/introspectionQuery.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | var introspectionQuery = exports.introspectionQuery = '\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n'; 7 | /** 8 | * Copyright (c) 2015, Facebook, Inc. 9 | * All rights reserved. 10 | * 11 | * This source code is licensed under the BSD-style license found in the 12 | * LICENSE file in the root directory of this source tree. An additional grant 13 | * of patent rights can be found in the PATENTS file in the same directory. 14 | */ 15 | //# sourceMappingURL=introspectionQuery.js.map 16 | -------------------------------------------------------------------------------- /utilities/separateOperations.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.separateOperations = separateOperations; 7 | 8 | var _visitor = require('../language/visitor'); 9 | 10 | /** 11 | * separateOperations accepts a single AST document which may contain many 12 | * operations and fragments and returns a collection of AST documents each of 13 | * which contains a single operation as well the fragment definitions it 14 | * refers to. 15 | */ 16 | function separateOperations(documentAST) { 17 | 18 | var operations = []; 19 | var depGraph = Object.create(null); 20 | var fromName = undefined; 21 | 22 | // Populate the list of operations and build a dependency graph. 23 | (0, _visitor.visit)(documentAST, { 24 | OperationDefinition: function OperationDefinition(node) { 25 | operations.push(node); 26 | fromName = opName(node); 27 | }, 28 | FragmentDefinition: function FragmentDefinition(node) { 29 | fromName = node.name.value; 30 | }, 31 | FragmentSpread: function FragmentSpread(node) { 32 | var toName = node.name.value; 33 | (depGraph[fromName] || (depGraph[fromName] = Object.create(null)))[toName] = true; 34 | } 35 | }); 36 | 37 | // For each operation, produce a new synthesized AST which includes only what 38 | // is necessary for completing that operation. 39 | var separatedDocumentASTs = Object.create(null); 40 | operations.forEach(function (operation) { 41 | var operationName = opName(operation); 42 | var dependencies = Object.create(null); 43 | collectTransitiveDependencies(dependencies, depGraph, operationName); 44 | 45 | separatedDocumentASTs[operationName] = { 46 | kind: 'Document', 47 | definitions: documentAST.definitions.filter(function (def) { 48 | return def === operation || def.kind === 'FragmentDefinition' && dependencies[def.name.value]; 49 | }) 50 | }; 51 | }); 52 | 53 | return separatedDocumentASTs; 54 | } 55 | /** 56 | * Copyright (c) 2015, Facebook, Inc. 57 | * All rights reserved. 58 | * 59 | * This source code is licensed under the BSD-style license found in the 60 | * LICENSE file in the root directory of this source tree. An additional grant 61 | * of patent rights can be found in the PATENTS file in the same directory. 62 | */ 63 | 64 | // Provides the empty string for anonymous operations. 65 | function opName(operation) { 66 | return operation.name ? operation.name.value : ''; 67 | } 68 | 69 | // From a dependency graph, collects a list of transitive dependencies by 70 | // recursing through a dependency graph. 71 | function collectTransitiveDependencies(collected, depGraph, fromName) { 72 | var immediateDeps = depGraph[fromName]; 73 | if (immediateDeps) { 74 | Object.keys(immediateDeps).forEach(function (toName) { 75 | if (!collected[toName]) { 76 | collected[toName] = true; 77 | collectTransitiveDependencies(collected, depGraph, toName); 78 | } 79 | }); 80 | } 81 | } 82 | //# sourceMappingURL=separateOperations.js.map 83 | -------------------------------------------------------------------------------- /utilities/separateOperations.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import { visit } from '../language/visitor'; 12 | import type { 13 | Document, 14 | OperationDefinition, 15 | } from '../language/ast'; 16 | 17 | /** 18 | * separateOperations accepts a single AST document which may contain many 19 | * operations and fragments and returns a collection of AST documents each of 20 | * which contains a single operation as well the fragment definitions it 21 | * refers to. 22 | */ 23 | export function separateOperations( 24 | documentAST: Document 25 | ): { [operationName: string]: Document } { 26 | 27 | const operations = []; 28 | const depGraph: DepGraph = Object.create(null); 29 | let fromName; 30 | 31 | // Populate the list of operations and build a dependency graph. 32 | visit(documentAST, { 33 | OperationDefinition(node) { 34 | operations.push(node); 35 | fromName = opName(node); 36 | }, 37 | FragmentDefinition(node) { 38 | fromName = node.name.value; 39 | }, 40 | FragmentSpread(node) { 41 | const toName = node.name.value; 42 | (depGraph[fromName] || 43 | (depGraph[fromName] = Object.create(null)))[toName] = true; 44 | } 45 | }); 46 | 47 | // For each operation, produce a new synthesized AST which includes only what 48 | // is necessary for completing that operation. 49 | const separatedDocumentASTs = Object.create(null); 50 | operations.forEach(operation => { 51 | const operationName = opName(operation); 52 | const dependencies = Object.create(null); 53 | collectTransitiveDependencies(dependencies, depGraph, operationName); 54 | 55 | separatedDocumentASTs[operationName] = { 56 | kind: 'Document', 57 | definitions: documentAST.definitions.filter(def => 58 | def === operation || 59 | def.kind === 'FragmentDefinition' && dependencies[def.name.value] 60 | ) 61 | }; 62 | }); 63 | 64 | return separatedDocumentASTs; 65 | } 66 | 67 | type DepGraph = {[from: string]: {[to: string]: boolean}}; 68 | 69 | // Provides the empty string for anonymous operations. 70 | function opName(operation: OperationDefinition): string { 71 | return operation.name ? operation.name.value : ''; 72 | } 73 | 74 | // From a dependency graph, collects a list of transitive dependencies by 75 | // recursing through a dependency graph. 76 | function collectTransitiveDependencies( 77 | collected: {[key: string]: boolean}, 78 | depGraph: DepGraph, 79 | fromName: string 80 | ): void { 81 | const immediateDeps = depGraph[fromName]; 82 | if (immediateDeps) { 83 | Object.keys(immediateDeps).forEach(toName => { 84 | if (!collected[toName]) { 85 | collected[toName] = true; 86 | collectTransitiveDependencies(collected, depGraph, toName); 87 | } 88 | }); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /utilities/typeFromAST.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.typeFromAST = typeFromAST; 7 | 8 | var _invariant = require('../jsutils/invariant'); 9 | 10 | var _invariant2 = _interopRequireDefault(_invariant); 11 | 12 | var _kinds = require('../language/kinds'); 13 | 14 | var _definition = require('../type/definition'); 15 | 16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 17 | 18 | function typeFromAST(schema, inputTypeAST) { 19 | var innerType = undefined; 20 | if (inputTypeAST.kind === _kinds.LIST_TYPE) { 21 | innerType = typeFromAST(schema, inputTypeAST.type); 22 | return innerType && new _definition.GraphQLList(innerType); 23 | } 24 | if (inputTypeAST.kind === _kinds.NON_NULL_TYPE) { 25 | innerType = typeFromAST(schema, inputTypeAST.type); 26 | return innerType && new _definition.GraphQLNonNull(innerType); 27 | } 28 | (0, _invariant2.default)(inputTypeAST.kind === _kinds.NAMED_TYPE, 'Must be a named type.'); 29 | return schema.getType(inputTypeAST.name.value); 30 | } 31 | /** 32 | * Copyright (c) 2015, Facebook, Inc. 33 | * All rights reserved. 34 | * 35 | * This source code is licensed under the BSD-style license found in the 36 | * LICENSE file in the root directory of this source tree. An additional grant 37 | * of patent rights can be found in the PATENTS file in the same directory. 38 | */ 39 | //# sourceMappingURL=typeFromAST.js.map 40 | -------------------------------------------------------------------------------- /utilities/typeFromAST.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import invariant from '../jsutils/invariant'; 12 | import { NAMED_TYPE, LIST_TYPE, NON_NULL_TYPE } from '../language/kinds'; 13 | import type { Type } from '../language/ast'; 14 | import { GraphQLList, GraphQLNonNull } from '../type/definition'; 15 | import type { GraphQLType, GraphQLNullableType } from '../type/definition'; 16 | import type { GraphQLSchema } from '../type/schema'; 17 | 18 | 19 | export function typeFromAST( 20 | schema: GraphQLSchema, 21 | inputTypeAST: Type 22 | ): ?GraphQLType { 23 | let innerType; 24 | if (inputTypeAST.kind === LIST_TYPE) { 25 | innerType = typeFromAST(schema, inputTypeAST.type); 26 | return innerType && new GraphQLList(innerType); 27 | } 28 | if (inputTypeAST.kind === NON_NULL_TYPE) { 29 | innerType = typeFromAST(schema, inputTypeAST.type); 30 | return innerType && new GraphQLNonNull( 31 | ((innerType: any): GraphQLNullableType) 32 | ); 33 | } 34 | invariant(inputTypeAST.kind === NAMED_TYPE, 'Must be a named type.'); 35 | return schema.getType(inputTypeAST.name.value); 36 | } 37 | -------------------------------------------------------------------------------- /utilities/typeFromAST.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["utilities/typeFromAST.js"],"names":[],"mappings":";;;;;QAkBgB;;AARhB;;;;AACA;;AAEA;;;;AAKO,SAAS,WAAT,CACL,MADK,EAEL,YAFK,EAGS;AACd,MAAI,qBAAJ,CADc;AAEd,MAAI,aAAa,IAAb,qBAAJ,EAAqC;AACnC,gBAAY,YAAY,MAAZ,EAAoB,aAAa,IAAb,CAAhC,CADmC;AAEnC,WAAO,aAAa,4BAAgB,SAAhB,CAAb,CAF4B;GAArC;AAIA,MAAI,aAAa,IAAb,yBAAJ,EAAyC;AACvC,gBAAY,YAAY,MAAZ,EAAoB,aAAa,IAAb,CAAhC,CADuC;AAEvC,WAAO,aAAa,+BAChB,SADgB,CAAb,CAFgC;GAAzC;AAMA,2BAAU,aAAa,IAAb,sBAAV,EAA4C,uBAA5C,EAZc;AAad,SAAO,OAAO,OAAP,CAAe,aAAa,IAAb,CAAkB,KAAlB,CAAtB,CAbc;CAHT","file":"utilities/typeFromAST.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport invariant from '../jsutils/invariant';\nimport { NAMED_TYPE, LIST_TYPE, NON_NULL_TYPE } from '../language/kinds';\nimport type { Type } from '../language/ast';\nimport { GraphQLList, GraphQLNonNull } from '../type/definition';\nimport type { GraphQLType, GraphQLNullableType } from '../type/definition';\nimport type { GraphQLSchema } from '../type/schema';\n\n\nexport function typeFromAST(\n schema: GraphQLSchema,\n inputTypeAST: Type\n): ?GraphQLType {\n let innerType;\n if (inputTypeAST.kind === LIST_TYPE) {\n innerType = typeFromAST(schema, inputTypeAST.type);\n return innerType && new GraphQLList(innerType);\n }\n if (inputTypeAST.kind === NON_NULL_TYPE) {\n innerType = typeFromAST(schema, inputTypeAST.type);\n return innerType && new GraphQLNonNull(\n ((innerType: any): GraphQLNullableType)\n );\n }\n invariant(inputTypeAST.kind === NAMED_TYPE, 'Must be a named type.');\n return schema.getType(inputTypeAST.name.value);\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | 7 | var _validate = require('./validate'); 8 | 9 | Object.defineProperty(exports, 'validate', { 10 | enumerable: true, 11 | get: function get() { 12 | return _validate.validate; 13 | } 14 | }); 15 | 16 | var _specifiedRules = require('./specifiedRules'); 17 | 18 | Object.defineProperty(exports, 'specifiedRules', { 19 | enumerable: true, 20 | get: function get() { 21 | return _specifiedRules.specifiedRules; 22 | } 23 | }); 24 | //# sourceMappingURL=index.js.map 25 | -------------------------------------------------------------------------------- /validation/index.js.flow: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | export { validate } from './validate'; 11 | export { specifiedRules } from './specifiedRules'; 12 | -------------------------------------------------------------------------------- /validation/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/index.js"],"names":[],"mappings":";;;;;;;;;;;qBASS;;;;;;;;;2BACA","file":"validation/index.js","sourcesContent":["/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nexport { validate } from './validate';\nexport { specifiedRules } from './specifiedRules';\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/ArgumentsOfCorrectType.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.badValueMessage = badValueMessage; 7 | exports.ArgumentsOfCorrectType = ArgumentsOfCorrectType; 8 | 9 | var _error = require('../../error'); 10 | 11 | var _printer = require('../../language/printer'); 12 | 13 | var _isValidLiteralValue = require('../../utilities/isValidLiteralValue'); 14 | 15 | /** 16 | * Copyright (c) 2015, Facebook, Inc. 17 | * All rights reserved. 18 | * 19 | * This source code is licensed under the BSD-style license found in the 20 | * LICENSE file in the root directory of this source tree. An additional grant 21 | * of patent rights can be found in the PATENTS file in the same directory. 22 | */ 23 | 24 | function badValueMessage(argName, type, value, verboseErrors) { 25 | var message = verboseErrors ? '\n' + verboseErrors.join('\n') : ''; 26 | return 'Argument "' + argName + '" has invalid value ' + value + '.' + message; 27 | } 28 | 29 | /** 30 | * Argument values of correct type 31 | * 32 | * A GraphQL document is only valid if all field argument literal values are 33 | * of the type expected by their position. 34 | */ 35 | function ArgumentsOfCorrectType(context) { 36 | return { 37 | Argument: function Argument(argAST) { 38 | var argDef = context.getArgument(); 39 | if (argDef) { 40 | var errors = (0, _isValidLiteralValue.isValidLiteralValue)(argDef.type, argAST.value); 41 | if (errors && errors.length > 0) { 42 | context.reportError(new _error.GraphQLError(badValueMessage(argAST.name.value, argDef.type, (0, _printer.print)(argAST.value), errors), [argAST.value])); 43 | } 44 | } 45 | return false; 46 | } 47 | }; 48 | } 49 | //# sourceMappingURL=ArgumentsOfCorrectType.js.map 50 | -------------------------------------------------------------------------------- /validation/rules/ArgumentsOfCorrectType.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import { print } from '../../language/printer'; 14 | import { isValidLiteralValue } from '../../utilities/isValidLiteralValue'; 15 | import type { GraphQLType } from '../../type/definition'; 16 | 17 | 18 | export function badValueMessage( 19 | argName: string, 20 | type: GraphQLType, 21 | value: string, 22 | verboseErrors?: [string] 23 | ): string { 24 | const message = verboseErrors ? '\n' + verboseErrors.join('\n') : ''; 25 | return ( 26 | `Argument "${argName}" has invalid value ${value}.${message}` 27 | ); 28 | } 29 | 30 | /** 31 | * Argument values of correct type 32 | * 33 | * A GraphQL document is only valid if all field argument literal values are 34 | * of the type expected by their position. 35 | */ 36 | export function ArgumentsOfCorrectType(context: ValidationContext): any { 37 | return { 38 | Argument(argAST) { 39 | const argDef = context.getArgument(); 40 | if (argDef) { 41 | const errors = isValidLiteralValue(argDef.type, argAST.value); 42 | if (errors && errors.length > 0) { 43 | context.reportError(new GraphQLError( 44 | badValueMessage( 45 | argAST.name.value, 46 | argDef.type, 47 | print(argAST.value), 48 | errors 49 | ), 50 | [ argAST.value ] 51 | )); 52 | } 53 | } 54 | return false; 55 | } 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /validation/rules/ArgumentsOfCorrectType.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/ArgumentsOfCorrectType.js"],"names":[],"mappings":";;;;;QAiBgB;QAkBA;;AAxBhB;;AACA;;AACA;;;;;;;;;;;AAIO,SAAS,eAAT,CACL,OADK,EAEL,IAFK,EAGL,KAHK,EAIL,aAJK,EAKG;AACR,MAAM,UAAU,gBAAgB,OAAO,cAAc,IAAd,CAAmB,IAAnB,CAAP,GAAkC,EAAlD,CADR;AAER,wBACe,mCAA8B,cAAS,OADtD,CAFQ;CALH;;;;;;;;AAkBA,SAAS,sBAAT,CAAgC,OAAhC,EAAiE;AACtE,SAAO;AACL,gCAAS,QAAQ;AACf,UAAM,SAAS,QAAQ,WAAR,EAAT,CADS;AAEf,UAAI,MAAJ,EAAY;AACV,YAAM,SAAS,8CAAoB,OAAO,IAAP,EAAa,OAAO,KAAP,CAA1C,CADI;AAEV,YAAI,UAAU,OAAO,MAAP,GAAgB,CAAhB,EAAmB;AAC/B,kBAAQ,WAAR,CAAoB,wBAClB,gBACE,OAAO,IAAP,CAAY,KAAZ,EACA,OAAO,IAAP,EACA,oBAAM,OAAO,KAAP,CAHR,EAIE,MAJF,CADkB,EAOlB,CAAE,OAAO,KAAP,CAPgB,CAApB,EAD+B;SAAjC;OAFF;AAcA,aAAO,KAAP,CAhBe;KADZ;GAAP,CADsE;CAAjE","file":"validation/rules/ArgumentsOfCorrectType.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\nimport { print } from '../../language/printer';\nimport { isValidLiteralValue } from '../../utilities/isValidLiteralValue';\nimport type { GraphQLType } from '../../type/definition';\n\n\nexport function badValueMessage(\n argName: string,\n type: GraphQLType,\n value: string,\n verboseErrors?: [string]\n): string {\n const message = verboseErrors ? '\\n' + verboseErrors.join('\\n') : '';\n return (\n `Argument \"${argName}\" has invalid value ${value}.${message}`\n );\n}\n\n/**\n * Argument values of correct type\n *\n * A GraphQL document is only valid if all field argument literal values are\n * of the type expected by their position.\n */\nexport function ArgumentsOfCorrectType(context: ValidationContext): any {\n return {\n Argument(argAST) {\n const argDef = context.getArgument();\n if (argDef) {\n const errors = isValidLiteralValue(argDef.type, argAST.value);\n if (errors && errors.length > 0) {\n context.reportError(new GraphQLError(\n badValueMessage(\n argAST.name.value,\n argDef.type,\n print(argAST.value),\n errors\n ),\n [ argAST.value ]\n ));\n }\n }\n return false;\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/DefaultValuesOfCorrectType.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.defaultForNonNullArgMessage = defaultForNonNullArgMessage; 7 | exports.badValueForDefaultArgMessage = badValueForDefaultArgMessage; 8 | exports.DefaultValuesOfCorrectType = DefaultValuesOfCorrectType; 9 | 10 | var _error = require('../../error'); 11 | 12 | var _printer = require('../../language/printer'); 13 | 14 | var _definition = require('../../type/definition'); 15 | 16 | var _isValidLiteralValue = require('../../utilities/isValidLiteralValue'); 17 | 18 | function defaultForNonNullArgMessage(varName, type, guessType) { 19 | return 'Variable "$' + varName + '" of type "' + String(type) + '" is required and ' + 'will not use the default value. ' + ('Perhaps you meant to use type "' + String(guessType) + '".'); 20 | } 21 | /** 22 | * Copyright (c) 2015, Facebook, Inc. 23 | * All rights reserved. 24 | * 25 | * This source code is licensed under the BSD-style license found in the 26 | * LICENSE file in the root directory of this source tree. An additional grant 27 | * of patent rights can be found in the PATENTS file in the same directory. 28 | */ 29 | 30 | function badValueForDefaultArgMessage(varName, type, value, verboseErrors) { 31 | var message = verboseErrors ? '\n' + verboseErrors.join('\n') : ''; 32 | return 'Variable "$' + varName + '" of type "' + String(type) + '" has invalid ' + ('default value ' + value + '.' + message); 33 | } 34 | 35 | /** 36 | * Variable default values of correct type 37 | * 38 | * A GraphQL document is only valid if all variable default values are of the 39 | * type expected by their definition. 40 | */ 41 | function DefaultValuesOfCorrectType(context) { 42 | return { 43 | VariableDefinition: function VariableDefinition(varDefAST) { 44 | var name = varDefAST.variable.name.value; 45 | var defaultValue = varDefAST.defaultValue; 46 | var type = context.getInputType(); 47 | if (type instanceof _definition.GraphQLNonNull && defaultValue) { 48 | context.reportError(new _error.GraphQLError(defaultForNonNullArgMessage(name, type, type.ofType), [defaultValue])); 49 | } 50 | if (type && defaultValue) { 51 | var errors = (0, _isValidLiteralValue.isValidLiteralValue)(type, defaultValue); 52 | if (errors && errors.length > 0) { 53 | context.reportError(new _error.GraphQLError(badValueForDefaultArgMessage(name, type, (0, _printer.print)(defaultValue), errors), [defaultValue])); 54 | } 55 | } 56 | return false; 57 | }, 58 | 59 | SelectionSet: function SelectionSet() { 60 | return false; 61 | }, 62 | FragmentDefinition: function FragmentDefinition() { 63 | return false; 64 | } 65 | }; 66 | } 67 | //# sourceMappingURL=DefaultValuesOfCorrectType.js.map 68 | -------------------------------------------------------------------------------- /validation/rules/DefaultValuesOfCorrectType.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import { print } from '../../language/printer'; 14 | import { GraphQLNonNull } from '../../type/definition'; 15 | import { isValidLiteralValue } from '../../utilities/isValidLiteralValue'; 16 | import type { GraphQLType } from '../../type/definition'; 17 | 18 | 19 | export function defaultForNonNullArgMessage( 20 | varName: string, 21 | type: GraphQLType, 22 | guessType: GraphQLType 23 | ): string { 24 | return `Variable "$${varName}" of type "${String(type)}" is required and ` + 25 | 'will not use the default value. ' + 26 | `Perhaps you meant to use type "${String(guessType)}".`; 27 | } 28 | 29 | export function badValueForDefaultArgMessage( 30 | varName: string, 31 | type: GraphQLType, 32 | value: string, 33 | verboseErrors?: [string] 34 | ): string { 35 | const message = verboseErrors ? '\n' + verboseErrors.join('\n') : ''; 36 | return `Variable "$${varName}" of type "${String(type)}" has invalid ` + 37 | `default value ${value}.${message}`; 38 | } 39 | 40 | /** 41 | * Variable default values of correct type 42 | * 43 | * A GraphQL document is only valid if all variable default values are of the 44 | * type expected by their definition. 45 | */ 46 | export function DefaultValuesOfCorrectType(context: ValidationContext): any { 47 | return { 48 | VariableDefinition(varDefAST) { 49 | const name = varDefAST.variable.name.value; 50 | const defaultValue = varDefAST.defaultValue; 51 | const type = context.getInputType(); 52 | if (type instanceof GraphQLNonNull && defaultValue) { 53 | context.reportError(new GraphQLError( 54 | defaultForNonNullArgMessage(name, type, type.ofType), 55 | [ defaultValue ] 56 | )); 57 | } 58 | if (type && defaultValue) { 59 | const errors = isValidLiteralValue(type, defaultValue); 60 | if (errors && errors.length > 0) { 61 | context.reportError(new GraphQLError( 62 | badValueForDefaultArgMessage( 63 | name, 64 | type, 65 | print(defaultValue), 66 | errors 67 | ), 68 | [ defaultValue ] 69 | )); 70 | } 71 | } 72 | return false; 73 | }, 74 | SelectionSet: () => false, 75 | FragmentDefinition: () => false, 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /validation/rules/FragmentsOnCompositeTypes.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.inlineFragmentOnNonCompositeErrorMessage = inlineFragmentOnNonCompositeErrorMessage; 7 | exports.fragmentOnNonCompositeErrorMessage = fragmentOnNonCompositeErrorMessage; 8 | exports.FragmentsOnCompositeTypes = FragmentsOnCompositeTypes; 9 | 10 | var _error = require('../../error'); 11 | 12 | var _printer = require('../../language/printer'); 13 | 14 | var _definition = require('../../type/definition'); 15 | 16 | /** 17 | * Copyright (c) 2015, Facebook, Inc. 18 | * All rights reserved. 19 | * 20 | * This source code is licensed under the BSD-style license found in the 21 | * LICENSE file in the root directory of this source tree. An additional grant 22 | * of patent rights can be found in the PATENTS file in the same directory. 23 | */ 24 | 25 | function inlineFragmentOnNonCompositeErrorMessage(type) { 26 | return 'Fragment cannot condition on non composite type "' + String(type) + '".'; 27 | } 28 | 29 | function fragmentOnNonCompositeErrorMessage(fragName, type) { 30 | return 'Fragment "' + fragName + '" cannot condition on non composite ' + ('type "' + String(type) + '".'); 31 | } 32 | 33 | /** 34 | * Fragments on composite type 35 | * 36 | * Fragments use a type condition to determine if they apply, since fragments 37 | * can only be spread into a composite type (object, interface, or union), the 38 | * type condition must also be a composite type. 39 | */ 40 | function FragmentsOnCompositeTypes(context) { 41 | return { 42 | InlineFragment: function InlineFragment(node) { 43 | var type = context.getType(); 44 | if (node.typeCondition && type && !(0, _definition.isCompositeType)(type)) { 45 | context.reportError(new _error.GraphQLError(inlineFragmentOnNonCompositeErrorMessage((0, _printer.print)(node.typeCondition)), [node.typeCondition])); 46 | } 47 | }, 48 | FragmentDefinition: function FragmentDefinition(node) { 49 | var type = context.getType(); 50 | if (type && !(0, _definition.isCompositeType)(type)) { 51 | context.reportError(new _error.GraphQLError(fragmentOnNonCompositeErrorMessage(node.name.value, (0, _printer.print)(node.typeCondition)), [node.typeCondition])); 52 | } 53 | } 54 | }; 55 | } 56 | //# sourceMappingURL=FragmentsOnCompositeTypes.js.map 57 | -------------------------------------------------------------------------------- /validation/rules/FragmentsOnCompositeTypes.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import { print } from '../../language/printer'; 14 | import { isCompositeType } from '../../type/definition'; 15 | import type { GraphQLType } from '../../type/definition'; 16 | 17 | 18 | export function inlineFragmentOnNonCompositeErrorMessage( 19 | type: GraphQLType 20 | ): string { 21 | return `Fragment cannot condition on non composite type "${String(type)}".`; 22 | } 23 | 24 | export function fragmentOnNonCompositeErrorMessage( 25 | fragName: string, 26 | type: GraphQLType 27 | ): string { 28 | return `Fragment "${fragName}" cannot condition on non composite ` + 29 | `type "${String(type)}".`; 30 | } 31 | 32 | /** 33 | * Fragments on composite type 34 | * 35 | * Fragments use a type condition to determine if they apply, since fragments 36 | * can only be spread into a composite type (object, interface, or union), the 37 | * type condition must also be a composite type. 38 | */ 39 | export function FragmentsOnCompositeTypes(context: ValidationContext): any { 40 | return { 41 | InlineFragment(node) { 42 | const type = context.getType(); 43 | if (node.typeCondition && type && !isCompositeType(type)) { 44 | context.reportError(new GraphQLError( 45 | inlineFragmentOnNonCompositeErrorMessage(print(node.typeCondition)), 46 | [ node.typeCondition ] 47 | )); 48 | } 49 | }, 50 | FragmentDefinition(node) { 51 | const type = context.getType(); 52 | if (type && !isCompositeType(type)) { 53 | context.reportError(new GraphQLError( 54 | fragmentOnNonCompositeErrorMessage( 55 | node.name.value, 56 | print(node.typeCondition) 57 | ), 58 | [ node.typeCondition ] 59 | )); 60 | } 61 | } 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /validation/rules/FragmentsOnCompositeTypes.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/FragmentsOnCompositeTypes.js"],"names":[],"mappings":";;;;;QAiBgB;QAMA;QAeA;;AA3BhB;;AACA;;AACA;;;;;;;;;;;AAIO,SAAS,wCAAT,CACL,IADK,EAEG;AACR,+DAA2D,OAAO,IAAP,QAA3D,CADQ;CAFH;;AAMA,SAAS,kCAAT,CACL,QADK,EAEL,IAFK,EAGG;AACR,SAAO,eAAa,iDAAb,eACI,OAAO,IAAP,SADJ,CADC;CAHH;;;;;;;;;AAeA,SAAS,yBAAT,CAAmC,OAAnC,EAAoE;AACzE,SAAO;AACL,4CAAe,MAAM;AACnB,UAAM,OAAO,QAAQ,OAAR,EAAP,CADa;AAEnB,UAAI,KAAK,aAAL,IAAsB,IAAtB,IAA8B,CAAC,iCAAgB,IAAhB,CAAD,EAAwB;AACxD,gBAAQ,WAAR,CAAoB,wBAClB,yCAAyC,oBAAM,KAAK,aAAL,CAA/C,CADkB,EAElB,CAAE,KAAK,aAAL,CAFgB,CAApB,EADwD;OAA1D;KAHG;AAUL,oDAAmB,MAAM;AACvB,UAAM,OAAO,QAAQ,OAAR,EAAP,CADiB;AAEvB,UAAI,QAAQ,CAAC,iCAAgB,IAAhB,CAAD,EAAwB;AAClC,gBAAQ,WAAR,CAAoB,wBAClB,mCACE,KAAK,IAAL,CAAU,KAAV,EACA,oBAAM,KAAK,aAAL,CAFR,CADkB,EAKlB,CAAE,KAAK,aAAL,CALgB,CAApB,EADkC;OAApC;KAZG;GAAP,CADyE;CAApE","file":"validation/rules/FragmentsOnCompositeTypes.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\nimport { print } from '../../language/printer';\nimport { isCompositeType } from '../../type/definition';\nimport type { GraphQLType } from '../../type/definition';\n\n\nexport function inlineFragmentOnNonCompositeErrorMessage(\n type: GraphQLType\n): string {\n return `Fragment cannot condition on non composite type \"${String(type)}\".`;\n}\n\nexport function fragmentOnNonCompositeErrorMessage(\n fragName: string,\n type: GraphQLType\n): string {\n return `Fragment \"${fragName}\" cannot condition on non composite ` +\n `type \"${String(type)}\".`;\n}\n\n/**\n * Fragments on composite type\n *\n * Fragments use a type condition to determine if they apply, since fragments\n * can only be spread into a composite type (object, interface, or union), the\n * type condition must also be a composite type.\n */\nexport function FragmentsOnCompositeTypes(context: ValidationContext): any {\n return {\n InlineFragment(node) {\n const type = context.getType();\n if (node.typeCondition && type && !isCompositeType(type)) {\n context.reportError(new GraphQLError(\n inlineFragmentOnNonCompositeErrorMessage(print(node.typeCondition)),\n [ node.typeCondition ]\n ));\n }\n },\n FragmentDefinition(node) {\n const type = context.getType();\n if (type && !isCompositeType(type)) {\n context.reportError(new GraphQLError(\n fragmentOnNonCompositeErrorMessage(\n node.name.value,\n print(node.typeCondition)\n ),\n [ node.typeCondition ]\n ));\n }\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/KnownFragmentNames.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.unknownFragmentMessage = unknownFragmentMessage; 7 | exports.KnownFragmentNames = KnownFragmentNames; 8 | 9 | var _error = require('../../error'); 10 | 11 | /** 12 | * Copyright (c) 2015, Facebook, Inc. 13 | * All rights reserved. 14 | * 15 | * This source code is licensed under the BSD-style license found in the 16 | * LICENSE file in the root directory of this source tree. An additional grant 17 | * of patent rights can be found in the PATENTS file in the same directory. 18 | */ 19 | 20 | function unknownFragmentMessage(fragName) { 21 | return 'Unknown fragment "' + fragName + '".'; 22 | } 23 | 24 | /** 25 | * Known fragment names 26 | * 27 | * A GraphQL document is only valid if all `...Fragment` fragment spreads refer 28 | * to fragments defined in the same document. 29 | */ 30 | function KnownFragmentNames(context) { 31 | return { 32 | FragmentSpread: function FragmentSpread(node) { 33 | var fragmentName = node.name.value; 34 | var fragment = context.getFragment(fragmentName); 35 | if (!fragment) { 36 | context.reportError(new _error.GraphQLError(unknownFragmentMessage(fragmentName), [node.name])); 37 | } 38 | } 39 | }; 40 | } 41 | //# sourceMappingURL=KnownFragmentNames.js.map 42 | -------------------------------------------------------------------------------- /validation/rules/KnownFragmentNames.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | 14 | 15 | export function unknownFragmentMessage(fragName: string): string { 16 | return `Unknown fragment "${fragName}".`; 17 | } 18 | 19 | /** 20 | * Known fragment names 21 | * 22 | * A GraphQL document is only valid if all `...Fragment` fragment spreads refer 23 | * to fragments defined in the same document. 24 | */ 25 | export function KnownFragmentNames(context: ValidationContext): any { 26 | return { 27 | FragmentSpread(node) { 28 | const fragmentName = node.name.value; 29 | const fragment = context.getFragment(fragmentName); 30 | if (!fragment) { 31 | context.reportError(new GraphQLError( 32 | unknownFragmentMessage(fragmentName), 33 | [ node.name ] 34 | )); 35 | } 36 | } 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /validation/rules/KnownFragmentNames.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/KnownFragmentNames.js"],"names":[],"mappings":";;;;;QAcgB;QAUA;;AAbhB;;;;;;;;;;;AAGO,SAAS,sBAAT,CAAgC,QAAhC,EAA0D;AAC/D,gCAA4B,eAA5B,CAD+D;CAA1D;;;;;;;;AAUA,SAAS,kBAAT,CAA4B,OAA5B,EAA6D;AAClE,SAAO;AACL,4CAAe,MAAM;AACnB,UAAM,eAAe,KAAK,IAAL,CAAU,KAAV,CADF;AAEnB,UAAM,WAAW,QAAQ,WAAR,CAAoB,YAApB,CAAX,CAFa;AAGnB,UAAI,CAAC,QAAD,EAAW;AACb,gBAAQ,WAAR,CAAoB,wBAClB,uBAAuB,YAAvB,CADkB,EAElB,CAAE,KAAK,IAAL,CAFgB,CAApB,EADa;OAAf;KAJG;GAAP,CADkE;CAA7D","file":"validation/rules/KnownFragmentNames.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\n\n\nexport function unknownFragmentMessage(fragName: string): string {\n return `Unknown fragment \"${fragName}\".`;\n}\n\n/**\n * Known fragment names\n *\n * A GraphQL document is only valid if all `...Fragment` fragment spreads refer\n * to fragments defined in the same document.\n */\nexport function KnownFragmentNames(context: ValidationContext): any {\n return {\n FragmentSpread(node) {\n const fragmentName = node.name.value;\n const fragment = context.getFragment(fragmentName);\n if (!fragment) {\n context.reportError(new GraphQLError(\n unknownFragmentMessage(fragmentName),\n [ node.name ]\n ));\n }\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/KnownTypeNames.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.unknownTypeMessage = unknownTypeMessage; 7 | exports.KnownTypeNames = KnownTypeNames; 8 | 9 | var _error = require('../../error'); 10 | 11 | var _suggestionList = require('../../jsutils/suggestionList'); 12 | 13 | var _suggestionList2 = _interopRequireDefault(_suggestionList); 14 | 15 | var _quotedOrList = require('../../jsutils/quotedOrList'); 16 | 17 | var _quotedOrList2 = _interopRequireDefault(_quotedOrList); 18 | 19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 20 | 21 | /** 22 | * Copyright (c) 2015, Facebook, Inc. 23 | * All rights reserved. 24 | * 25 | * This source code is licensed under the BSD-style license found in the 26 | * LICENSE file in the root directory of this source tree. An additional grant 27 | * of patent rights can be found in the PATENTS file in the same directory. 28 | */ 29 | 30 | function unknownTypeMessage(type, suggestedTypes) { 31 | var message = 'Unknown type "' + String(type) + '".'; 32 | if (suggestedTypes.length) { 33 | message += ' Did you mean ' + (0, _quotedOrList2.default)(suggestedTypes) + '?'; 34 | } 35 | return message; 36 | } 37 | 38 | /** 39 | * Known type names 40 | * 41 | * A GraphQL document is only valid if referenced types (specifically 42 | * variable definitions and fragment conditions) are defined by the type schema. 43 | */ 44 | function KnownTypeNames(context) { 45 | return { 46 | // TODO: when validating IDL, re-enable these. Experimental version does not 47 | // add unreferenced types, resulting in false-positive errors. Squelched 48 | // errors for now. 49 | ObjectTypeDefinition: function ObjectTypeDefinition() { 50 | return false; 51 | }, 52 | InterfaceTypeDefinition: function InterfaceTypeDefinition() { 53 | return false; 54 | }, 55 | UnionTypeDefinition: function UnionTypeDefinition() { 56 | return false; 57 | }, 58 | InputObjectTypeDefinition: function InputObjectTypeDefinition() { 59 | return false; 60 | }, 61 | NamedType: function NamedType(node) { 62 | var schema = context.getSchema(); 63 | var typeName = node.name.value; 64 | var type = schema.getType(typeName); 65 | if (!type) { 66 | context.reportError(new _error.GraphQLError(unknownTypeMessage(typeName, (0, _suggestionList2.default)(typeName, Object.keys(schema.getTypeMap()))), [node])); 67 | } 68 | } 69 | }; 70 | } 71 | //# sourceMappingURL=KnownTypeNames.js.map 72 | -------------------------------------------------------------------------------- /validation/rules/KnownTypeNames.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import suggestionList from '../../jsutils/suggestionList'; 14 | import quotedOrList from '../../jsutils/quotedOrList'; 15 | import type { GraphQLType } from '../../type/definition'; 16 | 17 | 18 | export function unknownTypeMessage( 19 | type: GraphQLType, 20 | suggestedTypes: Array 21 | ): string { 22 | let message = `Unknown type "${String(type)}".`; 23 | if (suggestedTypes.length) { 24 | message += ` Did you mean ${quotedOrList(suggestedTypes)}?`; 25 | } 26 | return message; 27 | } 28 | 29 | /** 30 | * Known type names 31 | * 32 | * A GraphQL document is only valid if referenced types (specifically 33 | * variable definitions and fragment conditions) are defined by the type schema. 34 | */ 35 | export function KnownTypeNames(context: ValidationContext): any { 36 | return { 37 | // TODO: when validating IDL, re-enable these. Experimental version does not 38 | // add unreferenced types, resulting in false-positive errors. Squelched 39 | // errors for now. 40 | ObjectTypeDefinition: () => false, 41 | InterfaceTypeDefinition: () => false, 42 | UnionTypeDefinition: () => false, 43 | InputObjectTypeDefinition: () => false, 44 | NamedType(node) { 45 | const schema = context.getSchema(); 46 | const typeName = node.name.value; 47 | const type = schema.getType(typeName); 48 | if (!type) { 49 | context.reportError( 50 | new GraphQLError( 51 | unknownTypeMessage( 52 | typeName, 53 | suggestionList(typeName, Object.keys(schema.getTypeMap())) 54 | ), 55 | [ node ] 56 | ) 57 | ); 58 | } 59 | } 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /validation/rules/KnownTypeNames.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/KnownTypeNames.js"],"names":[],"mappings":";;;;;QAiBgB;QAiBA;;AAvBhB;;AACA;;;;AACA;;;;;;;;;;;;;;;AAIO,SAAS,kBAAT,CACL,IADK,EAEL,cAFK,EAGG;AACR,MAAI,6BAA2B,OAAO,IAAP,QAA3B,CADI;AAER,MAAI,eAAe,MAAf,EAAuB;AACzB,kCAA4B,4BAAa,cAAb,OAA5B,CADyB;GAA3B;AAGA,SAAO,OAAP,CALQ;CAHH;;;;;;;;AAiBA,SAAS,cAAT,CAAwB,OAAxB,EAAyD;AAC9D,SAAO;;;;AAIL,0BAAsB;aAAM;KAAN;AACtB,6BAAyB;aAAM;KAAN;AACzB,yBAAqB;aAAM;KAAN;AACrB,+BAA2B;aAAM;KAAN;AAC3B,kCAAU,MAAM;AACd,UAAM,SAAS,QAAQ,SAAR,EAAT,CADQ;AAEd,UAAM,WAAW,KAAK,IAAL,CAAU,KAAV,CAFH;AAGd,UAAM,OAAO,OAAO,OAAP,CAAe,QAAf,CAAP,CAHQ;AAId,UAAI,CAAC,IAAD,EAAO;AACT,gBAAQ,WAAR,CACE,wBACE,mBACE,QADF,EAEE,8BAAe,QAAf,EAAyB,OAAO,IAAP,CAAY,OAAO,UAAP,EAAZ,CAAzB,CAFF,CADF,EAKE,CAAE,IAAF,CALF,CADF,EADS;OAAX;KAZG;GAAP,CAD8D;CAAzD","file":"validation/rules/KnownTypeNames.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\nimport suggestionList from '../../jsutils/suggestionList';\nimport quotedOrList from '../../jsutils/quotedOrList';\nimport type { GraphQLType } from '../../type/definition';\n\n\nexport function unknownTypeMessage(\n type: GraphQLType,\n suggestedTypes: Array\n): string {\n let message = `Unknown type \"${String(type)}\".`;\n if (suggestedTypes.length) {\n message += ` Did you mean ${quotedOrList(suggestedTypes)}?`;\n }\n return message;\n}\n\n/**\n * Known type names\n *\n * A GraphQL document is only valid if referenced types (specifically\n * variable definitions and fragment conditions) are defined by the type schema.\n */\nexport function KnownTypeNames(context: ValidationContext): any {\n return {\n // TODO: when validating IDL, re-enable these. Experimental version does not\n // add unreferenced types, resulting in false-positive errors. Squelched\n // errors for now.\n ObjectTypeDefinition: () => false,\n InterfaceTypeDefinition: () => false,\n UnionTypeDefinition: () => false,\n InputObjectTypeDefinition: () => false,\n NamedType(node) {\n const schema = context.getSchema();\n const typeName = node.name.value;\n const type = schema.getType(typeName);\n if (!type) {\n context.reportError(\n new GraphQLError(\n unknownTypeMessage(\n typeName,\n suggestionList(typeName, Object.keys(schema.getTypeMap()))\n ),\n [ node ]\n )\n );\n }\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/LoneAnonymousOperation.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.anonOperationNotAloneMessage = anonOperationNotAloneMessage; 7 | exports.LoneAnonymousOperation = LoneAnonymousOperation; 8 | 9 | var _error = require('../../error'); 10 | 11 | var _kinds = require('../../language/kinds'); 12 | 13 | function anonOperationNotAloneMessage() { 14 | return 'This anonymous operation must be the only defined operation.'; 15 | } 16 | 17 | /** 18 | * Lone anonymous operation 19 | * 20 | * A GraphQL document is only valid if when it contains an anonymous operation 21 | * (the query short-hand) that it contains only that one operation definition. 22 | */ 23 | 24 | /** 25 | * Copyright (c) 2015, Facebook, Inc. 26 | * All rights reserved. 27 | * 28 | * This source code is licensed under the BSD-style license found in the 29 | * LICENSE file in the root directory of this source tree. An additional grant 30 | * of patent rights can be found in the PATENTS file in the same directory. 31 | */ 32 | 33 | function LoneAnonymousOperation(context) { 34 | var operationCount = 0; 35 | return { 36 | Document: function Document(node) { 37 | operationCount = node.definitions.filter(function (definition) { 38 | return definition.kind === _kinds.OPERATION_DEFINITION; 39 | }).length; 40 | }, 41 | OperationDefinition: function OperationDefinition(node) { 42 | if (!node.name && operationCount > 1) { 43 | context.reportError(new _error.GraphQLError(anonOperationNotAloneMessage(), [node])); 44 | } 45 | } 46 | }; 47 | } 48 | //# sourceMappingURL=LoneAnonymousOperation.js.map 49 | -------------------------------------------------------------------------------- /validation/rules/LoneAnonymousOperation.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import { OPERATION_DEFINITION } from '../../language/kinds'; 14 | 15 | 16 | export function anonOperationNotAloneMessage(): string { 17 | return 'This anonymous operation must be the only defined operation.'; 18 | } 19 | 20 | /** 21 | * Lone anonymous operation 22 | * 23 | * A GraphQL document is only valid if when it contains an anonymous operation 24 | * (the query short-hand) that it contains only that one operation definition. 25 | */ 26 | export function LoneAnonymousOperation(context: ValidationContext): any { 27 | let operationCount = 0; 28 | return { 29 | Document(node) { 30 | operationCount = node.definitions.filter( 31 | definition => definition.kind === OPERATION_DEFINITION 32 | ).length; 33 | }, 34 | OperationDefinition(node) { 35 | if (!node.name && operationCount > 1) { 36 | context.reportError( 37 | new GraphQLError(anonOperationNotAloneMessage(), [ node ]) 38 | ); 39 | } 40 | } 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /validation/rules/LoneAnonymousOperation.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/LoneAnonymousOperation.js"],"names":[],"mappings":";;;;;QAegB;QAUA;;AAdhB;;AACA;;AAGO,SAAS,4BAAT,GAAgD;AACrD,SAAO,8DAAP,CADqD;CAAhD;;;;;;;;;;;;;;;;;;AAUA,SAAS,sBAAT,CAAgC,OAAhC,EAAiE;AACtE,MAAI,iBAAiB,CAAjB,CADkE;AAEtE,SAAO;AACL,gCAAS,MAAM;AACb,uBAAiB,KAAK,WAAL,CAAiB,MAAjB,CACf;eAAc,WAAW,IAAX;OAAd,CADe,CAEf,MAFe,CADJ;KADV;AAML,sDAAoB,MAAM;AACxB,UAAI,CAAC,KAAK,IAAL,IAAa,iBAAiB,CAAjB,EAAoB;AACpC,gBAAQ,WAAR,CACE,wBAAiB,8BAAjB,EAAiD,CAAE,IAAF,CAAjD,CADF,EADoC;OAAtC;KAPG;GAAP,CAFsE;CAAjE","file":"validation/rules/LoneAnonymousOperation.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\nimport { OPERATION_DEFINITION } from '../../language/kinds';\n\n\nexport function anonOperationNotAloneMessage(): string {\n return 'This anonymous operation must be the only defined operation.';\n}\n\n/**\n * Lone anonymous operation\n *\n * A GraphQL document is only valid if when it contains an anonymous operation\n * (the query short-hand) that it contains only that one operation definition.\n */\nexport function LoneAnonymousOperation(context: ValidationContext): any {\n let operationCount = 0;\n return {\n Document(node) {\n operationCount = node.definitions.filter(\n definition => definition.kind === OPERATION_DEFINITION\n ).length;\n },\n OperationDefinition(node) {\n if (!node.name && operationCount > 1) {\n context.reportError(\n new GraphQLError(anonOperationNotAloneMessage(), [ node ])\n );\n }\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/NoFragmentCycles.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.cycleErrorMessage = cycleErrorMessage; 7 | exports.NoFragmentCycles = NoFragmentCycles; 8 | 9 | var _error = require('../../error'); 10 | 11 | /** 12 | * Copyright (c) 2015, Facebook, Inc. 13 | * All rights reserved. 14 | * 15 | * This source code is licensed under the BSD-style license found in the 16 | * LICENSE file in the root directory of this source tree. An additional grant 17 | * of patent rights can be found in the PATENTS file in the same directory. 18 | */ 19 | 20 | function cycleErrorMessage(fragName, spreadNames) { 21 | var via = spreadNames.length ? ' via ' + spreadNames.join(', ') : ''; 22 | return 'Cannot spread fragment "' + fragName + '" within itself' + via + '.'; 23 | } 24 | 25 | function NoFragmentCycles(context) { 26 | // Tracks already visited fragments to maintain O(N) and to ensure that cycles 27 | // are not redundantly reported. 28 | var visitedFrags = Object.create(null); 29 | 30 | // Array of AST nodes used to produce meaningful errors 31 | var spreadPath = []; 32 | 33 | // Position in the spread path 34 | var spreadPathIndexByName = Object.create(null); 35 | 36 | return { 37 | OperationDefinition: function OperationDefinition() { 38 | return false; 39 | }, 40 | FragmentDefinition: function FragmentDefinition(node) { 41 | if (!visitedFrags[node.name.value]) { 42 | detectCycleRecursive(node); 43 | } 44 | return false; 45 | } 46 | }; 47 | 48 | // This does a straight-forward DFS to find cycles. 49 | // It does not terminate when a cycle was found but continues to explore 50 | // the graph to find all possible cycles. 51 | function detectCycleRecursive(fragment) { 52 | var fragmentName = fragment.name.value; 53 | visitedFrags[fragmentName] = true; 54 | 55 | var spreadNodes = context.getFragmentSpreads(fragment.selectionSet); 56 | if (spreadNodes.length === 0) { 57 | return; 58 | } 59 | 60 | spreadPathIndexByName[fragmentName] = spreadPath.length; 61 | 62 | for (var i = 0; i < spreadNodes.length; i++) { 63 | var spreadNode = spreadNodes[i]; 64 | var spreadName = spreadNode.name.value; 65 | var cycleIndex = spreadPathIndexByName[spreadName]; 66 | 67 | if (cycleIndex === undefined) { 68 | spreadPath.push(spreadNode); 69 | if (!visitedFrags[spreadName]) { 70 | var spreadFragment = context.getFragment(spreadName); 71 | if (spreadFragment) { 72 | detectCycleRecursive(spreadFragment); 73 | } 74 | } 75 | spreadPath.pop(); 76 | } else { 77 | var cyclePath = spreadPath.slice(cycleIndex); 78 | context.reportError(new _error.GraphQLError(cycleErrorMessage(spreadName, cyclePath.map(function (s) { 79 | return s.name.value; 80 | })), cyclePath.concat(spreadNode))); 81 | } 82 | } 83 | 84 | spreadPathIndexByName[fragmentName] = undefined; 85 | } 86 | } 87 | //# sourceMappingURL=NoFragmentCycles.js.map 88 | -------------------------------------------------------------------------------- /validation/rules/NoFragmentCycles.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import type { FragmentDefinition } from '../../language/ast'; 14 | 15 | 16 | export function cycleErrorMessage( 17 | fragName: string, 18 | spreadNames: Array 19 | ): string { 20 | const via = spreadNames.length ? ' via ' + spreadNames.join(', ') : ''; 21 | return `Cannot spread fragment "${fragName}" within itself${via}.`; 22 | } 23 | 24 | export function NoFragmentCycles(context: ValidationContext): any { 25 | // Tracks already visited fragments to maintain O(N) and to ensure that cycles 26 | // are not redundantly reported. 27 | const visitedFrags = Object.create(null); 28 | 29 | // Array of AST nodes used to produce meaningful errors 30 | const spreadPath = []; 31 | 32 | // Position in the spread path 33 | const spreadPathIndexByName = Object.create(null); 34 | 35 | return { 36 | OperationDefinition: () => false, 37 | FragmentDefinition(node) { 38 | if (!visitedFrags[node.name.value]) { 39 | detectCycleRecursive(node); 40 | } 41 | return false; 42 | }, 43 | }; 44 | 45 | // This does a straight-forward DFS to find cycles. 46 | // It does not terminate when a cycle was found but continues to explore 47 | // the graph to find all possible cycles. 48 | function detectCycleRecursive(fragment: FragmentDefinition) { 49 | const fragmentName = fragment.name.value; 50 | visitedFrags[fragmentName] = true; 51 | 52 | const spreadNodes = context.getFragmentSpreads(fragment.selectionSet); 53 | if (spreadNodes.length === 0) { 54 | return; 55 | } 56 | 57 | spreadPathIndexByName[fragmentName] = spreadPath.length; 58 | 59 | for (let i = 0; i < spreadNodes.length; i++) { 60 | const spreadNode = spreadNodes[i]; 61 | const spreadName = spreadNode.name.value; 62 | const cycleIndex = spreadPathIndexByName[spreadName]; 63 | 64 | if (cycleIndex === undefined) { 65 | spreadPath.push(spreadNode); 66 | if (!visitedFrags[spreadName]) { 67 | const spreadFragment = context.getFragment(spreadName); 68 | if (spreadFragment) { 69 | detectCycleRecursive(spreadFragment); 70 | } 71 | } 72 | spreadPath.pop(); 73 | } else { 74 | const cyclePath = spreadPath.slice(cycleIndex); 75 | context.reportError(new GraphQLError( 76 | cycleErrorMessage( 77 | spreadName, 78 | cyclePath.map(s => s.name.value) 79 | ), 80 | cyclePath.concat(spreadNode) 81 | )); 82 | } 83 | } 84 | 85 | spreadPathIndexByName[fragmentName] = undefined; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /validation/rules/NoUndefinedVariables.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.undefinedVarMessage = undefinedVarMessage; 7 | exports.NoUndefinedVariables = NoUndefinedVariables; 8 | 9 | var _error = require('../../error'); 10 | 11 | /** 12 | * Copyright (c) 2015, Facebook, Inc. 13 | * All rights reserved. 14 | * 15 | * This source code is licensed under the BSD-style license found in the 16 | * LICENSE file in the root directory of this source tree. An additional grant 17 | * of patent rights can be found in the PATENTS file in the same directory. 18 | */ 19 | 20 | function undefinedVarMessage(varName, opName) { 21 | return opName ? 'Variable "$' + varName + '" is not defined by operation "' + opName + '".' : 'Variable "$' + varName + '" is not defined.'; 22 | } 23 | 24 | /** 25 | * No undefined variables 26 | * 27 | * A GraphQL operation is only valid if all variables encountered, both directly 28 | * and via fragment spreads, are defined by that operation. 29 | */ 30 | function NoUndefinedVariables(context) { 31 | var variableNameDefined = Object.create(null); 32 | 33 | return { 34 | OperationDefinition: { 35 | enter: function enter() { 36 | variableNameDefined = Object.create(null); 37 | }, 38 | leave: function leave(operation) { 39 | var usages = context.getRecursiveVariableUsages(operation); 40 | 41 | usages.forEach(function (_ref) { 42 | var node = _ref.node; 43 | 44 | var varName = node.name.value; 45 | if (variableNameDefined[varName] !== true) { 46 | context.reportError(new _error.GraphQLError(undefinedVarMessage(varName, operation.name && operation.name.value), [node, operation])); 47 | } 48 | }); 49 | } 50 | }, 51 | VariableDefinition: function VariableDefinition(varDefAST) { 52 | variableNameDefined[varDefAST.variable.name.value] = true; 53 | } 54 | }; 55 | } 56 | //# sourceMappingURL=NoUndefinedVariables.js.map 57 | -------------------------------------------------------------------------------- /validation/rules/NoUndefinedVariables.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | 14 | 15 | export function undefinedVarMessage(varName: string, opName: ?string): string { 16 | return opName ? 17 | `Variable "$${varName}" is not defined by operation "${opName}".` : 18 | `Variable "$${varName}" is not defined.`; 19 | } 20 | 21 | /** 22 | * No undefined variables 23 | * 24 | * A GraphQL operation is only valid if all variables encountered, both directly 25 | * and via fragment spreads, are defined by that operation. 26 | */ 27 | export function NoUndefinedVariables(context: ValidationContext): any { 28 | let variableNameDefined = Object.create(null); 29 | 30 | return { 31 | OperationDefinition: { 32 | enter() { 33 | variableNameDefined = Object.create(null); 34 | }, 35 | leave(operation) { 36 | const usages = context.getRecursiveVariableUsages(operation); 37 | 38 | usages.forEach(({ node }) => { 39 | const varName = node.name.value; 40 | if (variableNameDefined[varName] !== true) { 41 | context.reportError(new GraphQLError( 42 | undefinedVarMessage( 43 | varName, 44 | operation.name && operation.name.value 45 | ), 46 | [ node, operation ] 47 | )); 48 | } 49 | }); 50 | } 51 | }, 52 | VariableDefinition(varDefAST) { 53 | variableNameDefined[varDefAST.variable.name.value] = true; 54 | } 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /validation/rules/NoUndefinedVariables.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/NoUndefinedVariables.js"],"names":[],"mappings":";;;;;QAcgB;QAYA;;AAfhB;;;;;;;;;;;AAGO,SAAS,mBAAT,CAA6B,OAA7B,EAA8C,MAA9C,EAAuE;AAC5E,SAAO,yBACS,8CAAyC,aADlD,mBAES,6BAFT,CADqE;CAAvE;;;;;;;;AAYA,SAAS,oBAAT,CAA8B,OAA9B,EAA+D;AACpE,MAAI,sBAAsB,OAAO,MAAP,CAAc,IAAd,CAAtB,CADgE;;AAGpE,SAAO;AACL,yBAAqB;AACnB,8BAAQ;AACN,8BAAsB,OAAO,MAAP,CAAc,IAAd,CAAtB,CADM;OADW;AAInB,4BAAM,WAAW;AACf,YAAM,SAAS,QAAQ,0BAAR,CAAmC,SAAnC,CAAT,CADS;;AAGf,eAAO,OAAP,CAAe,gBAAc;cAAX,iBAAW;;AAC3B,cAAM,UAAU,KAAK,IAAL,CAAU,KAAV,CADW;AAE3B,cAAI,oBAAoB,OAApB,MAAiC,IAAjC,EAAuC;AACzC,oBAAQ,WAAR,CAAoB,wBAClB,oBACE,OADF,EAEE,UAAU,IAAV,IAAkB,UAAU,IAAV,CAAe,KAAf,CAHF,EAKlB,CAAE,IAAF,EAAQ,SAAR,CALkB,CAApB,EADyC;WAA3C;SAFa,CAAf,CAHe;OAJE;KAArB;AAqBA,oDAAmB,WAAW;AAC5B,0BAAoB,UAAU,QAAV,CAAmB,IAAnB,CAAwB,KAAxB,CAApB,GAAqD,IAArD,CAD4B;KAtBzB;GAAP,CAHoE;CAA/D","file":"validation/rules/NoUndefinedVariables.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\n\n\nexport function undefinedVarMessage(varName: string, opName: ?string): string {\n return opName ?\n `Variable \"$${varName}\" is not defined by operation \"${opName}\".` :\n `Variable \"$${varName}\" is not defined.`;\n}\n\n/**\n * No undefined variables\n *\n * A GraphQL operation is only valid if all variables encountered, both directly\n * and via fragment spreads, are defined by that operation.\n */\nexport function NoUndefinedVariables(context: ValidationContext): any {\n let variableNameDefined = Object.create(null);\n\n return {\n OperationDefinition: {\n enter() {\n variableNameDefined = Object.create(null);\n },\n leave(operation) {\n const usages = context.getRecursiveVariableUsages(operation);\n\n usages.forEach(({ node }) => {\n const varName = node.name.value;\n if (variableNameDefined[varName] !== true) {\n context.reportError(new GraphQLError(\n undefinedVarMessage(\n varName,\n operation.name && operation.name.value\n ),\n [ node, operation ]\n ));\n }\n });\n }\n },\n VariableDefinition(varDefAST) {\n variableNameDefined[varDefAST.variable.name.value] = true;\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/NoUnusedFragments.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.unusedFragMessage = unusedFragMessage; 7 | exports.NoUnusedFragments = NoUnusedFragments; 8 | 9 | var _error = require('../../error'); 10 | 11 | /** 12 | * Copyright (c) 2015, Facebook, Inc. 13 | * All rights reserved. 14 | * 15 | * This source code is licensed under the BSD-style license found in the 16 | * LICENSE file in the root directory of this source tree. An additional grant 17 | * of patent rights can be found in the PATENTS file in the same directory. 18 | */ 19 | 20 | function unusedFragMessage(fragName) { 21 | return 'Fragment "' + fragName + '" is never used.'; 22 | } 23 | 24 | /** 25 | * No unused fragments 26 | * 27 | * A GraphQL document is only valid if all fragment definitions are spread 28 | * within operations, or spread within other fragments spread within operations. 29 | */ 30 | function NoUnusedFragments(context) { 31 | var operationDefs = []; 32 | var fragmentDefs = []; 33 | 34 | return { 35 | OperationDefinition: function OperationDefinition(node) { 36 | operationDefs.push(node); 37 | return false; 38 | }, 39 | FragmentDefinition: function FragmentDefinition(node) { 40 | fragmentDefs.push(node); 41 | return false; 42 | }, 43 | 44 | Document: { 45 | leave: function leave() { 46 | var fragmentNameUsed = Object.create(null); 47 | operationDefs.forEach(function (operation) { 48 | context.getRecursivelyReferencedFragments(operation).forEach(function (fragment) { 49 | fragmentNameUsed[fragment.name.value] = true; 50 | }); 51 | }); 52 | 53 | fragmentDefs.forEach(function (fragmentDef) { 54 | var fragName = fragmentDef.name.value; 55 | if (fragmentNameUsed[fragName] !== true) { 56 | context.reportError(new _error.GraphQLError(unusedFragMessage(fragName), [fragmentDef])); 57 | } 58 | }); 59 | } 60 | } 61 | }; 62 | } 63 | //# sourceMappingURL=NoUnusedFragments.js.map 64 | -------------------------------------------------------------------------------- /validation/rules/NoUnusedFragments.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | 14 | 15 | export function unusedFragMessage(fragName: string): string { 16 | return `Fragment "${fragName}" is never used.`; 17 | } 18 | 19 | /** 20 | * No unused fragments 21 | * 22 | * A GraphQL document is only valid if all fragment definitions are spread 23 | * within operations, or spread within other fragments spread within operations. 24 | */ 25 | export function NoUnusedFragments(context: ValidationContext): any { 26 | const operationDefs = []; 27 | const fragmentDefs = []; 28 | 29 | return { 30 | OperationDefinition(node) { 31 | operationDefs.push(node); 32 | return false; 33 | }, 34 | FragmentDefinition(node) { 35 | fragmentDefs.push(node); 36 | return false; 37 | }, 38 | Document: { 39 | leave() { 40 | const fragmentNameUsed = Object.create(null); 41 | operationDefs.forEach(operation => { 42 | context.getRecursivelyReferencedFragments(operation).forEach( 43 | fragment => { fragmentNameUsed[fragment.name.value] = true; } 44 | ); 45 | }); 46 | 47 | fragmentDefs.forEach(fragmentDef => { 48 | const fragName = fragmentDef.name.value; 49 | if (fragmentNameUsed[fragName] !== true) { 50 | context.reportError(new GraphQLError( 51 | unusedFragMessage(fragName), 52 | [ fragmentDef ] 53 | )); 54 | } 55 | }); 56 | } 57 | } 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /validation/rules/NoUnusedFragments.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/NoUnusedFragments.js"],"names":[],"mappings":";;;;;QAcgB;QAUA;;AAbhB;;;;;;;;;;;AAGO,SAAS,iBAAT,CAA2B,QAA3B,EAAqD;AAC1D,wBAAoB,6BAApB,CAD0D;CAArD;;;;;;;;AAUA,SAAS,iBAAT,CAA2B,OAA3B,EAA4D;AACjE,MAAM,gBAAgB,EAAhB,CAD2D;AAEjE,MAAM,eAAe,EAAf,CAF2D;;AAIjE,SAAO;AACL,sDAAoB,MAAM;AACxB,oBAAc,IAAd,CAAmB,IAAnB,EADwB;AAExB,aAAO,KAAP,CAFwB;KADrB;AAKL,oDAAmB,MAAM;AACvB,mBAAa,IAAb,CAAkB,IAAlB,EADuB;AAEvB,aAAO,KAAP,CAFuB;KALpB;;AASL,cAAU;AACR,8BAAQ;AACN,YAAM,mBAAmB,OAAO,MAAP,CAAc,IAAd,CAAnB,CADA;AAEN,sBAAc,OAAd,CAAsB,qBAAa;AACjC,kBAAQ,iCAAR,CAA0C,SAA1C,EAAqD,OAArD,CACE,oBAAY;AAAE,6BAAiB,SAAS,IAAT,CAAc,KAAd,CAAjB,GAAwC,IAAxC,CAAF;WAAZ,CADF,CADiC;SAAb,CAAtB,CAFM;;AAQN,qBAAa,OAAb,CAAqB,uBAAe;AAClC,cAAM,WAAW,YAAY,IAAZ,CAAiB,KAAjB,CADiB;AAElC,cAAI,iBAAiB,QAAjB,MAA+B,IAA/B,EAAqC;AACvC,oBAAQ,WAAR,CAAoB,wBAClB,kBAAkB,QAAlB,CADkB,EAElB,CAAE,WAAF,CAFkB,CAApB,EADuC;WAAzC;SAFmB,CAArB,CARM;OADA;KAAV;GATF,CAJiE;CAA5D","file":"validation/rules/NoUnusedFragments.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\n\n\nexport function unusedFragMessage(fragName: string): string {\n return `Fragment \"${fragName}\" is never used.`;\n}\n\n/**\n * No unused fragments\n *\n * A GraphQL document is only valid if all fragment definitions are spread\n * within operations, or spread within other fragments spread within operations.\n */\nexport function NoUnusedFragments(context: ValidationContext): any {\n const operationDefs = [];\n const fragmentDefs = [];\n\n return {\n OperationDefinition(node) {\n operationDefs.push(node);\n return false;\n },\n FragmentDefinition(node) {\n fragmentDefs.push(node);\n return false;\n },\n Document: {\n leave() {\n const fragmentNameUsed = Object.create(null);\n operationDefs.forEach(operation => {\n context.getRecursivelyReferencedFragments(operation).forEach(\n fragment => { fragmentNameUsed[fragment.name.value] = true; }\n );\n });\n\n fragmentDefs.forEach(fragmentDef => {\n const fragName = fragmentDef.name.value;\n if (fragmentNameUsed[fragName] !== true) {\n context.reportError(new GraphQLError(\n unusedFragMessage(fragName),\n [ fragmentDef ]\n ));\n }\n });\n }\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/NoUnusedVariables.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.unusedVariableMessage = unusedVariableMessage; 7 | exports.NoUnusedVariables = NoUnusedVariables; 8 | 9 | var _error = require('../../error'); 10 | 11 | /** 12 | * Copyright (c) 2015, Facebook, Inc. 13 | * All rights reserved. 14 | * 15 | * This source code is licensed under the BSD-style license found in the 16 | * LICENSE file in the root directory of this source tree. An additional grant 17 | * of patent rights can be found in the PATENTS file in the same directory. 18 | */ 19 | 20 | function unusedVariableMessage(varName, opName) { 21 | return opName ? 'Variable "$' + varName + '" is never used in operation "' + opName + '".' : 'Variable "$' + varName + '" is never used.'; 22 | } 23 | 24 | /** 25 | * No unused variables 26 | * 27 | * A GraphQL operation is only valid if all variables defined by an operation 28 | * are used, either directly or within a spread fragment. 29 | */ 30 | function NoUnusedVariables(context) { 31 | var variableDefs = []; 32 | 33 | return { 34 | OperationDefinition: { 35 | enter: function enter() { 36 | variableDefs = []; 37 | }, 38 | leave: function leave(operation) { 39 | var variableNameUsed = Object.create(null); 40 | var usages = context.getRecursiveVariableUsages(operation); 41 | var opName = operation.name ? operation.name.value : null; 42 | 43 | usages.forEach(function (_ref) { 44 | var node = _ref.node; 45 | 46 | variableNameUsed[node.name.value] = true; 47 | }); 48 | 49 | variableDefs.forEach(function (variableDef) { 50 | var variableName = variableDef.variable.name.value; 51 | if (variableNameUsed[variableName] !== true) { 52 | context.reportError(new _error.GraphQLError(unusedVariableMessage(variableName, opName), [variableDef])); 53 | } 54 | }); 55 | } 56 | }, 57 | VariableDefinition: function VariableDefinition(def) { 58 | variableDefs.push(def); 59 | } 60 | }; 61 | } 62 | //# sourceMappingURL=NoUnusedVariables.js.map 63 | -------------------------------------------------------------------------------- /validation/rules/NoUnusedVariables.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | 14 | 15 | export function unusedVariableMessage( 16 | varName: string, 17 | opName: ?string 18 | ): string { 19 | return opName ? 20 | `Variable "$${varName}" is never used in operation "${opName}".` : 21 | `Variable "$${varName}" is never used.`; 22 | } 23 | 24 | /** 25 | * No unused variables 26 | * 27 | * A GraphQL operation is only valid if all variables defined by an operation 28 | * are used, either directly or within a spread fragment. 29 | */ 30 | export function NoUnusedVariables(context: ValidationContext): any { 31 | let variableDefs = []; 32 | 33 | return { 34 | OperationDefinition: { 35 | enter() { 36 | variableDefs = []; 37 | }, 38 | leave(operation) { 39 | const variableNameUsed = Object.create(null); 40 | const usages = context.getRecursiveVariableUsages(operation); 41 | const opName = operation.name ? operation.name.value : null; 42 | 43 | usages.forEach(({ node }) => { 44 | variableNameUsed[node.name.value] = true; 45 | }); 46 | 47 | variableDefs.forEach(variableDef => { 48 | const variableName = variableDef.variable.name.value; 49 | if (variableNameUsed[variableName] !== true) { 50 | context.reportError(new GraphQLError( 51 | unusedVariableMessage(variableName, opName), 52 | [ variableDef ] 53 | )); 54 | } 55 | }); 56 | } 57 | }, 58 | VariableDefinition(def) { 59 | variableDefs.push(def); 60 | } 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /validation/rules/NoUnusedVariables.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/NoUnusedVariables.js"],"names":[],"mappings":";;;;;QAcgB;QAeA;;AAlBhB;;;;;;;;;;;AAGO,SAAS,qBAAT,CACL,OADK,EAEL,MAFK,EAGG;AACR,SAAO,yBACS,6CAAwC,aADjD,mBAES,4BAFT,CADC;CAHH;;;;;;;;AAeA,SAAS,iBAAT,CAA2B,OAA3B,EAA4D;AACjE,MAAI,eAAe,EAAf,CAD6D;;AAGjE,SAAO;AACL,yBAAqB;AACnB,8BAAQ;AACN,uBAAe,EAAf,CADM;OADW;AAInB,4BAAM,WAAW;AACf,YAAM,mBAAmB,OAAO,MAAP,CAAc,IAAd,CAAnB,CADS;AAEf,YAAM,SAAS,QAAQ,0BAAR,CAAmC,SAAnC,CAAT,CAFS;AAGf,YAAM,SAAS,UAAU,IAAV,GAAiB,UAAU,IAAV,CAAe,KAAf,GAAuB,IAAxC,CAHA;;AAKf,eAAO,OAAP,CAAe,gBAAc;cAAX,iBAAW;;AAC3B,2BAAiB,KAAK,IAAL,CAAU,KAAV,CAAjB,GAAoC,IAApC,CAD2B;SAAd,CAAf,CALe;;AASf,qBAAa,OAAb,CAAqB,uBAAe;AAClC,cAAM,eAAe,YAAY,QAAZ,CAAqB,IAArB,CAA0B,KAA1B,CADa;AAElC,cAAI,iBAAiB,YAAjB,MAAmC,IAAnC,EAAyC;AAC3C,oBAAQ,WAAR,CAAoB,wBAClB,sBAAsB,YAAtB,EAAoC,MAApC,CADkB,EAElB,CAAE,WAAF,CAFkB,CAApB,EAD2C;WAA7C;SAFmB,CAArB,CATe;OAJE;KAArB;AAwBA,oDAAmB,KAAK;AACtB,mBAAa,IAAb,CAAkB,GAAlB,EADsB;KAzBnB;GAAP,CAHiE;CAA5D","file":"validation/rules/NoUnusedVariables.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\n\n\nexport function unusedVariableMessage(\n varName: string,\n opName: ?string\n): string {\n return opName ?\n `Variable \"$${varName}\" is never used in operation \"${opName}\".` :\n `Variable \"$${varName}\" is never used.`;\n}\n\n/**\n * No unused variables\n *\n * A GraphQL operation is only valid if all variables defined by an operation\n * are used, either directly or within a spread fragment.\n */\nexport function NoUnusedVariables(context: ValidationContext): any {\n let variableDefs = [];\n\n return {\n OperationDefinition: {\n enter() {\n variableDefs = [];\n },\n leave(operation) {\n const variableNameUsed = Object.create(null);\n const usages = context.getRecursiveVariableUsages(operation);\n const opName = operation.name ? operation.name.value : null;\n\n usages.forEach(({ node }) => {\n variableNameUsed[node.name.value] = true;\n });\n\n variableDefs.forEach(variableDef => {\n const variableName = variableDef.variable.name.value;\n if (variableNameUsed[variableName] !== true) {\n context.reportError(new GraphQLError(\n unusedVariableMessage(variableName, opName),\n [ variableDef ]\n ));\n }\n });\n }\n },\n VariableDefinition(def) {\n variableDefs.push(def);\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/PossibleFragmentSpreads.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.typeIncompatibleSpreadMessage = typeIncompatibleSpreadMessage; 7 | exports.typeIncompatibleAnonSpreadMessage = typeIncompatibleAnonSpreadMessage; 8 | exports.PossibleFragmentSpreads = PossibleFragmentSpreads; 9 | 10 | var _error = require('../../error'); 11 | 12 | var _typeComparators = require('../../utilities/typeComparators'); 13 | 14 | var _typeFromAST = require('../../utilities/typeFromAST'); 15 | 16 | /** 17 | * Copyright (c) 2015, Facebook, Inc. 18 | * All rights reserved. 19 | * 20 | * This source code is licensed under the BSD-style license found in the 21 | * LICENSE file in the root directory of this source tree. An additional grant 22 | * of patent rights can be found in the PATENTS file in the same directory. 23 | */ 24 | 25 | function typeIncompatibleSpreadMessage(fragName, parentType, fragType) { 26 | return 'Fragment "' + fragName + '" cannot be spread here as objects of ' + ('type "' + String(parentType) + '" can never be of type "' + String(fragType) + '".'); 27 | } 28 | 29 | function typeIncompatibleAnonSpreadMessage(parentType, fragType) { 30 | return 'Fragment cannot be spread here as objects of ' + ('type "' + String(parentType) + '" can never be of type "' + String(fragType) + '".'); 31 | } 32 | 33 | /** 34 | * Possible fragment spread 35 | * 36 | * A fragment spread is only valid if the type condition could ever possibly 37 | * be true: if there is a non-empty intersection of the possible parent types, 38 | * and possible types which pass the type condition. 39 | */ 40 | function PossibleFragmentSpreads(context) { 41 | return { 42 | InlineFragment: function InlineFragment(node) { 43 | var fragType = context.getType(); 44 | var parentType = context.getParentType(); 45 | if (fragType && parentType && !(0, _typeComparators.doTypesOverlap)(context.getSchema(), fragType, parentType)) { 46 | context.reportError(new _error.GraphQLError(typeIncompatibleAnonSpreadMessage(parentType, fragType), [node])); 47 | } 48 | }, 49 | FragmentSpread: function FragmentSpread(node) { 50 | var fragName = node.name.value; 51 | var fragType = getFragmentType(context, fragName); 52 | var parentType = context.getParentType(); 53 | if (fragType && parentType && !(0, _typeComparators.doTypesOverlap)(context.getSchema(), fragType, parentType)) { 54 | context.reportError(new _error.GraphQLError(typeIncompatibleSpreadMessage(fragName, parentType, fragType), [node])); 55 | } 56 | } 57 | }; 58 | } 59 | 60 | function getFragmentType(context, name) { 61 | var frag = context.getFragment(name); 62 | return frag && (0, _typeFromAST.typeFromAST)(context.getSchema(), frag.typeCondition); 63 | } 64 | //# sourceMappingURL=PossibleFragmentSpreads.js.map 65 | -------------------------------------------------------------------------------- /validation/rules/PossibleFragmentSpreads.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import { doTypesOverlap } from '../../utilities/typeComparators'; 14 | import { typeFromAST } from '../../utilities/typeFromAST'; 15 | import type { GraphQLType } from '../../type/definition'; 16 | 17 | 18 | export function typeIncompatibleSpreadMessage( 19 | fragName: string, 20 | parentType: GraphQLType, 21 | fragType: GraphQLType 22 | ): string { 23 | return `Fragment "${fragName}" cannot be spread here as objects of ` + 24 | `type "${String(parentType)}" can never be of type "${String(fragType)}".`; 25 | } 26 | 27 | export function typeIncompatibleAnonSpreadMessage( 28 | parentType: GraphQLType, 29 | fragType: GraphQLType 30 | ): string { 31 | return 'Fragment cannot be spread here as objects of ' + 32 | `type "${String(parentType)}" can never be of type "${String(fragType)}".`; 33 | } 34 | 35 | /** 36 | * Possible fragment spread 37 | * 38 | * A fragment spread is only valid if the type condition could ever possibly 39 | * be true: if there is a non-empty intersection of the possible parent types, 40 | * and possible types which pass the type condition. 41 | */ 42 | export function PossibleFragmentSpreads(context: ValidationContext): any { 43 | return { 44 | InlineFragment(node) { 45 | const fragType = context.getType(); 46 | const parentType = context.getParentType(); 47 | if (fragType && 48 | parentType && 49 | !doTypesOverlap(context.getSchema(), fragType, parentType)) { 50 | context.reportError(new GraphQLError( 51 | typeIncompatibleAnonSpreadMessage(parentType, fragType), 52 | [ node ] 53 | )); 54 | } 55 | }, 56 | FragmentSpread(node) { 57 | const fragName = node.name.value; 58 | const fragType = getFragmentType(context, fragName); 59 | const parentType = context.getParentType(); 60 | if (fragType && 61 | parentType && 62 | !doTypesOverlap(context.getSchema(), fragType, parentType)) { 63 | context.reportError(new GraphQLError( 64 | typeIncompatibleSpreadMessage(fragName, parentType, fragType), 65 | [ node ] 66 | )); 67 | } 68 | } 69 | }; 70 | } 71 | 72 | function getFragmentType(context, name) { 73 | const frag = context.getFragment(name); 74 | return frag && typeFromAST(context.getSchema(), frag.typeCondition); 75 | } 76 | -------------------------------------------------------------------------------- /validation/rules/ScalarLeafs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.noSubselectionAllowedMessage = noSubselectionAllowedMessage; 7 | exports.requiredSubselectionMessage = requiredSubselectionMessage; 8 | exports.ScalarLeafs = ScalarLeafs; 9 | 10 | var _error = require('../../error'); 11 | 12 | var _definition = require('../../type/definition'); 13 | 14 | function noSubselectionAllowedMessage(fieldName, type) { 15 | return 'Field "' + fieldName + '" must not have a selection since ' + ('type "' + String(type) + '" has no subfields.'); 16 | } 17 | /** 18 | * Copyright (c) 2015, Facebook, Inc. 19 | * All rights reserved. 20 | * 21 | * This source code is licensed under the BSD-style license found in the 22 | * LICENSE file in the root directory of this source tree. An additional grant 23 | * of patent rights can be found in the PATENTS file in the same directory. 24 | */ 25 | 26 | function requiredSubselectionMessage(fieldName, type) { 27 | return 'Field "' + fieldName + '" of type "' + String(type) + '" must have a ' + ('selection of subfields. Did you mean "' + fieldName + ' { ... }"?'); 28 | } 29 | 30 | /** 31 | * Scalar leafs 32 | * 33 | * A GraphQL document is valid only if all leaf fields (fields without 34 | * sub selections) are of scalar or enum types. 35 | */ 36 | function ScalarLeafs(context) { 37 | return { 38 | Field: function Field(node) { 39 | var type = context.getType(); 40 | if (type) { 41 | if ((0, _definition.isLeafType)(type)) { 42 | if (node.selectionSet) { 43 | context.reportError(new _error.GraphQLError(noSubselectionAllowedMessage(node.name.value, type), [node.selectionSet])); 44 | } 45 | } else if (!node.selectionSet) { 46 | context.reportError(new _error.GraphQLError(requiredSubselectionMessage(node.name.value, type), [node])); 47 | } 48 | } 49 | } 50 | }; 51 | } 52 | //# sourceMappingURL=ScalarLeafs.js.map 53 | -------------------------------------------------------------------------------- /validation/rules/ScalarLeafs.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import type { Field } from '../../language/ast'; 14 | import { isLeafType } from '../../type/definition'; 15 | import type { GraphQLType } from '../../type/definition'; 16 | 17 | 18 | export function noSubselectionAllowedMessage( 19 | fieldName: string, 20 | type: GraphQLType 21 | ): string { 22 | return `Field "${fieldName}" must not have a selection since ` + 23 | `type "${String(type)}" has no subfields.`; 24 | } 25 | 26 | export function requiredSubselectionMessage( 27 | fieldName: string, 28 | type: GraphQLType 29 | ): string { 30 | return `Field "${fieldName}" of type "${String(type)}" must have a ` + 31 | `selection of subfields. Did you mean "${fieldName} { ... }"?`; 32 | } 33 | 34 | /** 35 | * Scalar leafs 36 | * 37 | * A GraphQL document is valid only if all leaf fields (fields without 38 | * sub selections) are of scalar or enum types. 39 | */ 40 | export function ScalarLeafs(context: ValidationContext): any { 41 | return { 42 | Field(node: Field) { 43 | const type = context.getType(); 44 | if (type) { 45 | if (isLeafType(type)) { 46 | if (node.selectionSet) { 47 | context.reportError(new GraphQLError( 48 | noSubselectionAllowedMessage(node.name.value, type), 49 | [ node.selectionSet ] 50 | )); 51 | } 52 | } else if (!node.selectionSet) { 53 | context.reportError(new GraphQLError( 54 | requiredSubselectionMessage(node.name.value, type), 55 | [ node ] 56 | )); 57 | } 58 | } 59 | } 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /validation/rules/ScalarLeafs.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/ScalarLeafs.js"],"names":[],"mappings":";;;;;QAiBgB;QAQA;QAcA;;AA5BhB;;AAEA;;AAIO,SAAS,4BAAT,CACL,SADK,EAEL,IAFK,EAGG;AACR,SAAO,YAAU,gDAAV,eACI,OAAO,IAAP,0BADJ,CADC;CAHH;;;;;;;;;;AAQA,SAAS,2BAAT,CACL,SADK,EAEL,IAFK,EAGG;AACR,SAAO,YAAU,4BAAuB,OAAO,IAAP,oBAAjC,+CACoC,yBADpC,CADC;CAHH;;;;;;;;AAcA,SAAS,WAAT,CAAqB,OAArB,EAAsD;AAC3D,SAAO;AACL,0BAAM,MAAa;AACjB,UAAM,OAAO,QAAQ,OAAR,EAAP,CADW;AAEjB,UAAI,IAAJ,EAAU;AACR,YAAI,4BAAW,IAAX,CAAJ,EAAsB;AACpB,cAAI,KAAK,YAAL,EAAmB;AACrB,oBAAQ,WAAR,CAAoB,wBAClB,6BAA6B,KAAK,IAAL,CAAU,KAAV,EAAiB,IAA9C,CADkB,EAElB,CAAE,KAAK,YAAL,CAFgB,CAApB,EADqB;WAAvB;SADF,MAOO,IAAI,CAAC,KAAK,YAAL,EAAmB;AAC7B,kBAAQ,WAAR,CAAoB,wBAClB,4BAA4B,KAAK,IAAL,CAAU,KAAV,EAAiB,IAA7C,CADkB,EAElB,CAAE,IAAF,CAFkB,CAApB,EAD6B;SAAxB;OART;KAHG;GAAP,CAD2D;CAAtD","file":"validation/rules/ScalarLeafs.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\nimport type { Field } from '../../language/ast';\nimport { isLeafType } from '../../type/definition';\nimport type { GraphQLType } from '../../type/definition';\n\n\nexport function noSubselectionAllowedMessage(\n fieldName: string,\n type: GraphQLType\n): string {\n return `Field \"${fieldName}\" must not have a selection since ` +\n `type \"${String(type)}\" has no subfields.`;\n}\n\nexport function requiredSubselectionMessage(\n fieldName: string,\n type: GraphQLType\n): string {\n return `Field \"${fieldName}\" of type \"${String(type)}\" must have a ` +\n `selection of subfields. Did you mean \"${fieldName} { ... }\"?`;\n}\n\n/**\n * Scalar leafs\n *\n * A GraphQL document is valid only if all leaf fields (fields without\n * sub selections) are of scalar or enum types.\n */\nexport function ScalarLeafs(context: ValidationContext): any {\n return {\n Field(node: Field) {\n const type = context.getType();\n if (type) {\n if (isLeafType(type)) {\n if (node.selectionSet) {\n context.reportError(new GraphQLError(\n noSubselectionAllowedMessage(node.name.value, type),\n [ node.selectionSet ]\n ));\n }\n } else if (!node.selectionSet) {\n context.reportError(new GraphQLError(\n requiredSubselectionMessage(node.name.value, type),\n [ node ]\n ));\n }\n }\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/UniqueArgumentNames.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.duplicateArgMessage = duplicateArgMessage; 7 | exports.UniqueArgumentNames = UniqueArgumentNames; 8 | 9 | var _error = require('../../error'); 10 | 11 | /** 12 | * Copyright (c) 2015, Facebook, Inc. 13 | * All rights reserved. 14 | * 15 | * This source code is licensed under the BSD-style license found in the 16 | * LICENSE file in the root directory of this source tree. An additional grant 17 | * of patent rights can be found in the PATENTS file in the same directory. 18 | */ 19 | 20 | function duplicateArgMessage(argName) { 21 | return 'There can be only one argument named "' + argName + '".'; 22 | } 23 | 24 | /** 25 | * Unique argument names 26 | * 27 | * A GraphQL field or directive is only valid if all supplied arguments are 28 | * uniquely named. 29 | */ 30 | function UniqueArgumentNames(context) { 31 | var knownArgNames = Object.create(null); 32 | return { 33 | Field: function Field() { 34 | knownArgNames = Object.create(null); 35 | }, 36 | Directive: function Directive() { 37 | knownArgNames = Object.create(null); 38 | }, 39 | Argument: function Argument(node) { 40 | var argName = node.name.value; 41 | if (knownArgNames[argName]) { 42 | context.reportError(new _error.GraphQLError(duplicateArgMessage(argName), [knownArgNames[argName], node.name])); 43 | } else { 44 | knownArgNames[argName] = node.name; 45 | } 46 | return false; 47 | } 48 | }; 49 | } 50 | //# sourceMappingURL=UniqueArgumentNames.js.map 51 | -------------------------------------------------------------------------------- /validation/rules/UniqueArgumentNames.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | 14 | 15 | export function duplicateArgMessage(argName: string): string { 16 | return `There can be only one argument named "${argName}".`; 17 | } 18 | 19 | /** 20 | * Unique argument names 21 | * 22 | * A GraphQL field or directive is only valid if all supplied arguments are 23 | * uniquely named. 24 | */ 25 | export function UniqueArgumentNames(context: ValidationContext): any { 26 | let knownArgNames = Object.create(null); 27 | return { 28 | Field() { 29 | knownArgNames = Object.create(null); 30 | }, 31 | Directive() { 32 | knownArgNames = Object.create(null); 33 | }, 34 | Argument(node) { 35 | const argName = node.name.value; 36 | if (knownArgNames[argName]) { 37 | context.reportError(new GraphQLError( 38 | duplicateArgMessage(argName), 39 | [ knownArgNames[argName], node.name ] 40 | )); 41 | } else { 42 | knownArgNames[argName] = node.name; 43 | } 44 | return false; 45 | } 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /validation/rules/UniqueArgumentNames.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/UniqueArgumentNames.js"],"names":[],"mappings":";;;;;QAcgB;QAUA;;AAbhB;;;;;;;;;;;AAGO,SAAS,mBAAT,CAA6B,OAA7B,EAAsD;AAC3D,oDAAgD,cAAhD,CAD2D;CAAtD;;;;;;;;AAUA,SAAS,mBAAT,CAA6B,OAA7B,EAA8D;AACnE,MAAI,gBAAgB,OAAO,MAAP,CAAc,IAAd,CAAhB,CAD+D;AAEnE,SAAO;AACL,4BAAQ;AACN,sBAAgB,OAAO,MAAP,CAAc,IAAd,CAAhB,CADM;KADH;AAIL,oCAAY;AACV,sBAAgB,OAAO,MAAP,CAAc,IAAd,CAAhB,CADU;KAJP;AAOL,gCAAS,MAAM;AACb,UAAM,UAAU,KAAK,IAAL,CAAU,KAAV,CADH;AAEb,UAAI,cAAc,OAAd,CAAJ,EAA4B;AAC1B,gBAAQ,WAAR,CAAoB,wBAClB,oBAAoB,OAApB,CADkB,EAElB,CAAE,cAAc,OAAd,CAAF,EAA0B,KAAK,IAAL,CAFR,CAApB,EAD0B;OAA5B,MAKO;AACL,sBAAc,OAAd,IAAyB,KAAK,IAAL,CADpB;OALP;AAQA,aAAO,KAAP,CAVa;KAPV;GAAP,CAFmE;CAA9D","file":"validation/rules/UniqueArgumentNames.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\n\n\nexport function duplicateArgMessage(argName: string): string {\n return `There can be only one argument named \"${argName}\".`;\n}\n\n/**\n * Unique argument names\n *\n * A GraphQL field or directive is only valid if all supplied arguments are\n * uniquely named.\n */\nexport function UniqueArgumentNames(context: ValidationContext): any {\n let knownArgNames = Object.create(null);\n return {\n Field() {\n knownArgNames = Object.create(null);\n },\n Directive() {\n knownArgNames = Object.create(null);\n },\n Argument(node) {\n const argName = node.name.value;\n if (knownArgNames[argName]) {\n context.reportError(new GraphQLError(\n duplicateArgMessage(argName),\n [ knownArgNames[argName], node.name ]\n ));\n } else {\n knownArgNames[argName] = node.name;\n }\n return false;\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/UniqueFragmentNames.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.duplicateFragmentNameMessage = duplicateFragmentNameMessage; 7 | exports.UniqueFragmentNames = UniqueFragmentNames; 8 | 9 | var _error = require('../../error'); 10 | 11 | /** 12 | * Copyright (c) 2015, Facebook, Inc. 13 | * All rights reserved. 14 | * 15 | * This source code is licensed under the BSD-style license found in the 16 | * LICENSE file in the root directory of this source tree. An additional grant 17 | * of patent rights can be found in the PATENTS file in the same directory. 18 | */ 19 | 20 | function duplicateFragmentNameMessage(fragName) { 21 | return 'There can only be one fragment named "' + fragName + '".'; 22 | } 23 | 24 | /** 25 | * Unique fragment names 26 | * 27 | * A GraphQL document is only valid if all defined fragments have unique names. 28 | */ 29 | function UniqueFragmentNames(context) { 30 | var knownFragmentNames = Object.create(null); 31 | return { 32 | OperationDefinition: function OperationDefinition() { 33 | return false; 34 | }, 35 | FragmentDefinition: function FragmentDefinition(node) { 36 | var fragmentName = node.name.value; 37 | if (knownFragmentNames[fragmentName]) { 38 | context.reportError(new _error.GraphQLError(duplicateFragmentNameMessage(fragmentName), [knownFragmentNames[fragmentName], node.name])); 39 | } else { 40 | knownFragmentNames[fragmentName] = node.name; 41 | } 42 | return false; 43 | } 44 | }; 45 | } 46 | //# sourceMappingURL=UniqueFragmentNames.js.map 47 | -------------------------------------------------------------------------------- /validation/rules/UniqueFragmentNames.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | 14 | 15 | export function duplicateFragmentNameMessage(fragName: string): string { 16 | return `There can only be one fragment named "${fragName}".`; 17 | } 18 | 19 | /** 20 | * Unique fragment names 21 | * 22 | * A GraphQL document is only valid if all defined fragments have unique names. 23 | */ 24 | export function UniqueFragmentNames(context: ValidationContext): any { 25 | const knownFragmentNames = Object.create(null); 26 | return { 27 | OperationDefinition: () => false, 28 | FragmentDefinition(node) { 29 | const fragmentName = node.name.value; 30 | if (knownFragmentNames[fragmentName]) { 31 | context.reportError(new GraphQLError( 32 | duplicateFragmentNameMessage(fragmentName), 33 | [ knownFragmentNames[fragmentName], node.name ] 34 | )); 35 | } else { 36 | knownFragmentNames[fragmentName] = node.name; 37 | } 38 | return false; 39 | } 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /validation/rules/UniqueFragmentNames.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/UniqueFragmentNames.js"],"names":[],"mappings":";;;;;QAcgB;QASA;;AAZhB;;;;;;;;;;;AAGO,SAAS,4BAAT,CAAsC,QAAtC,EAAgE;AACrE,oDAAgD,eAAhD,CADqE;CAAhE;;;;;;;AASA,SAAS,mBAAT,CAA6B,OAA7B,EAA8D;AACnE,MAAM,qBAAqB,OAAO,MAAP,CAAc,IAAd,CAArB,CAD6D;AAEnE,SAAO;AACL,yBAAqB;aAAM;KAAN;AACrB,oDAAmB,MAAM;AACvB,UAAM,eAAe,KAAK,IAAL,CAAU,KAAV,CADE;AAEvB,UAAI,mBAAmB,YAAnB,CAAJ,EAAsC;AACpC,gBAAQ,WAAR,CAAoB,wBAClB,6BAA6B,YAA7B,CADkB,EAElB,CAAE,mBAAmB,YAAnB,CAAF,EAAoC,KAAK,IAAL,CAFlB,CAApB,EADoC;OAAtC,MAKO;AACL,2BAAmB,YAAnB,IAAmC,KAAK,IAAL,CAD9B;OALP;AAQA,aAAO,KAAP,CAVuB;KAFpB;GAAP,CAFmE;CAA9D","file":"validation/rules/UniqueFragmentNames.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\n\n\nexport function duplicateFragmentNameMessage(fragName: string): string {\n return `There can only be one fragment named \"${fragName}\".`;\n}\n\n/**\n * Unique fragment names\n *\n * A GraphQL document is only valid if all defined fragments have unique names.\n */\nexport function UniqueFragmentNames(context: ValidationContext): any {\n const knownFragmentNames = Object.create(null);\n return {\n OperationDefinition: () => false,\n FragmentDefinition(node) {\n const fragmentName = node.name.value;\n if (knownFragmentNames[fragmentName]) {\n context.reportError(new GraphQLError(\n duplicateFragmentNameMessage(fragmentName),\n [ knownFragmentNames[fragmentName], node.name ]\n ));\n } else {\n knownFragmentNames[fragmentName] = node.name;\n }\n return false;\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/UniqueInputFieldNames.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.duplicateInputFieldMessage = duplicateInputFieldMessage; 7 | exports.UniqueInputFieldNames = UniqueInputFieldNames; 8 | 9 | var _error = require('../../error'); 10 | 11 | /** 12 | * Copyright (c) 2015, Facebook, Inc. 13 | * All rights reserved. 14 | * 15 | * This source code is licensed under the BSD-style license found in the 16 | * LICENSE file in the root directory of this source tree. An additional grant 17 | * of patent rights can be found in the PATENTS file in the same directory. 18 | */ 19 | 20 | function duplicateInputFieldMessage(fieldName) { 21 | return 'There can be only one input field named "' + fieldName + '".'; 22 | } 23 | 24 | /** 25 | * Unique input field names 26 | * 27 | * A GraphQL input object value is only valid if all supplied fields are 28 | * uniquely named. 29 | */ 30 | function UniqueInputFieldNames(context) { 31 | var knownNameStack = []; 32 | var knownNames = Object.create(null); 33 | 34 | return { 35 | ObjectValue: { 36 | enter: function enter() { 37 | knownNameStack.push(knownNames); 38 | knownNames = Object.create(null); 39 | }, 40 | leave: function leave() { 41 | knownNames = knownNameStack.pop(); 42 | } 43 | }, 44 | ObjectField: function ObjectField(node) { 45 | var fieldName = node.name.value; 46 | if (knownNames[fieldName]) { 47 | context.reportError(new _error.GraphQLError(duplicateInputFieldMessage(fieldName), [knownNames[fieldName], node.name])); 48 | } else { 49 | knownNames[fieldName] = node.name; 50 | } 51 | return false; 52 | } 53 | }; 54 | } 55 | //# sourceMappingURL=UniqueInputFieldNames.js.map 56 | -------------------------------------------------------------------------------- /validation/rules/UniqueInputFieldNames.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | 14 | 15 | export function duplicateInputFieldMessage(fieldName: string): string { 16 | return `There can be only one input field named "${fieldName}".`; 17 | } 18 | 19 | /** 20 | * Unique input field names 21 | * 22 | * A GraphQL input object value is only valid if all supplied fields are 23 | * uniquely named. 24 | */ 25 | export function UniqueInputFieldNames(context: ValidationContext): any { 26 | const knownNameStack = []; 27 | let knownNames = Object.create(null); 28 | 29 | return { 30 | ObjectValue: { 31 | enter() { 32 | knownNameStack.push(knownNames); 33 | knownNames = Object.create(null); 34 | }, 35 | leave() { 36 | knownNames = knownNameStack.pop(); 37 | } 38 | }, 39 | ObjectField(node) { 40 | const fieldName = node.name.value; 41 | if (knownNames[fieldName]) { 42 | context.reportError(new GraphQLError( 43 | duplicateInputFieldMessage(fieldName), 44 | [ knownNames[fieldName], node.name ] 45 | )); 46 | } else { 47 | knownNames[fieldName] = node.name; 48 | } 49 | return false; 50 | } 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /validation/rules/UniqueInputFieldNames.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/UniqueInputFieldNames.js"],"names":[],"mappings":";;;;;QAcgB;QAUA;;AAbhB;;;;;;;;;;;AAGO,SAAS,0BAAT,CAAoC,SAApC,EAA+D;AACpE,uDAAmD,gBAAnD,CADoE;CAA/D;;;;;;;;AAUA,SAAS,qBAAT,CAA+B,OAA/B,EAAgE;AACrE,MAAM,iBAAiB,EAAjB,CAD+D;AAErE,MAAI,aAAa,OAAO,MAAP,CAAc,IAAd,CAAb,CAFiE;;AAIrE,SAAO;AACL,iBAAa;AACX,8BAAQ;AACN,uBAAe,IAAf,CAAoB,UAApB,EADM;AAEN,qBAAa,OAAO,MAAP,CAAc,IAAd,CAAb,CAFM;OADG;AAKX,8BAAQ;AACN,qBAAa,eAAe,GAAf,EAAb,CADM;OALG;KAAb;AASA,sCAAY,MAAM;AAChB,UAAM,YAAY,KAAK,IAAL,CAAU,KAAV,CADF;AAEhB,UAAI,WAAW,SAAX,CAAJ,EAA2B;AACzB,gBAAQ,WAAR,CAAoB,wBAClB,2BAA2B,SAA3B,CADkB,EAElB,CAAE,WAAW,SAAX,CAAF,EAAyB,KAAK,IAAL,CAFP,CAApB,EADyB;OAA3B,MAKO;AACL,mBAAW,SAAX,IAAwB,KAAK,IAAL,CADnB;OALP;AAQA,aAAO,KAAP,CAVgB;KAVb;GAAP,CAJqE;CAAhE","file":"validation/rules/UniqueInputFieldNames.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\n\n\nexport function duplicateInputFieldMessage(fieldName: string): string {\n return `There can be only one input field named \"${fieldName}\".`;\n}\n\n/**\n * Unique input field names\n *\n * A GraphQL input object value is only valid if all supplied fields are\n * uniquely named.\n */\nexport function UniqueInputFieldNames(context: ValidationContext): any {\n const knownNameStack = [];\n let knownNames = Object.create(null);\n\n return {\n ObjectValue: {\n enter() {\n knownNameStack.push(knownNames);\n knownNames = Object.create(null);\n },\n leave() {\n knownNames = knownNameStack.pop();\n }\n },\n ObjectField(node) {\n const fieldName = node.name.value;\n if (knownNames[fieldName]) {\n context.reportError(new GraphQLError(\n duplicateInputFieldMessage(fieldName),\n [ knownNames[fieldName], node.name ]\n ));\n } else {\n knownNames[fieldName] = node.name;\n }\n return false;\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/UniqueOperationNames.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.duplicateOperationNameMessage = duplicateOperationNameMessage; 7 | exports.UniqueOperationNames = UniqueOperationNames; 8 | 9 | var _error = require('../../error'); 10 | 11 | /** 12 | * Copyright (c) 2015, Facebook, Inc. 13 | * All rights reserved. 14 | * 15 | * This source code is licensed under the BSD-style license found in the 16 | * LICENSE file in the root directory of this source tree. An additional grant 17 | * of patent rights can be found in the PATENTS file in the same directory. 18 | */ 19 | 20 | function duplicateOperationNameMessage(operationName) { 21 | return 'There can only be one operation named "' + operationName + '".'; 22 | } 23 | 24 | /** 25 | * Unique operation names 26 | * 27 | * A GraphQL document is only valid if all defined operations have unique names. 28 | */ 29 | function UniqueOperationNames(context) { 30 | var knownOperationNames = Object.create(null); 31 | return { 32 | OperationDefinition: function OperationDefinition(node) { 33 | var operationName = node.name; 34 | if (operationName) { 35 | if (knownOperationNames[operationName.value]) { 36 | context.reportError(new _error.GraphQLError(duplicateOperationNameMessage(operationName.value), [knownOperationNames[operationName.value], operationName])); 37 | } else { 38 | knownOperationNames[operationName.value] = operationName; 39 | } 40 | } 41 | return false; 42 | }, 43 | 44 | FragmentDefinition: function FragmentDefinition() { 45 | return false; 46 | } 47 | }; 48 | } 49 | //# sourceMappingURL=UniqueOperationNames.js.map 50 | -------------------------------------------------------------------------------- /validation/rules/UniqueOperationNames.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | 14 | 15 | export function duplicateOperationNameMessage(operationName: string): string { 16 | return `There can only be one operation named "${operationName}".`; 17 | } 18 | 19 | /** 20 | * Unique operation names 21 | * 22 | * A GraphQL document is only valid if all defined operations have unique names. 23 | */ 24 | export function UniqueOperationNames(context: ValidationContext): any { 25 | const knownOperationNames = Object.create(null); 26 | return { 27 | OperationDefinition(node) { 28 | const operationName = node.name; 29 | if (operationName) { 30 | if (knownOperationNames[operationName.value]) { 31 | context.reportError(new GraphQLError( 32 | duplicateOperationNameMessage(operationName.value), 33 | [ knownOperationNames[operationName.value], operationName ] 34 | )); 35 | } else { 36 | knownOperationNames[operationName.value] = operationName; 37 | } 38 | } 39 | return false; 40 | }, 41 | FragmentDefinition: () => false, 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /validation/rules/UniqueOperationNames.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/UniqueOperationNames.js"],"names":[],"mappings":";;;;;QAcgB;QASA;;AAZhB;;;;;;;;;;;AAGO,SAAS,6BAAT,CAAuC,aAAvC,EAAsE;AAC3E,qDAAiD,oBAAjD,CAD2E;CAAtE;;;;;;;AASA,SAAS,oBAAT,CAA8B,OAA9B,EAA+D;AACpE,MAAM,sBAAsB,OAAO,MAAP,CAAc,IAAd,CAAtB,CAD8D;AAEpE,SAAO;AACL,sDAAoB,MAAM;AACxB,UAAM,gBAAgB,KAAK,IAAL,CADE;AAExB,UAAI,aAAJ,EAAmB;AACjB,YAAI,oBAAoB,cAAc,KAAd,CAAxB,EAA8C;AAC5C,kBAAQ,WAAR,CAAoB,wBAClB,8BAA8B,cAAc,KAAd,CADZ,EAElB,CAAE,oBAAoB,cAAc,KAAd,CAAtB,EAA4C,aAA5C,CAFkB,CAApB,EAD4C;SAA9C,MAKO;AACL,8BAAoB,cAAc,KAAd,CAApB,GAA2C,aAA3C,CADK;SALP;OADF;AAUA,aAAO,KAAP,CAZwB;KADrB;;AAeL,wBAAoB;aAAM;KAAN;GAftB,CAFoE;CAA/D","file":"validation/rules/UniqueOperationNames.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\n\n\nexport function duplicateOperationNameMessage(operationName: string): string {\n return `There can only be one operation named \"${operationName}\".`;\n}\n\n/**\n * Unique operation names\n *\n * A GraphQL document is only valid if all defined operations have unique names.\n */\nexport function UniqueOperationNames(context: ValidationContext): any {\n const knownOperationNames = Object.create(null);\n return {\n OperationDefinition(node) {\n const operationName = node.name;\n if (operationName) {\n if (knownOperationNames[operationName.value]) {\n context.reportError(new GraphQLError(\n duplicateOperationNameMessage(operationName.value),\n [ knownOperationNames[operationName.value], operationName ]\n ));\n } else {\n knownOperationNames[operationName.value] = operationName;\n }\n }\n return false;\n },\n FragmentDefinition: () => false,\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/UniqueVariableNames.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.duplicateVariableMessage = duplicateVariableMessage; 7 | exports.UniqueVariableNames = UniqueVariableNames; 8 | 9 | var _error = require('../../error'); 10 | 11 | function duplicateVariableMessage(variableName) { 12 | return 'There can be only one variable named "' + variableName + '".'; 13 | } 14 | 15 | /** 16 | * Unique variable names 17 | * 18 | * A GraphQL operation is only valid if all its variables are uniquely named. 19 | */ 20 | 21 | /** 22 | * Copyright (c) 2015, Facebook, Inc. 23 | * All rights reserved. 24 | * 25 | * This source code is licensed under the BSD-style license found in the 26 | * LICENSE file in the root directory of this source tree. An additional grant 27 | * of patent rights can be found in the PATENTS file in the same directory. 28 | */ 29 | 30 | function UniqueVariableNames(context) { 31 | var knownVariableNames = Object.create(null); 32 | return { 33 | OperationDefinition: function OperationDefinition() { 34 | knownVariableNames = Object.create(null); 35 | }, 36 | VariableDefinition: function VariableDefinition(node) { 37 | var variableName = node.variable.name.value; 38 | if (knownVariableNames[variableName]) { 39 | context.reportError(new _error.GraphQLError(duplicateVariableMessage(variableName), [knownVariableNames[variableName], node.variable.name])); 40 | } else { 41 | knownVariableNames[variableName] = node.variable.name; 42 | } 43 | } 44 | }; 45 | } 46 | //# sourceMappingURL=UniqueVariableNames.js.map 47 | -------------------------------------------------------------------------------- /validation/rules/UniqueVariableNames.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import type { VariableDefinition } from '../../language/ast'; 13 | import { GraphQLError } from '../../error'; 14 | 15 | 16 | export function duplicateVariableMessage(variableName: string): string { 17 | return `There can be only one variable named "${variableName}".`; 18 | } 19 | 20 | /** 21 | * Unique variable names 22 | * 23 | * A GraphQL operation is only valid if all its variables are uniquely named. 24 | */ 25 | export function UniqueVariableNames(context: ValidationContext): any { 26 | let knownVariableNames = Object.create(null); 27 | return { 28 | OperationDefinition() { 29 | knownVariableNames = Object.create(null); 30 | }, 31 | VariableDefinition(node: VariableDefinition) { 32 | const variableName = node.variable.name.value; 33 | if (knownVariableNames[variableName]) { 34 | context.reportError(new GraphQLError( 35 | duplicateVariableMessage(variableName), 36 | [ knownVariableNames[variableName], node.variable.name ] 37 | )); 38 | } else { 39 | knownVariableNames[variableName] = node.variable.name; 40 | } 41 | } 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /validation/rules/UniqueVariableNames.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/UniqueVariableNames.js"],"names":[],"mappings":";;;;;QAegB;QASA;;AAZhB;;AAGO,SAAS,wBAAT,CAAkC,YAAlC,EAAgE;AACrE,oDAAgD,mBAAhD,CADqE;CAAhE;;;;;;;;;;;;;;;;;AASA,SAAS,mBAAT,CAA6B,OAA7B,EAA8D;AACnE,MAAI,qBAAqB,OAAO,MAAP,CAAc,IAAd,CAArB,CAD+D;AAEnE,SAAO;AACL,wDAAsB;AACpB,2BAAqB,OAAO,MAAP,CAAc,IAAd,CAArB,CADoB;KADjB;AAIL,oDAAmB,MAA0B;AAC3C,UAAM,eAAe,KAAK,QAAL,CAAc,IAAd,CAAmB,KAAnB,CADsB;AAE3C,UAAI,mBAAmB,YAAnB,CAAJ,EAAsC;AACpC,gBAAQ,WAAR,CAAoB,wBAClB,yBAAyB,YAAzB,CADkB,EAElB,CAAE,mBAAmB,YAAnB,CAAF,EAAoC,KAAK,QAAL,CAAc,IAAd,CAFlB,CAApB,EADoC;OAAtC,MAKO;AACL,2BAAmB,YAAnB,IAAmC,KAAK,QAAL,CAAc,IAAd,CAD9B;OALP;KANG;GAAP,CAFmE;CAA9D","file":"validation/rules/UniqueVariableNames.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport type { VariableDefinition } from '../../language/ast';\nimport { GraphQLError } from '../../error';\n\n\nexport function duplicateVariableMessage(variableName: string): string {\n return `There can be only one variable named \"${variableName}\".`;\n}\n\n/**\n * Unique variable names\n *\n * A GraphQL operation is only valid if all its variables are uniquely named.\n */\nexport function UniqueVariableNames(context: ValidationContext): any {\n let knownVariableNames = Object.create(null);\n return {\n OperationDefinition() {\n knownVariableNames = Object.create(null);\n },\n VariableDefinition(node: VariableDefinition) {\n const variableName = node.variable.name.value;\n if (knownVariableNames[variableName]) {\n context.reportError(new GraphQLError(\n duplicateVariableMessage(variableName),\n [ knownVariableNames[variableName], node.variable.name ]\n ));\n } else {\n knownVariableNames[variableName] = node.variable.name;\n }\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/VariablesAreInputTypes.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.nonInputTypeOnVarMessage = nonInputTypeOnVarMessage; 7 | exports.VariablesAreInputTypes = VariablesAreInputTypes; 8 | 9 | var _error = require('../../error'); 10 | 11 | var _printer = require('../../language/printer'); 12 | 13 | var _definition = require('../../type/definition'); 14 | 15 | var _typeFromAST = require('../../utilities/typeFromAST'); 16 | 17 | function nonInputTypeOnVarMessage(variableName, typeName) { 18 | return 'Variable "$' + variableName + '" cannot be non-input type "' + typeName + '".'; 19 | } 20 | 21 | /** 22 | * Variables are input types 23 | * 24 | * A GraphQL operation is only valid if all the variables it defines are of 25 | * input types (scalar, enum, or input object). 26 | */ 27 | 28 | /** 29 | * Copyright (c) 2015, Facebook, Inc. 30 | * All rights reserved. 31 | * 32 | * This source code is licensed under the BSD-style license found in the 33 | * LICENSE file in the root directory of this source tree. An additional grant 34 | * of patent rights can be found in the PATENTS file in the same directory. 35 | */ 36 | 37 | function VariablesAreInputTypes(context) { 38 | return { 39 | VariableDefinition: function VariableDefinition(node) { 40 | var type = (0, _typeFromAST.typeFromAST)(context.getSchema(), node.type); 41 | 42 | // If the variable type is not an input type, return an error. 43 | if (type && !(0, _definition.isInputType)(type)) { 44 | var variableName = node.variable.name.value; 45 | context.reportError(new _error.GraphQLError(nonInputTypeOnVarMessage(variableName, (0, _printer.print)(node.type)), [node.type])); 46 | } 47 | } 48 | }; 49 | } 50 | //# sourceMappingURL=VariablesAreInputTypes.js.map 51 | -------------------------------------------------------------------------------- /validation/rules/VariablesAreInputTypes.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import type { VariableDefinition } from '../../language/ast'; 14 | import { print } from '../../language/printer'; 15 | import { isInputType } from '../../type/definition'; 16 | import { typeFromAST } from '../../utilities/typeFromAST'; 17 | 18 | 19 | export function nonInputTypeOnVarMessage( 20 | variableName: string, 21 | typeName: string 22 | ): string { 23 | return `Variable "$${variableName}" cannot be non-input type "${typeName}".`; 24 | } 25 | 26 | /** 27 | * Variables are input types 28 | * 29 | * A GraphQL operation is only valid if all the variables it defines are of 30 | * input types (scalar, enum, or input object). 31 | */ 32 | export function VariablesAreInputTypes(context: ValidationContext): any { 33 | return { 34 | VariableDefinition(node: VariableDefinition): ?GraphQLError { 35 | const type = typeFromAST(context.getSchema(), node.type); 36 | 37 | // If the variable type is not an input type, return an error. 38 | if (type && !isInputType(type)) { 39 | const variableName = node.variable.name.value; 40 | context.reportError(new GraphQLError( 41 | nonInputTypeOnVarMessage(variableName, print(node.type)), 42 | [ node.type ] 43 | )); 44 | } 45 | } 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /validation/rules/VariablesAreInputTypes.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["validation/rules/VariablesAreInputTypes.js"],"names":[],"mappings":";;;;;QAkBgB;QAaA;;AApBhB;;AAEA;;AACA;;AACA;;AAGO,SAAS,wBAAT,CACL,YADK,EAEL,QAFK,EAGG;AACR,yBAAqB,gDAA2C,eAAhE,CADQ;CAHH;;;;;;;;;;;;;;;;;;AAaA,SAAS,sBAAT,CAAgC,OAAhC,EAAiE;AACtE,SAAO;AACL,oDAAmB,MAAyC;AAC1D,UAAM,OAAO,8BAAY,QAAQ,SAAR,EAAZ,EAAiC,KAAK,IAAL,CAAxC;;;AADoD,UAItD,QAAQ,CAAC,6BAAY,IAAZ,CAAD,EAAoB;AAC9B,YAAM,eAAe,KAAK,QAAL,CAAc,IAAd,CAAmB,KAAnB,CADS;AAE9B,gBAAQ,WAAR,CAAoB,wBAClB,yBAAyB,YAAzB,EAAuC,oBAAM,KAAK,IAAL,CAA7C,CADkB,EAElB,CAAE,KAAK,IAAL,CAFgB,CAApB,EAF8B;OAAhC;KALG;GAAP,CADsE;CAAjE","file":"validation/rules/VariablesAreInputTypes.js","sourcesContent":["/* @flow */\n/**\n * Copyright (c) 2015, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nimport type { ValidationContext } from '../index';\nimport { GraphQLError } from '../../error';\nimport type { VariableDefinition } from '../../language/ast';\nimport { print } from '../../language/printer';\nimport { isInputType } from '../../type/definition';\nimport { typeFromAST } from '../../utilities/typeFromAST';\n\n\nexport function nonInputTypeOnVarMessage(\n variableName: string,\n typeName: string\n): string {\n return `Variable \"$${variableName}\" cannot be non-input type \"${typeName}\".`;\n}\n\n/**\n * Variables are input types\n *\n * A GraphQL operation is only valid if all the variables it defines are of\n * input types (scalar, enum, or input object).\n */\nexport function VariablesAreInputTypes(context: ValidationContext): any {\n return {\n VariableDefinition(node: VariableDefinition): ?GraphQLError {\n const type = typeFromAST(context.getSchema(), node.type);\n\n // If the variable type is not an input type, return an error.\n if (type && !isInputType(type)) {\n const variableName = node.variable.name.value;\n context.reportError(new GraphQLError(\n nonInputTypeOnVarMessage(variableName, print(node.type)),\n [ node.type ]\n ));\n }\n }\n };\n}\n"],"sourceRoot":"/home/iamchenxin/project/fork/graphql-js/src"} -------------------------------------------------------------------------------- /validation/rules/VariablesInAllowedPosition.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.badVarPosMessage = badVarPosMessage; 7 | exports.VariablesInAllowedPosition = VariablesInAllowedPosition; 8 | 9 | var _error = require('../../error'); 10 | 11 | var _definition = require('../../type/definition'); 12 | 13 | var _typeComparators = require('../../utilities/typeComparators'); 14 | 15 | var _typeFromAST = require('../../utilities/typeFromAST'); 16 | 17 | function badVarPosMessage(varName, varType, expectedType) { 18 | return 'Variable "$' + varName + '" of type "' + String(varType) + '" used in ' + ('position expecting type "' + String(expectedType) + '".'); 19 | } 20 | 21 | /** 22 | * Variables passed to field arguments conform to type 23 | */ 24 | 25 | /** 26 | * Copyright (c) 2015, Facebook, Inc. 27 | * All rights reserved. 28 | * 29 | * This source code is licensed under the BSD-style license found in the 30 | * LICENSE file in the root directory of this source tree. An additional grant 31 | * of patent rights can be found in the PATENTS file in the same directory. 32 | */ 33 | 34 | function VariablesInAllowedPosition(context) { 35 | var varDefMap = Object.create(null); 36 | 37 | return { 38 | OperationDefinition: { 39 | enter: function enter() { 40 | varDefMap = Object.create(null); 41 | }, 42 | leave: function leave(operation) { 43 | var usages = context.getRecursiveVariableUsages(operation); 44 | 45 | usages.forEach(function (_ref) { 46 | var node = _ref.node; 47 | var type = _ref.type; 48 | 49 | var varName = node.name.value; 50 | var varDef = varDefMap[varName]; 51 | if (varDef && type) { 52 | // A var type is allowed if it is the same or more strict (e.g. is 53 | // a subtype of) than the expected type. It can be more strict if 54 | // the variable type is non-null when the expected type is nullable. 55 | // If both are list types, the variable item type can be more strict 56 | // than the expected item type (contravariant). 57 | var schema = context.getSchema(); 58 | var varType = (0, _typeFromAST.typeFromAST)(schema, varDef.type); 59 | if (varType && !(0, _typeComparators.isTypeSubTypeOf)(schema, effectiveType(varType, varDef), type)) { 60 | context.reportError(new _error.GraphQLError(badVarPosMessage(varName, varType, type), [varDef, node])); 61 | } 62 | } 63 | }); 64 | } 65 | }, 66 | VariableDefinition: function VariableDefinition(varDefAST) { 67 | varDefMap[varDefAST.variable.name.value] = varDefAST; 68 | } 69 | }; 70 | } 71 | 72 | // If a variable definition has a default value, it's effectively non-null. 73 | function effectiveType(varType, varDef) { 74 | return !varDef.defaultValue || varType instanceof _definition.GraphQLNonNull ? varType : new _definition.GraphQLNonNull(varType); 75 | } 76 | //# sourceMappingURL=VariablesInAllowedPosition.js.map 77 | -------------------------------------------------------------------------------- /validation/rules/VariablesInAllowedPosition.js.flow: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * Copyright (c) 2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import type { ValidationContext } from '../index'; 12 | import { GraphQLError } from '../../error'; 13 | import { GraphQLNonNull } from '../../type/definition'; 14 | import { isTypeSubTypeOf } from '../../utilities/typeComparators'; 15 | import { typeFromAST } from '../../utilities/typeFromAST'; 16 | import type { GraphQLType } from '../../type/definition'; 17 | 18 | 19 | export function badVarPosMessage( 20 | varName: string, 21 | varType: GraphQLType, 22 | expectedType: GraphQLType 23 | ): string { 24 | return `Variable "$${varName}" of type "${String(varType)}" used in ` + 25 | `position expecting type "${String(expectedType)}".`; 26 | } 27 | 28 | /** 29 | * Variables passed to field arguments conform to type 30 | */ 31 | export function VariablesInAllowedPosition(context: ValidationContext): any { 32 | let varDefMap = Object.create(null); 33 | 34 | return { 35 | OperationDefinition: { 36 | enter() { 37 | varDefMap = Object.create(null); 38 | }, 39 | leave(operation) { 40 | const usages = context.getRecursiveVariableUsages(operation); 41 | 42 | usages.forEach(({ node, type }) => { 43 | const varName = node.name.value; 44 | const varDef = varDefMap[varName]; 45 | if (varDef && type) { 46 | // A var type is allowed if it is the same or more strict (e.g. is 47 | // a subtype of) than the expected type. It can be more strict if 48 | // the variable type is non-null when the expected type is nullable. 49 | // If both are list types, the variable item type can be more strict 50 | // than the expected item type (contravariant). 51 | const schema = context.getSchema(); 52 | const varType = typeFromAST(schema, varDef.type); 53 | if ( 54 | varType && 55 | !isTypeSubTypeOf(schema, effectiveType(varType, varDef), type) 56 | ) { 57 | context.reportError(new GraphQLError( 58 | badVarPosMessage(varName, varType, type), 59 | [ varDef, node ] 60 | )); 61 | } 62 | } 63 | }); 64 | } 65 | }, 66 | VariableDefinition(varDefAST) { 67 | varDefMap[varDefAST.variable.name.value] = varDefAST; 68 | } 69 | }; 70 | } 71 | 72 | // If a variable definition has a default value, it's effectively non-null. 73 | function effectiveType(varType, varDef) { 74 | return !varDef.defaultValue || varType instanceof GraphQLNonNull ? 75 | varType : 76 | new GraphQLNonNull(varType); 77 | } 78 | --------------------------------------------------------------------------------