Comparing version 0.1.4 to 0.1.5
'use strict'; | ||
var _get = require('babel-runtime/helpers/get')['default']; | ||
var _inherits = require('babel-runtime/helpers/inherits')['default']; | ||
var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default']; | ||
var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default']; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.locatedError = locatedError; | ||
exports.formatError = formatError; | ||
var _utilsInvariant = require('../utils/invariant'); | ||
var _GraphQLError = require('./GraphQLError'); | ||
var _utilsInvariant2 = _interopRequireDefault(_utilsInvariant); | ||
Object.defineProperty(exports, 'GraphQLError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _GraphQLError.GraphQLError; | ||
} | ||
}); | ||
var _language = require('../language'); | ||
var _syntaxError = require('./syntaxError'); | ||
var GraphQLError = (function (_Error) { | ||
_inherits(GraphQLError, _Error); | ||
Object.defineProperty(exports, 'syntaxError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _syntaxError.syntaxError; | ||
} | ||
}); | ||
function GraphQLError(message, | ||
// A flow bug keeps us from declaring nodes as an array of Node | ||
nodes, stack) { | ||
_classCallCheck(this, GraphQLError); | ||
var _locatedError = require('./locatedError'); | ||
_get(Object.getPrototypeOf(GraphQLError.prototype), 'constructor', this).call(this, message); | ||
this.message = message; | ||
this.stack = stack || message; | ||
if (nodes) { | ||
this.nodes = nodes; | ||
var positions = nodes.map(function (node) { | ||
return node.loc && node.loc.start; | ||
}); | ||
if (positions.some(function (p) { | ||
return !!p; | ||
})) { | ||
this.positions = positions; | ||
var loc = nodes[0].loc; | ||
var source = loc && loc.source; | ||
if (source) { | ||
this.locations = positions.map(function (pos) { | ||
return (0, _language.getLocation)(source, pos); | ||
}); | ||
this.source = source; | ||
} | ||
} | ||
} | ||
Object.defineProperty(exports, 'locatedError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _locatedError.locatedError; | ||
} | ||
}); | ||
return GraphQLError; | ||
})(Error); | ||
var _formatError = require('./formatError'); | ||
exports.GraphQLError = GraphQLError; | ||
function locatedError(error, nodes) { | ||
if (error instanceof GraphQLError) { | ||
return error; | ||
Object.defineProperty(exports, 'formatError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _formatError.formatError; | ||
} | ||
return new GraphQLError(error && error.message, nodes, error ? error.stack : null); | ||
} | ||
}); | ||
function formatError(error) { | ||
(0, _utilsInvariant2['default'])(error, 'Received null or undefined error.'); | ||
if (error.locations) { | ||
return { | ||
message: error.message || '' + error, | ||
locations: error.locations || null | ||
}; | ||
} | ||
return { | ||
message: error.message || '' + error | ||
}; | ||
} | ||
/** | ||
@@ -87,4 +50,2 @@ * Copyright (c) 2015, Facebook, Inc. | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
/*Node*/ | ||
*/ |
@@ -76,3 +76,8 @@ 'use strict'; | ||
/** | ||
* Implements the "Evaluating requests" section of the spec. | ||
* Implements the "Evaluating requests" section of the GraphQL specification. | ||
* | ||
* Returns a Promise that will eventually be resolved and never rejected. | ||
* | ||
* If the arguments to this function do not result in a legal execution context, | ||
* a GraphQLError will be thrown immediately explaining the invalid input. | ||
*/ | ||
@@ -82,18 +87,27 @@ | ||
(0, _utilsInvariant2['default'])(schema, 'Must provide schema'); | ||
var errors = []; | ||
// If a valid context cannot be created due to incorrect arguments, | ||
// this will throw an error. | ||
var context = buildExecutionContext(schema, root, ast, operationName, args); | ||
// Return a Promise that will eventually resolve to the data described by | ||
// The "Response" section of the GraphQL specification. | ||
// | ||
// If errors are encountered while executing a GraphQL field, only that | ||
// field and it's descendents will be omitted, and sibling fields will still | ||
// be executed. An execution which encounters errors will still result in a | ||
// resolved Promise. | ||
return new _Promise(function (resolve) { | ||
var exeContext = buildExecutionContext(schema, root, ast, operationName, args, errors); | ||
resolve(executeOperation(exeContext, root, exeContext.operation)); | ||
resolve(executeOperation(context, root, context.operation)); | ||
})['catch'](function (error) { | ||
errors.push(error); | ||
// Errors from sub-fields of a NonNull type may propagate to the top level, | ||
// at which point we still log the error and null the parent field, which | ||
// in this case is the entire response. | ||
context.errors.push(error); | ||
return null; | ||
}).then(function (data) { | ||
if (!errors.length) { | ||
if (!context.errors.length) { | ||
return { data: data }; | ||
} | ||
return { | ||
data: data, | ||
errors: errors.map(_error.formatError) | ||
}; | ||
return { data: data, errors: context.errors }; | ||
}); | ||
@@ -105,4 +119,7 @@ } | ||
* execute, which we will pass throughout the other execution methods. | ||
* | ||
* Throws a GraphQLError if a valid execution context cannot be created. | ||
*/ | ||
function buildExecutionContext(schema, root, ast, operationName, args, errors) { | ||
function buildExecutionContext(schema, root, ast, operationName, args) { | ||
var errors = []; | ||
var operations = {}; | ||
@@ -121,3 +138,3 @@ var fragments = {}; | ||
if (!operationName && _Object$keys(operations).length !== 1) { | ||
throw new _error.GraphQLError('Must provide operation name if query contains multiple operations'); | ||
throw new _error.GraphQLError('Must provide operation name if query contains multiple operations.'); | ||
} | ||
@@ -127,3 +144,3 @@ var opName = operationName || _Object$keys(operations)[0]; | ||
if (!operation) { | ||
throw new _error.GraphQLError('Unknown operation name: ' + opName); | ||
throw new _error.GraphQLError('Unknown operation named "' + opName + '".'); | ||
} | ||
@@ -301,3 +318,3 @@ var variables = (0, _values.getVariableValues)(schema, operation.variableDefinitions || [], args || {}); | ||
} | ||
if (conditionalType instanceof _typeDefinition.GraphQLInterfaceType || conditionalType instanceof _typeDefinition.GraphQLUnionType) { | ||
if ((0, _typeDefinition.isAbstractType)(conditionalType)) { | ||
return conditionalType.isPossibleType(type); | ||
@@ -309,9 +326,5 @@ } | ||
/** | ||
* A wrapper around Promise.all that operates on an object rather than an | ||
* iterable. | ||
* This function transforms a JS object `{[key: string]: Promise<any>}` into | ||
* a `Promise<{[key: string]: any}>` | ||
* | ||
* Effectively, this method transforms a `Map<string, Promise<T>>` into | ||
* a `Promise<Map<string, T>>`, in the same way that `Promise.all` transforms | ||
* a `Array<Promise<T>>` into a `Promise<Array<T>>`. | ||
* | ||
* This is akin to bluebird's `Promise.props`, but implemented only using | ||
@@ -480,3 +493,3 @@ * `Promise.all` so it will work with any implementation of ES6 promises. | ||
var objectType = fieldType instanceof _typeDefinition.GraphQLObjectType ? fieldType : fieldType instanceof _typeDefinition.GraphQLInterfaceType || fieldType instanceof _typeDefinition.GraphQLUnionType ? fieldType.resolveType(result) : null; | ||
var objectType = fieldType instanceof _typeDefinition.GraphQLObjectType ? fieldType : (0, _typeDefinition.isAbstractType)(fieldType) ? fieldType.resolveType(result) : null; | ||
@@ -483,0 +496,0 @@ if (!objectType) { |
@@ -23,8 +23,2 @@ /** | ||
} | ||
}); | ||
Object.defineProperty(exports, 'formatError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _executor.formatError; | ||
} | ||
}); |
@@ -41,7 +41,17 @@ 'use strict'; | ||
var ast = (0, _languageParser.parse)(source); | ||
var validationResult = (0, _validator.validateDocument)(schema, ast); | ||
if (!validationResult.isValid) { | ||
resolve({ errors: validationResult.errors }); | ||
var validationErrors = (0, _validator.validateDocument)(schema, ast); | ||
if (validationErrors.length > 0) { | ||
resolve({ | ||
errors: validationErrors.map(_error.formatError) | ||
}); | ||
} else { | ||
resolve((0, _executorExecutor.execute)(schema, rootObject, ast, operationName, variableValues)); | ||
resolve((0, _executorExecutor.execute)(schema, rootObject, ast, operationName, variableValues).then(function (result) { | ||
if (result.errors) { | ||
return { | ||
data: result.data, | ||
errors: result.errors.map(_error.formatError) | ||
}; | ||
} | ||
return result; | ||
})); | ||
} | ||
@@ -48,0 +58,0 @@ })['catch'](function (error) { |
@@ -37,2 +37,4 @@ /** | ||
// Define Types. | ||
var _typeDefinition = require('./type/definition'); | ||
@@ -89,2 +91,4 @@ | ||
// Use Pre-defined Scalar Types. | ||
var _typeScalars = require('./type/scalars'); | ||
@@ -121,2 +125,19 @@ | ||
} | ||
}); | ||
// Produce and format errors. | ||
var _error = require('./error'); | ||
Object.defineProperty(exports, 'GraphQLError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _error.GraphQLError; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'formatError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _error.formatError; | ||
} | ||
}); |
@@ -14,3 +14,3 @@ 'use strict'; | ||
var _error = require('./error'); | ||
var _error = require('../error'); | ||
@@ -197,3 +197,3 @@ /** | ||
throw (0, _error.error)(source, position, 'Unexpected character "' + fromCharCode(code) + '"'); | ||
throw (0, _error.syntaxError)(source, position, 'Unexpected character "' + fromCharCode(code) + '".'); | ||
} | ||
@@ -239,3 +239,3 @@ | ||
* Int: -?(0|[1-9][0-9]*) | ||
* Float: -?(0|[1-9][0-9]*)\.[0-9]+(e-?[0-9]+)? | ||
* Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)? | ||
*/ | ||
@@ -262,3 +262,3 @@ function readNumber(source, start, firstCode) { | ||
} else { | ||
throw (0, _error.error)(source, position, 'Invalid number'); | ||
throw (0, _error.syntaxError)(source, position, 'Invalid number.'); | ||
} | ||
@@ -277,20 +277,22 @@ | ||
} else { | ||
throw (0, _error.error)(source, position, 'Invalid number'); | ||
throw (0, _error.syntaxError)(source, position, 'Invalid number.'); | ||
} | ||
} | ||
if (code === 101) { | ||
// e | ||
if (code === 69 || code === 101) { | ||
// E e | ||
isFloat = true; | ||
code = charCodeAt.call(body, ++position); | ||
if (code === 43 || code === 45) { | ||
// + - | ||
code = charCodeAt.call(body, ++position); | ||
if (code === 45) { | ||
// - | ||
} | ||
if (code >= 48 && code <= 57) { | ||
// 0 - 9 | ||
do { | ||
code = charCodeAt.call(body, ++position); | ||
} | ||
if (code >= 48 && code <= 57) { | ||
// 0 - 9 | ||
do { | ||
code = charCodeAt.call(body, ++position); | ||
} while (code >= 48 && code <= 57); // 0 - 9 | ||
} else { | ||
throw (0, _error.error)(source, position, 'Invalid number'); | ||
} | ||
} while (code >= 48 && code <= 57); // 0 - 9 | ||
} else { | ||
throw (0, _error.syntaxError)(source, position, 'Invalid number.'); | ||
} | ||
@@ -340,3 +342,3 @@ } | ||
if (charCode < 0) { | ||
throw (0, _error.error)(source, position, 'Bad character escape sequence'); | ||
throw (0, _error.syntaxError)(source, position, 'Bad character escape sequence.'); | ||
} | ||
@@ -347,3 +349,3 @@ value += fromCharCode(charCode); | ||
default: | ||
throw (0, _error.error)(source, position, 'Bad character escape sequence'); | ||
throw (0, _error.syntaxError)(source, position, 'Bad character escape sequence.'); | ||
} | ||
@@ -356,3 +358,3 @@ ++position; | ||
if (code !== 34) { | ||
throw (0, _error.error)(source, position, 'Unterminated string'); | ||
throw (0, _error.syntaxError)(source, position, 'Unterminated string.'); | ||
} | ||
@@ -359,0 +361,0 @@ |
@@ -22,3 +22,3 @@ /** | ||
var _error = require('./error'); | ||
var _error = require('../error'); | ||
@@ -30,3 +30,4 @@ var _lexer = require('./lexer'); | ||
/** | ||
* Given a GraphQL source, parses it into a Document. Throws on error. | ||
* Given a GraphQL source, parses it into a Document. | ||
* Throws GraphQLError if a syntax error is encountered. | ||
*/ | ||
@@ -114,3 +115,3 @@ | ||
} | ||
throw (0, _error.error)(parser.source, token.start, 'Expected ' + (0, _lexer.getTokenKindDesc)(kind) + ', found ' + (0, _lexer.getTokenDesc)(token)); | ||
throw (0, _error.syntaxError)(parser.source, token.start, 'Expected ' + (0, _lexer.getTokenKindDesc)(kind) + ', found ' + (0, _lexer.getTokenDesc)(token)); | ||
} | ||
@@ -129,3 +130,3 @@ | ||
} | ||
throw (0, _error.error)(parser.source, token.start, 'Expected "' + value + '", found ' + (0, _lexer.getTokenDesc)(token)); | ||
throw (0, _error.syntaxError)(parser.source, token.start, 'Expected "' + value + '", found ' + (0, _lexer.getTokenDesc)(token)); | ||
} | ||
@@ -139,3 +140,3 @@ | ||
var token = atToken || parser.token; | ||
return (0, _error.error)(parser.source, token.start, 'Unexpected ' + (0, _lexer.getTokenDesc)(token)); | ||
return (0, _error.syntaxError)(parser.source, token.start, 'Unexpected ' + (0, _lexer.getTokenDesc)(token)); | ||
} | ||
@@ -340,3 +341,3 @@ | ||
kind: _kinds.FRAGMENT_SPREAD, | ||
name: parseName(parser), | ||
name: parseFragmentName(parser), | ||
directives: parseDirectives(parser), | ||
@@ -347,2 +348,9 @@ loc: loc(parser, start) | ||
function parseFragmentName(parser) { | ||
if (parser.token.value === 'on') { | ||
throw unexpected(parser); | ||
} | ||
return parseName(parser); | ||
} | ||
function parseFragmentDefinition(parser) { | ||
@@ -353,3 +361,3 @@ var start = parser.token.start; | ||
kind: _kinds.FRAGMENT_DEFINITION, | ||
name: parseName(parser), | ||
name: parseFragmentName(parser), | ||
typeCondition: (expectKeyword(parser, 'on'), parseName(parser)), | ||
@@ -401,17 +409,18 @@ directives: parseDirectives(parser), | ||
case _lexer.TokenKind.NAME: | ||
advance(parser); | ||
switch (token.value) { | ||
case 'true': | ||
case 'false': | ||
return { | ||
kind: _kinds.BOOLEAN, | ||
value: token.value === 'true', | ||
loc: loc(parser, token.start) | ||
}; | ||
if (token.value === 'true' || token.value === 'false') { | ||
advance(parser); | ||
return { | ||
kind: _kinds.BOOLEAN, | ||
value: token.value === 'true', | ||
loc: loc(parser, token.start) | ||
}; | ||
} else if (token.value !== 'null') { | ||
advance(parser); | ||
return { | ||
kind: _kinds.ENUM, | ||
value: token.value, | ||
loc: loc(parser, token.start) | ||
}; | ||
} | ||
return { | ||
kind: _kinds.ENUM, | ||
value: token.value, | ||
loc: loc(parser, token.start) | ||
}; | ||
break; | ||
case _lexer.TokenKind.DOLLAR: | ||
@@ -455,3 +464,3 @@ if (!isConst) { | ||
if (fieldNames.hasOwnProperty(name.value)) { | ||
throw (0, _error.error)(parser.source, start, 'Duplicate input object field ' + name.value + '.'); | ||
throw (0, _error.syntaxError)(parser.source, start, 'Duplicate input object field ' + name.value + '.'); | ||
} | ||
@@ -458,0 +467,0 @@ fieldNames[name.value] = true; |
@@ -51,3 +51,3 @@ /** | ||
SelectionSet: function SelectionSet(node) { | ||
return blockList(node.selections, ',\n'); | ||
return length(node.selections) === 0 ? null : indent('{\n' + join(node.selections, '\n')) + '\n}'; | ||
}, | ||
@@ -118,6 +118,2 @@ Field: function Field(node) { | ||
function blockList(list, separator) { | ||
return length(list) === 0 ? null : indent('{\n' + join(list, separator)) + '\n}'; | ||
} | ||
function indent(maybeString) { | ||
@@ -124,0 +120,0 @@ return maybeString && maybeString.replace(/\n/g, '\n '); |
@@ -269,5 +269,2 @@ /** | ||
function getVisitFn(visitor, isLeaving, kind) { | ||
if (!visitor) { | ||
return; | ||
} | ||
var kindVisitor = visitor[kind]; | ||
@@ -274,0 +271,0 @@ if (kindVisitor) { |
@@ -15,3 +15,3 @@ /** | ||
}); | ||
var introspectionQuery = "\n query IntrospectionTestQuery {\n schemaType: __type(name: \"__Schema\") {\n ...FullType\n }\n queryRootType: __type(name: \"QueryRoot\") {\n ...FullType\n }\n __schema {\n __typename\n types {\n ...FullType\n }\n directives {\n __typename\n name\n args {\n __typename\n name\n type { ...TypeRef }\n defaultValue\n }\n onOperation\n onFragment\n onField\n }\n }\n }\n\n fragment FullType on __Type {\n __typename\n kind\n name\n fields {\n __typename\n name\n args {\n __typename\n name\n type { ...TypeRef }\n defaultValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n interfaces {\n ...TypeRef\n }\n enumValues {\n __typename\n name\n isDeprecated\n deprecationReason\n }\n }\n\n fragment TypeRef on __Type {\n __typename\n kind\n name\n ofType {\n __typename\n kind\n name\n ofType {\n __typename\n kind\n name\n ofType {\n __typename\n kind\n name\n }\n }\n }\n }\n"; | ||
var introspectionQuery = "\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n types {\n ...FullType\n }\n directives {\n name\n args {\n name\n type { ...TypeRef }\n defaultValue\n }\n onOperation\n onFragment\n onField\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n fields {\n name\n args {\n name\n type { ...TypeRef }\n defaultValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n name\n type { ...TypeRef }\n defaultValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues {\n name\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\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 }\n }\n }\n }\n"; | ||
exports.introspectionQuery = introspectionQuery; |
@@ -21,3 +21,6 @@ 'use strict'; | ||
var num = +value; | ||
return num === num && num <= MAX_INT && num >= MIN_INT ? num | 0 : null; | ||
if (num === num && num <= MAX_INT && num >= MIN_INT) { | ||
return (num < 0 ? Math.ceil : Math.floor)(num); | ||
} | ||
return null; | ||
}, | ||
@@ -31,2 +34,3 @@ coerceLiteral: function coerceLiteral(ast) { | ||
} | ||
return null; | ||
} | ||
@@ -33,0 +37,0 @@ }); |
'use strict'; | ||
/** | ||
* The result of schema validation. `isValid` is true if validation is | ||
* successful. `errors` is null if no errors occurred, and is a non-empty array | ||
* if any validation errors occurred. | ||
*/ | ||
var _createClass = require('babel-runtime/helpers/create-class')['default']; | ||
@@ -24,4 +18,2 @@ | ||
var _error = require('../error'); | ||
var _schema = require('./schema'); | ||
@@ -32,4 +24,7 @@ | ||
/** | ||
* Checks an input type system for conformance to the "Type System" | ||
* section of the spec. | ||
* Checks an input type schema for conformance to the "Type System" | ||
* section of the spec, returning an array of errors describing any encountered | ||
* issues rendering the schema invalid. | ||
* | ||
* If the schema is valid, an empty array is returned. | ||
*/ | ||
@@ -50,4 +45,3 @@ | ||
var isValid = errors.length === 0; | ||
return { isValid: isValid, errors: isValid ? null : errors.map(_error.formatError) }; | ||
return errors; | ||
} | ||
@@ -54,0 +48,0 @@ |
@@ -179,4 +179,7 @@ 'use strict'; | ||
case _language.Kind.VARIABLE_DEFINITION: | ||
this._inputTypeStack.pop(); | ||
break; | ||
case _language.Kind.ARGUMENT: | ||
this._argument = null; | ||
this._inputTypeStack.pop(); | ||
break; | ||
@@ -183,0 +186,0 @@ case _language.Kind.ARRAY: |
'use strict'; | ||
/** | ||
* The result of validation. `isValid` is true if validation is successful. | ||
* `errors` is null if no errors occurred, and is a non-empty array if any | ||
* validation errors occurred. | ||
*/ | ||
var _createClass = require('babel-runtime/helpers/create-class')['default']; | ||
@@ -43,7 +37,12 @@ | ||
* | ||
* Rules is a list of function which return visitors | ||
* (see the language/visitor API) | ||
* Validation runs synchronously, returning an array of encountered errors, or | ||
* an empty array if no errors were encountered and the document is valid. | ||
* | ||
* Visitors are expected to return Error objects when invalid. | ||
* A list of specific validation rules may be provided. If not provided, the | ||
* default list of rules defined by the GraphQL specification will be used. | ||
* | ||
* Each validation rules is a function which returns a visitor | ||
* (see the language/visitor API). Visitor methods are expected to return | ||
* GraphQLErrors, or Arrays of GraphQLErrors when invalid. | ||
* | ||
* Visitors can also supply `visitSpreadFragments: true` which will alter the | ||
@@ -57,5 +56,3 @@ * behavior of the visitor to skip over top level defined fragments, and instead | ||
(0, _utilsInvariant2['default'])(ast, 'Must provide document'); | ||
var errors = visitUsingRules(schema, ast, rules || _allRules.allRules); | ||
var isValid = errors.length === 0; | ||
return { isValid: isValid, errors: isValid ? null : errors.map(_error.formatError) }; | ||
return visitUsingRules(schema, ast, rules || _allRules.allRules); | ||
} | ||
@@ -185,4 +182,4 @@ | ||
return Array.isArray(value) ? value.every(function (item) { | ||
return item instanceof Error; | ||
}) : value instanceof Error; | ||
return item instanceof _error.GraphQLError; | ||
}) : value instanceof _error.GraphQLError; | ||
} | ||
@@ -189,0 +186,0 @@ |
@@ -27,4 +27,3 @@ 'use strict'; | ||
var type = context.getSchema().getType(typeName); | ||
var isCompositeType = type instanceof _typeDefinition.GraphQLObjectType || type instanceof _typeDefinition.GraphQLInterfaceType || type instanceof _typeDefinition.GraphQLUnionType; | ||
if (!isCompositeType) { | ||
if (!(0, _typeDefinition.isCompositeType)(type)) { | ||
return new _error.GraphQLError('Fragment cannot condition on non composite type "' + typeName + '".', [node.typeCondition]); | ||
@@ -36,4 +35,3 @@ } | ||
var type = context.getSchema().getType(typeName); | ||
var isCompositeType = type instanceof _typeDefinition.GraphQLObjectType || type instanceof _typeDefinition.GraphQLInterfaceType || type instanceof _typeDefinition.GraphQLUnionType; | ||
if (!isCompositeType) { | ||
if (!(0, _typeDefinition.isCompositeType)(type)) { | ||
return new _error.GraphQLError((0, _errors.fragmentOnNonCompositeErrorMessage)(node.name.value, typeName), [node.typeCondition]); | ||
@@ -40,0 +38,0 @@ } |
'use strict'; | ||
var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default']; | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -10,6 +8,2 @@ value: true | ||
var _utilsInvariant = require('../../utils/invariant'); | ||
var _utilsInvariant2 = _interopRequireDefault(_utilsInvariant); | ||
var _error = require('../../error'); | ||
@@ -35,6 +29,14 @@ | ||
VariableDefinition: function VariableDefinition(node) { | ||
var typeName = getTypeASTName(node.type); | ||
var type = context.getSchema().getType(typeName); | ||
var isInputType = type instanceof _typeDefinition.GraphQLScalarType || type instanceof _typeDefinition.GraphQLEnumType || type instanceof _typeDefinition.GraphQLInputObjectType; | ||
if (!isInputType) { | ||
// Get the un-modified type from the variable definition, unwrapping | ||
// List and NonNull. | ||
var typeAST = node.type; | ||
while (typeAST.kind !== _languageKinds.NAME) { | ||
typeAST = typeAST.type; | ||
} | ||
// Get the type definition from the Schema. | ||
var typeDef = context.getSchema().getType(typeAST.value); | ||
// If the variable type is not an input type, return an error. | ||
if (!(0, _typeDefinition.isInputType)(typeDef)) { | ||
var variableName = node.variable.name.value; | ||
@@ -47,18 +49,2 @@ return new _error.GraphQLError((0, _errors.nonInputTypeOnVarMessage)(variableName, (0, _languagePrinter.print)(node.type)), [node.type]); | ||
function getTypeASTName(_x) { | ||
var _again = true; | ||
_function: while (_again) { | ||
var typeAST = _x; | ||
_again = false; | ||
if (typeAST.kind === _languageKinds.NAME) { | ||
return typeAST.value; | ||
} | ||
(0, _utilsInvariant2['default'])(typeAST.type, 'Must be wrapping type'); | ||
_x = typeAST.type; | ||
_again = true; | ||
continue _function; | ||
} | ||
} | ||
module.exports = exports['default']; | ||
@@ -65,0 +51,0 @@ |
{ | ||
"name": "graphql", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "A Query Language and Runtime which can target any service.", | ||
@@ -32,2 +32,8 @@ "contributors": [ | ||
}, | ||
"babel": { | ||
"optional": [ | ||
"runtime", | ||
"es7.asyncFunctions" | ||
] | ||
}, | ||
"scripts": { | ||
@@ -39,16 +45,14 @@ "prepublish": "npm test && npm run build", | ||
"check": "flow check", | ||
"cover": "babel-node node_modules/.bin/isparta cover --report html node_modules/.bin/_mocha -- $npm_package_options_mocha", | ||
"build": "rm -rf lib/* && babel src --ignore __tests__ --optional runtime --out-dir lib", | ||
"watch": "babel --optional runtime scripts/watch.js | node", | ||
"coveralls": "babel-node node_modules/.bin/isparta cover --report html node_modules/.bin/_mocha --report lcovonly -- $npm_package_options_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" | ||
"build": "rm -rf lib/* && babel src --ignore __tests__ --out-dir lib", | ||
"watch": "babel scripts/watch.js | node", | ||
"coveralls": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "5.6.12" | ||
"babel-runtime": "5.7.0" | ||
}, | ||
"devDependencies": { | ||
"babel": "5.6.14", | ||
"babel-core": "5.6.20", | ||
"babel": "5.6.23", | ||
"babel-core": "5.7.2", | ||
"babel-eslint": "3.1.23", | ||
"chai": "3.0.0", | ||
"chai-as-promised": "5.1.0", | ||
"chai-subset": "1.0.1", | ||
@@ -55,0 +59,0 @@ "coveralls": "2.11.2", |
@@ -131,4 +131,5 @@ # GraphQL.js | ||
GraphQL is written in ES6 using [Babel](http://babeljs.io/), widely consumable | ||
JavaScript can be produced by running: | ||
GraphQL is written in ES6 and uses [Babel](http://babeljs.io/) for ES5 | ||
transpilation and [Flow](http://flowtype.org/) for type safety. Widely | ||
consumable JavaScript can be produced by running: | ||
@@ -135,0 +136,0 @@ ```sh |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
231965
11
65
6205
158
0
+ Addedbabel-runtime@5.7.0(transitive)
- Removedbabel-runtime@5.6.12(transitive)
Updatedbabel-runtime@5.7.0