Comparing version 0.9.1 to 0.9.2
@@ -252,4 +252,5 @@ 'use strict'; | ||
} | ||
if (isThenable(result)) { | ||
return result.then(function (resolvedResult) { | ||
var promise = getPromise(result); | ||
if (promise) { | ||
return promise.then(function (resolvedResult) { | ||
results[responseName] = resolvedResult; | ||
@@ -280,3 +281,3 @@ return results; | ||
results[responseName] = result; | ||
if (isThenable(result)) { | ||
if (getPromise(result)) { | ||
containsPromise = true; | ||
@@ -497,3 +498,4 @@ } | ||
var completed = completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result); | ||
if (isThenable(completed)) { | ||
var promise = getPromise(completed); | ||
if (promise) { | ||
// If `completeValueWithLocatedError` returned a rejected promise, log | ||
@@ -503,3 +505,3 @@ // the rejection error and resolve to null. | ||
// to take a second callback for the error case. | ||
return completed.then(undefined, function (error) { | ||
return promise.then(undefined, function (error) { | ||
exeContext.errors.push(error); | ||
@@ -523,4 +525,5 @@ return Promise.resolve(null); | ||
var completed = completeValue(exeContext, returnType, fieldNodes, info, path, result); | ||
if (isThenable(completed)) { | ||
return completed.then(undefined, function (error) { | ||
var promise = getPromise(completed); | ||
if (promise) { | ||
return promise.then(undefined, function (error) { | ||
return Promise.reject((0, _error.locatedError)(error, fieldNodes, responsePathAsArray(path))); | ||
@@ -558,4 +561,5 @@ }); | ||
// If result is a Promise, apply-lift over completeValue. | ||
if (isThenable(result)) { | ||
return result.then(function (resolved) { | ||
var promise = getPromise(result); | ||
if (promise) { | ||
return promise.then(function (resolved) { | ||
return completeValue(exeContext, returnType, fieldNodes, info, path, resolved); | ||
@@ -629,3 +633,3 @@ }); | ||
if (!containsPromise && isThenable(completedItem)) { | ||
if (!containsPromise && getPromise(completedItem)) { | ||
containsPromise = true; | ||
@@ -659,6 +663,5 @@ } | ||
if (isThenable(runtimeType)) { | ||
// Cast to Promise | ||
var runtimeTypePromise = runtimeType; | ||
return runtimeTypePromise.then(function (resolvedRuntimeType) { | ||
var promise = getPromise(runtimeType); | ||
if (promise) { | ||
return promise.then(function (resolvedRuntimeType) { | ||
return completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result); | ||
@@ -695,4 +698,5 @@ }); | ||
if (isThenable(isTypeOf)) { | ||
return isTypeOf.then(function (isTypeOfResult) { | ||
var promise = getPromise(isTypeOf); | ||
if (promise) { | ||
return promise.then(function (isTypeOfResult) { | ||
if (!isTypeOfResult) { | ||
@@ -746,4 +750,5 @@ throw invalidReturnTypeError(returnType, result, fieldNodes); | ||
if (isThenable(isTypeOfResult)) { | ||
promisedIsTypeOfResults[i] = isTypeOfResult; | ||
var promise = getPromise(isTypeOfResult); | ||
if (promise) { | ||
promisedIsTypeOfResults[i] = promise; | ||
} else if (isTypeOfResult) { | ||
@@ -784,7 +789,9 @@ return type; | ||
/** | ||
* Checks to see if this object acts like a Promise, i.e. has a "then" | ||
* function. | ||
* Only returns the value if it acts like a Promise, i.e. has a "then" function, | ||
* otherwise returns void. | ||
*/ | ||
function isThenable(value) { | ||
return typeof value === 'object' && value !== null && typeof value.then === 'function'; | ||
function getPromise(value) { | ||
if (typeof value === 'object' && value !== null && typeof value.then === 'function') { | ||
return value; | ||
} | ||
} | ||
@@ -791,0 +798,0 @@ |
@@ -1,1 +0,1 @@ | ||
{"name":"graphql","version":"0.9.1","description":"A Query Language and Runtime which can target any service.","contributors":["Lee Byron <lee@leebyron.com> (http://leebyron.com/)","Nicholas Schrock <schrockn@fb.com>","Daniel Schafer <dschafer@fb.com>"],"license":"BSD-3-Clause","main":"index.js","homepage":"https://github.com/graphql/graphql-js","bugs":{"url":"https://github.com/graphql/graphql-js/issues"},"repository":{"type":"git","url":"http://github.com/graphql/graphql-js.git"},"dependencies":{"iterall":"1.0.3"}} | ||
{"name":"graphql","version":"0.9.2","description":"A Query Language and Runtime which can target any service.","contributors":["Lee Byron <lee@leebyron.com> (http://leebyron.com/)","Nicholas Schrock <schrockn@fb.com>","Daniel Schafer <dschafer@fb.com>"],"license":"BSD-3-Clause","main":"index.js","homepage":"https://github.com/graphql/graphql-js","bugs":{"url":"https://github.com/graphql/graphql-js/issues"},"repository":{"type":"git","url":"http://github.com/graphql/graphql-js.git"},"dependencies":{"iterall":"1.0.3"}} |
@@ -95,4 +95,3 @@ 'use strict'; | ||
function isLeafType(type) { | ||
var namedType = getNamedType(type); | ||
return namedType instanceof GraphQLScalarType || namedType instanceof GraphQLEnumType; | ||
return type instanceof GraphQLScalarType || type instanceof GraphQLEnumType; | ||
} | ||
@@ -331,2 +330,3 @@ | ||
var fieldConfig = fieldMap[fieldName]; | ||
(0, _invariant2.default)(isPlainObj(fieldConfig), type.name + '.' + fieldName + ' field config must be an object'); | ||
(0, _invariant2.default)(!fieldConfig.hasOwnProperty('isDeprecated'), type.name + '.' + fieldName + ' should provide "deprecationReason" instead ' + 'of "isDeprecated".'); | ||
@@ -333,0 +333,0 @@ var field = _extends({}, fieldConfig, { |
@@ -7,2 +7,3 @@ 'use strict'; | ||
exports.assertValidName = assertValidName; | ||
exports.formatWarning = formatWarning; | ||
@@ -19,2 +20,3 @@ /** | ||
var NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/; | ||
var ERROR_PREFIX_RX = /^Error: /; | ||
@@ -34,5 +36,5 @@ // Ensures console warnings are only issued once. | ||
/* eslint-disable no-console */ | ||
if (console && console.error) { | ||
var error = new Error('Name "' + name + '" must not begin with "__", which is reserved by ' + 'GraphQL introspection.'); | ||
console.error(error.stack || String(error)); | ||
if (console && console.warn) { | ||
var error = new Error('Name "' + name + '" must not begin with "__", which is reserved by ' + 'GraphQL introspection. In a future release of graphql this will ' + 'become a hard error.'); | ||
console.warn(formatWarning(error)); | ||
} | ||
@@ -44,2 +46,19 @@ /* eslint-enable no-console */ | ||
} | ||
} | ||
/** | ||
* Returns a human-readable warning based an the supplied Error object, | ||
* including stack trace information if available. | ||
*/ | ||
function formatWarning(error) { | ||
var formatted = ''; | ||
var errorString = String(error).replace(ERROR_PREFIX_RX, ''); | ||
var stack = error.stack; | ||
if (stack) { | ||
formatted = stack.replace(ERROR_PREFIX_RX, ''); | ||
} | ||
if (formatted.indexOf(errorString) === -1) { | ||
formatted = errorString + '\n' + formatted; | ||
} | ||
return formatted.trim(); | ||
} |
@@ -7,2 +7,3 @@ 'use strict'; | ||
exports.buildASTSchema = buildASTSchema; | ||
exports.getDeprecationReason = getDeprecationReason; | ||
exports.getDescription = getDescription; | ||
@@ -417,2 +418,6 @@ exports.buildSchema = buildSchema; | ||
/** | ||
* Given a collection of directives, returns the string value for the | ||
* deprecation reason. | ||
*/ | ||
function getDeprecationReason(directives) { | ||
@@ -419,0 +424,0 @@ var deprecatedAST = directives && (0, _find2.default)(directives, function (directive) { |
@@ -351,3 +351,4 @@ 'use strict'; | ||
type: buildOutputFieldType(field.type), | ||
args: buildInputValues(field.arguments) | ||
args: buildInputValues(field.arguments), | ||
deprecationReason: (0, _buildASTSchema.getDeprecationReason)(field.directives) | ||
}; | ||
@@ -446,6 +447,9 @@ }); | ||
description: (0, _buildASTSchema.getDescription)(typeNode), | ||
values: (0, _keyValMap2.default)(typeNode.values, function (v) { | ||
return v.name.value; | ||
}, function () { | ||
return {}; | ||
values: (0, _keyValMap2.default)(typeNode.values, function (enumValue) { | ||
return enumValue.name.value; | ||
}, function (enumValue) { | ||
return { | ||
description: (0, _buildASTSchema.getDescription)(enumValue), | ||
deprecationReason: (0, _buildASTSchema.getDeprecationReason)(enumValue.directives) | ||
}; | ||
}) | ||
@@ -486,3 +490,4 @@ }); | ||
description: (0, _buildASTSchema.getDescription)(field), | ||
args: buildInputValues(field.arguments) | ||
args: buildInputValues(field.arguments), | ||
deprecationReason: (0, _buildASTSchema.getDeprecationReason)(field.directives) | ||
}; | ||
@@ -489,0 +494,0 @@ }); |
@@ -6,6 +6,8 @@ 'use strict'; | ||
}); | ||
exports.BreakingChangeType = undefined; | ||
exports.DangerousChangeType = exports.BreakingChangeType = undefined; | ||
exports.findBreakingChanges = findBreakingChanges; | ||
exports.findDangerousChanges = findDangerousChanges; | ||
exports.findRemovedTypes = findRemovedTypes; | ||
exports.findTypesThatChangedKind = findTypesThatChangedKind; | ||
exports.findArgChanges = findArgChanges; | ||
exports.findFieldsThatChangedType = findFieldsThatChangedType; | ||
@@ -34,5 +36,11 @@ exports.findTypesRemovedFromUnions = findTypesRemovedFromUnions; | ||
TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION', | ||
VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM' | ||
VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM', | ||
ARG_REMOVED: 'ARG_REMOVED', | ||
ARG_CHANGED_KIND: 'ARG_CHANGED_KIND' | ||
}; | ||
var DangerousChangeType = exports.DangerousChangeType = { | ||
ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE' | ||
}; | ||
/** | ||
@@ -43,6 +51,14 @@ * Given two schemas, returns an Array containing descriptions of all the types | ||
function findBreakingChanges(oldSchema, newSchema) { | ||
return [].concat(findRemovedTypes(oldSchema, newSchema), findTypesThatChangedKind(oldSchema, newSchema), findFieldsThatChangedType(oldSchema, newSchema), findTypesRemovedFromUnions(oldSchema, newSchema), findValuesRemovedFromEnums(oldSchema, newSchema)); | ||
return [].concat(findRemovedTypes(oldSchema, newSchema), findTypesThatChangedKind(oldSchema, newSchema), findFieldsThatChangedType(oldSchema, newSchema), findTypesRemovedFromUnions(oldSchema, newSchema), findValuesRemovedFromEnums(oldSchema, newSchema), findArgChanges(oldSchema, newSchema).breakingChanges); | ||
} | ||
/** | ||
* Given two schemas, returns an Array containing descriptions of all the types | ||
* of potentially dangerous changes covered by the other functions down below. | ||
*/ | ||
function findDangerousChanges(oldSchema, newSchema) { | ||
return [].concat(findArgChanges(oldSchema, newSchema).dangerousChanges); | ||
} | ||
/** | ||
* Given two schemas, returns an Array containing descriptions of any breaking | ||
@@ -92,2 +108,68 @@ * changes in the newSchema related to removing an entire type. | ||
/** | ||
* Given two schemas, returns an Array containing descriptions of any | ||
* breaking or dangerous changes in the newSchema related to arguments | ||
* (such as removal or change of type of an argument, or a change in an | ||
* argument's default value). | ||
*/ | ||
function findArgChanges(oldSchema, newSchema) { | ||
var oldTypeMap = oldSchema.getTypeMap(); | ||
var newTypeMap = newSchema.getTypeMap(); | ||
var breakingChanges = []; | ||
var dangerousChanges = []; | ||
Object.keys(oldTypeMap).forEach(function (typeName) { | ||
var oldType = oldTypeMap[typeName]; | ||
var newType = newTypeMap[typeName]; | ||
if (!(oldType instanceof _definition.GraphQLObjectType) || !(newType instanceof oldType.constructor)) { | ||
return; | ||
} | ||
var oldTypeFields = oldType.getFields(); | ||
var newTypeFields = newType.getFields(); | ||
Object.keys(oldTypeFields).forEach(function (fieldName) { | ||
if (!newTypeFields[fieldName]) { | ||
return; | ||
} | ||
oldTypeFields[fieldName].args.forEach(function (oldArgDef) { | ||
var newArgs = newTypeFields[fieldName].args; | ||
var newTypeArgIndex = newArgs.findIndex(function (arg) { | ||
return arg.name === oldArgDef.name; | ||
}); | ||
var newArgDef = newArgs[newTypeArgIndex]; | ||
// Arg not present | ||
if (newTypeArgIndex < 0) { | ||
breakingChanges.push({ | ||
type: BreakingChangeType.ARG_REMOVED, | ||
description: oldType.name + '.' + fieldName + ' arg ' + (oldArgDef.name + ' was removed') | ||
}); | ||
// Arg changed type in a breaking way | ||
} else if (oldArgDef.type !== newArgDef.type && (0, _definition.getNullableType)(oldArgDef.type) !== newArgDef.type) { | ||
breakingChanges.push({ | ||
type: BreakingChangeType.ARG_CHANGED_KIND, | ||
description: oldType.name + '.' + fieldName + ' arg ' + (oldArgDef.name + ' has changed type from ') + (oldArgDef.type.toString() + ' to ' + newArgDef.type.toString()) | ||
}); | ||
// Arg default value has changed | ||
} else if (oldArgDef.defaultValue !== undefined && oldArgDef.defaultValue !== newArgDef.defaultValue) { | ||
dangerousChanges.push({ | ||
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE, | ||
description: oldType.name + '.' + fieldName + ' arg ' + oldArgDef.name + ' ' + 'has changed defaultValue' | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
return { | ||
breakingChanges: breakingChanges, | ||
dangerousChanges: dangerousChanges | ||
}; | ||
} | ||
function typeKindName(type) { | ||
@@ -94,0 +176,0 @@ if (type instanceof _definition.GraphQLScalarType) { |
@@ -19,13 +19,19 @@ 'use strict'; | ||
var operations = []; | ||
var fragments = Object.create(null); | ||
var positions = new Map(); | ||
var depGraph = Object.create(null); | ||
var fromName = void 0; | ||
var idx = 0; | ||
// Populate the list of operations and build a dependency graph. | ||
// Populate metadata and build a dependency graph. | ||
(0, _visitor.visit)(documentAST, { | ||
OperationDefinition: function OperationDefinition(node) { | ||
fromName = opName(node); | ||
operations.push(node); | ||
fromName = opName(node); | ||
positions.set(node, idx++); | ||
}, | ||
FragmentDefinition: function FragmentDefinition(node) { | ||
fromName = node.name.value; | ||
fragments[fromName] = node; | ||
positions.set(node, idx++); | ||
}, | ||
@@ -46,7 +52,15 @@ FragmentSpread: function FragmentSpread(node) { | ||
// The list of definition nodes to be included for this operation, sorted | ||
// to retain the same order as the original document. | ||
var definitions = [operation]; | ||
Object.keys(dependencies).forEach(function (name) { | ||
definitions.push(fragments[name]); | ||
}); | ||
definitions.sort(function (n1, n2) { | ||
return (positions.get(n1) || 0) - (positions.get(n2) || 0); | ||
}); | ||
separatedDocumentASTs[operationName] = { | ||
kind: 'Document', | ||
definitions: documentAST.definitions.filter(function (def) { | ||
return def === operation || def.kind === 'FragmentDefinition' && dependencies[def.name.value]; | ||
}) | ||
definitions: definitions | ||
}; | ||
@@ -53,0 +67,0 @@ }); |
@@ -103,8 +103,3 @@ 'use strict'; | ||
var namedType = (0, _definition.getNamedType)(this.getType()); | ||
var compositeType = void 0; | ||
if ((0, _definition.isCompositeType)(namedType)) { | ||
// isCompositeType is a type refining predicate, so this is safe. | ||
compositeType = namedType; | ||
} | ||
this._parentTypeStack.push(compositeType); | ||
this._parentTypeStack.push((0, _definition.isCompositeType)(namedType) ? namedType : undefined); | ||
break; | ||
@@ -138,7 +133,7 @@ case Kind.FIELD: | ||
var outputType = typeConditionAST ? (0, _typeFromAST.typeFromAST)(schema, typeConditionAST) : this.getType(); | ||
this._typeStack.push(outputType); | ||
this._typeStack.push((0, _definition.isOutputType)(outputType) ? outputType : undefined); | ||
break; | ||
case Kind.VARIABLE_DEFINITION: | ||
var inputType = (0, _typeFromAST.typeFromAST)(schema, node.type); | ||
this._inputTypeStack.push(inputType); | ||
this._inputTypeStack.push((0, _definition.isInputType)(inputType) ? inputType : undefined); | ||
break; | ||
@@ -145,0 +140,0 @@ case Kind.ARGUMENT: |
@@ -16,2 +16,7 @@ 'use strict'; | ||
var _typeFromAST = require('../../utilities/typeFromAST'); | ||
function inlineFragmentOnNonCompositeErrorMessage(type) { | ||
return 'Fragment cannot condition on non composite type "' + String(type) + '".'; | ||
} | ||
/** | ||
@@ -26,6 +31,2 @@ * Copyright (c) 2015, Facebook, Inc. | ||
function inlineFragmentOnNonCompositeErrorMessage(type) { | ||
return 'Fragment cannot condition on non composite type "' + String(type) + '".'; | ||
} | ||
function fragmentOnNonCompositeErrorMessage(fragName, type) { | ||
@@ -45,9 +46,11 @@ return 'Fragment "' + fragName + '" cannot condition on non composite ' + ('type "' + String(type) + '".'); | ||
InlineFragment: function InlineFragment(node) { | ||
var type = context.getType(); | ||
if (node.typeCondition && type && !(0, _definition.isCompositeType)(type)) { | ||
context.reportError(new _error.GraphQLError(inlineFragmentOnNonCompositeErrorMessage((0, _printer.print)(node.typeCondition)), [node.typeCondition])); | ||
if (node.typeCondition) { | ||
var type = (0, _typeFromAST.typeFromAST)(context.getSchema(), node.typeCondition); | ||
if (type && !(0, _definition.isCompositeType)(type)) { | ||
context.reportError(new _error.GraphQLError(inlineFragmentOnNonCompositeErrorMessage((0, _printer.print)(node.typeCondition)), [node.typeCondition])); | ||
} | ||
} | ||
}, | ||
FragmentDefinition: function FragmentDefinition(node) { | ||
var type = context.getType(); | ||
var type = (0, _typeFromAST.typeFromAST)(context.getSchema(), node.typeCondition); | ||
if (type && !(0, _definition.isCompositeType)(type)) { | ||
@@ -54,0 +57,0 @@ context.reportError(new _error.GraphQLError(fragmentOnNonCompositeErrorMessage(node.name.value, (0, _printer.print)(node.typeCondition)), [node.typeCondition])); |
@@ -41,3 +41,3 @@ 'use strict'; | ||
if (type) { | ||
if ((0, _definition.isLeafType)(type)) { | ||
if ((0, _definition.isLeafType)((0, _definition.getNamedType)(type))) { | ||
if (node.selectionSet) { | ||
@@ -44,0 +44,0 @@ context.reportError(new _error.GraphQLError(noSubselectionAllowedMessage(node.name.value, type), [node.selectionSet])); |
@@ -21,3 +21,3 @@ 'use strict'; | ||
function duplicateFragmentNameMessage(fragName) { | ||
return 'There can only be one fragment named "' + fragName + '".'; | ||
return 'There can be only one fragment named "' + fragName + '".'; | ||
} | ||
@@ -24,0 +24,0 @@ |
@@ -21,3 +21,3 @@ 'use strict'; | ||
function duplicateOperationNameMessage(operationName) { | ||
return 'There can only be one operation named "' + operationName + '".'; | ||
return 'There can be only one operation named "' + operationName + '".'; | ||
} | ||
@@ -24,0 +24,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
924508
11014