Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql

Package Overview
Dependencies
Maintainers
3
Versions
260
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql - npm Package Compare versions

Comparing version 0.7.2 to 0.8.0-beta1

jsutils/isInvalid.js

4

error/locatedError.js

@@ -18,3 +18,3 @@ 'use strict';

// other contexts.
if (originalError && originalError.locations) {
if (originalError && originalError.path) {
return originalError;

@@ -24,3 +24,3 @@ }

var message = originalError ? originalError.message || String(originalError) : 'An unknown error occurred.';
return new _GraphQLError.GraphQLError(message, nodes, undefined, undefined, path, originalError);
return new _GraphQLError.GraphQLError(message, originalError && originalError.nodes || nodes, originalError && originalError.source, originalError && originalError.positions, path, originalError);
}

@@ -27,0 +27,0 @@ /**

@@ -6,2 +6,3 @@ 'use strict';

});
exports.defaultFieldResolver = undefined;
exports.execute = execute;

@@ -84,5 +85,6 @@

/**
* The result of execution. `data` is the result of executing the
* query, `errors` is null if no errors occurred, and is a
* non-empty array if an error occurred.
* The result of GraphQL execution.
*
* - `data` is the result of a successful execution of the query.
* - `errors` is included when any errors occurred as a non-empty array.
*/

@@ -99,3 +101,3 @@

function execute(schema, documentAST, rootValue, contextValue, variableValues, operationName) {
function execute(schema, document, rootValue, contextValue, variableValues, operationName) {
(0, _invariant2.default)(schema, 'Must provide schema');

@@ -109,3 +111,3 @@ (0, _invariant2.default)(schema instanceof _schema.GraphQLSchema, 'Schema must be an instance of GraphQLSchema. Also ensure that there are ' + 'not multiple versions of GraphQL installed in your node_modules directory.');

// this will throw an error.
var context = buildExecutionContext(schema, documentAST, rootValue, contextValue, variableValues, operationName);
var context = buildExecutionContext(schema, document, rootValue, contextValue, variableValues, operationName);

@@ -141,7 +143,7 @@ // Return a Promise that will eventually resolve to the data described by

*/
function buildExecutionContext(schema, documentAST, rootValue, contextValue, rawVariableValues, operationName) {
function buildExecutionContext(schema, document, rootValue, contextValue, rawVariableValues, operationName) {
var errors = [];
var operation = void 0;
var fragments = Object.create(null);
documentAST.definitions.forEach(function (definition) {
document.definitions.forEach(function (definition) {
switch (definition.kind) {

@@ -229,5 +231,5 @@ case Kind.OPERATION_DEFINITION:

return prevPromise.then(function (results) {
var fieldASTs = fields[responseName];
var fieldNodes = fields[responseName];
var fieldPath = path.concat([responseName]);
var result = resolveField(exeContext, parentType, sourceValue, fieldASTs, fieldPath);
var result = resolveField(exeContext, parentType, sourceValue, fieldNodes, fieldPath);
if (result === undefined) {

@@ -256,5 +258,5 @@ return results;

var finalResults = Object.keys(fields).reduce(function (results, responseName) {
var fieldASTs = fields[responseName];
var fieldNodes = fields[responseName];
var fieldPath = path.concat([responseName]);
var result = resolveField(exeContext, parentType, sourceValue, fieldASTs, fieldPath);
var result = resolveField(exeContext, parentType, sourceValue, fieldNodes, fieldPath);
if (result === undefined) {

@@ -332,10 +334,9 @@ return results;

function shouldIncludeNode(exeContext, directives) {
var skipAST = directives && (0, _find2.default)(directives, function (directive) {
var skipNode = directives && (0, _find2.default)(directives, function (directive) {
return directive.name.value === _directives.GraphQLSkipDirective.name;
});
if (skipAST) {
var _getArgumentValues = (0, _values.getArgumentValues)(_directives.GraphQLSkipDirective.args, skipAST.arguments, exeContext.variableValues);
if (skipNode) {
var _getArgumentValues = (0, _values.getArgumentValues)(_directives.GraphQLSkipDirective, skipNode, exeContext.variableValues),
skipIf = _getArgumentValues.if;
var skipIf = _getArgumentValues.if;
if (skipIf === true) {

@@ -346,10 +347,9 @@ return false;

var includeAST = directives && (0, _find2.default)(directives, function (directive) {
var includeNode = directives && (0, _find2.default)(directives, function (directive) {
return directive.name.value === _directives.GraphQLIncludeDirective.name;
});
if (includeAST) {
var _getArgumentValues2 = (0, _values.getArgumentValues)(_directives.GraphQLIncludeDirective.args, includeAST.arguments, exeContext.variableValues);
if (includeNode) {
var _getArgumentValues2 = (0, _values.getArgumentValues)(_directives.GraphQLIncludeDirective, includeNode, exeContext.variableValues),
includeIf = _getArgumentValues2.if;
var includeIf = _getArgumentValues2.if;
if (includeIf === false) {

@@ -367,7 +367,7 @@ return false;

function doesFragmentConditionMatch(exeContext, fragment, type) {
var typeConditionAST = fragment.typeCondition;
if (!typeConditionAST) {
var typeConditionNode = fragment.typeCondition;
if (!typeConditionNode) {
return true;
}
var conditionalType = (0, _typeFromAST.typeFromAST)(exeContext.schema, typeConditionAST);
var conditionalType = (0, _typeFromAST.typeFromAST)(exeContext.schema, typeConditionNode);
if (conditionalType === type) {

@@ -416,5 +416,5 @@ return true;

*/
function resolveField(exeContext, parentType, source, fieldASTs, path) {
var fieldAST = fieldASTs[0];
var fieldName = fieldAST.name.value;
function resolveField(exeContext, parentType, source, fieldNodes, path) {
var fieldNode = fieldNodes[0];
var fieldName = fieldNode.name.value;

@@ -427,9 +427,4 @@ var fieldDef = getFieldDef(exeContext.schema, parentType, fieldName);

var returnType = fieldDef.type;
var resolveFn = fieldDef.resolve || defaultResolveFn;
var resolveFn = fieldDef.resolve || defaultFieldResolver;
// Build a JS object of arguments from the field.arguments AST, using the
// variables scope to fulfill any variable references.
// TODO: find a way to memoize, in case this field is within a List type.
var args = (0, _values.getArgumentValues)(fieldDef.args, fieldAST.arguments, exeContext.variableValues);
// The resolve function's optional third argument is a context value that

@@ -444,3 +439,3 @@ // is provided to every resolve function within an execution. It is commonly

fieldName: fieldName,
fieldASTs: fieldASTs,
fieldNodes: fieldNodes,
returnType: returnType,

@@ -458,5 +453,5 @@ parentType: parentType,

// or abrupt (error).
var result = resolveOrError(resolveFn, source, args, context, info);
var result = resolveOrError(exeContext, fieldDef, fieldNode, resolveFn, source, context, info);
return completeValueCatchingError(exeContext, returnType, fieldASTs, info, path, result);
return completeValueCatchingError(exeContext, returnType, fieldNodes, info, path, result);
}

@@ -466,4 +461,9 @@

// function. Returns the result of resolveFn or the abrupt-return Error object.
function resolveOrError(resolveFn, source, args, context, info) {
function resolveOrError(exeContext, fieldDef, fieldNode, resolveFn, source, context, info) {
try {
// Build a JS object of arguments from the field.arguments AST, using the
// variables scope to fulfill any variable references.
// TODO: find a way to memoize, in case this field is within a List type.
var args = (0, _values.getArgumentValues)(fieldDef, fieldNode, exeContext.variableValues);
return resolveFn(source, args, context, info);

@@ -479,7 +479,7 @@ } catch (error) {

// in the execution context.
function completeValueCatchingError(exeContext, returnType, fieldASTs, info, path, result) {
function completeValueCatchingError(exeContext, returnType, fieldNodes, info, path, result) {
// If the field type is non-nullable, then it is resolved without any
// protection from errors, however it still properly locates the error.
if (returnType instanceof _definition.GraphQLNonNull) {
return completeValueWithLocatedError(exeContext, returnType, fieldASTs, info, path, result);
return completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result);
}

@@ -490,3 +490,3 @@

try {
var completed = completeValueWithLocatedError(exeContext, returnType, fieldASTs, info, path, result);
var completed = completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result);
if (isThenable(completed)) {

@@ -513,8 +513,8 @@ // If `completeValueWithLocatedError` returned a rejected promise, log

// location information.
function completeValueWithLocatedError(exeContext, returnType, fieldASTs, info, path, result) {
function completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result) {
try {
var completed = completeValue(exeContext, returnType, fieldASTs, info, path, result);
var completed = completeValue(exeContext, returnType, fieldNodes, info, path, result);
if (isThenable(completed)) {
return completed.then(undefined, function (error) {
return Promise.reject((0, _error.locatedError)(error, fieldASTs, path));
return Promise.reject((0, _error.locatedError)(error, fieldNodes, path));
});

@@ -524,3 +524,3 @@ }

} catch (error) {
throw (0, _error.locatedError)(error, fieldASTs, path);
throw (0, _error.locatedError)(error, fieldNodes, path);
}

@@ -550,7 +550,7 @@ }

*/
function completeValue(exeContext, returnType, fieldASTs, info, path, result) {
function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
// If result is a Promise, apply-lift over completeValue.
if (isThenable(result)) {
return result.then(function (resolved) {
return completeValue(exeContext, returnType, fieldASTs, info, path, resolved);
return completeValue(exeContext, returnType, fieldNodes, info, path, resolved);
});

@@ -567,3 +567,3 @@ }

if (returnType instanceof _definition.GraphQLNonNull) {
var completed = completeValue(exeContext, returnType.ofType, fieldASTs, info, path, result);
var completed = completeValue(exeContext, returnType.ofType, fieldNodes, info, path, result);
if (completed === null) {

@@ -582,3 +582,3 @@ throw new Error('Cannot return null for non-nullable field ' + info.parentType.name + '.' + info.fieldName + '.');

if (returnType instanceof _definition.GraphQLList) {
return completeListValue(exeContext, returnType, fieldASTs, info, path, result);
return completeListValue(exeContext, returnType, fieldNodes, info, path, result);
}

@@ -595,3 +595,3 @@

if (returnType instanceof _definition.GraphQLInterfaceType || returnType instanceof _definition.GraphQLUnionType) {
return completeAbstractValue(exeContext, returnType, fieldASTs, info, path, result);
return completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result);
}

@@ -601,3 +601,3 @@

if (returnType instanceof _definition.GraphQLObjectType) {
return completeObjectValue(exeContext, returnType, fieldASTs, info, path, result);
return completeObjectValue(exeContext, returnType, fieldNodes, info, path, result);
}

@@ -613,3 +613,3 @@

*/
function completeListValue(exeContext, returnType, fieldASTs, info, path, result) {
function completeListValue(exeContext, returnType, fieldNodes, info, path, result) {
(0, _invariant2.default)((0, _iterall.isCollection)(result), 'Expected Iterable, but did not find one for field ' + info.parentType.name + '.' + info.fieldName + '.');

@@ -626,3 +626,3 @@

var fieldPath = path.concat([index]);
var completedItem = completeValueCatchingError(exeContext, itemType, fieldASTs, info, fieldPath, item);
var completedItem = completeValueCatchingError(exeContext, itemType, fieldNodes, info, fieldPath, item);

@@ -655,3 +655,3 @@ if (!containsPromise && isThenable(completedItem)) {

*/
function completeAbstractValue(exeContext, returnType, fieldASTs, info, path, result) {
function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result) {
var runtimeType = returnType.resolveType ? returnType.resolveType(result, exeContext.contextValue, info) : defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);

@@ -665,10 +665,10 @@

if (!(runtimeType instanceof _definition.GraphQLObjectType)) {
throw new _error.GraphQLError('Abstract type ' + returnType.name + ' must resolve to an Object type at ' + ('runtime for field ' + info.parentType.name + '.' + info.fieldName + ' with ') + ('value "' + String(result) + '", received "' + String(runtimeType) + '".'), fieldASTs);
throw new _error.GraphQLError('Abstract type ' + returnType.name + ' must resolve to an Object type at ' + ('runtime for field ' + info.parentType.name + '.' + info.fieldName + ' with ') + ('value "' + String(result) + '", received "' + String(runtimeType) + '".'), fieldNodes);
}
if (!exeContext.schema.isPossibleType(returnType, runtimeType)) {
throw new _error.GraphQLError('Runtime Object type "' + runtimeType.name + '" is not a possible type ' + ('for "' + returnType.name + '".'), fieldASTs);
throw new _error.GraphQLError('Runtime Object type "' + runtimeType.name + '" is not a possible type ' + ('for "' + returnType.name + '".'), fieldNodes);
}
return completeObjectValue(exeContext, runtimeType, fieldASTs, info, path, result);
return completeObjectValue(exeContext, runtimeType, fieldNodes, info, path, result);
}

@@ -679,3 +679,3 @@

*/
function completeObjectValue(exeContext, returnType, fieldASTs, info, path, result) {
function completeObjectValue(exeContext, returnType, fieldNodes, info, path, result) {
// If there is an isTypeOf predicate function, call it with the

@@ -685,16 +685,16 @@ // current result. If isTypeOf returns false, then raise an error rather

if (returnType.isTypeOf && !returnType.isTypeOf(result, exeContext.contextValue, info)) {
throw new _error.GraphQLError('Expected value of type "' + returnType.name + '" but got: ' + String(result) + '.', fieldASTs);
throw new _error.GraphQLError('Expected value of type "' + returnType.name + '" but got: ' + String(result) + '.', fieldNodes);
}
// Collect sub-fields to execute to complete this value.
var subFieldASTs = Object.create(null);
var subFieldNodes = Object.create(null);
var visitedFragmentNames = Object.create(null);
for (var i = 0; i < fieldASTs.length; i++) {
var selectionSet = fieldASTs[i].selectionSet;
for (var i = 0; i < fieldNodes.length; i++) {
var selectionSet = fieldNodes[i].selectionSet;
if (selectionSet) {
subFieldASTs = collectFields(exeContext, returnType, selectionSet, subFieldASTs, visitedFragmentNames);
subFieldNodes = collectFields(exeContext, returnType, selectionSet, subFieldNodes, visitedFragmentNames);
}
}
return executeFields(exeContext, returnType, result, path, subFieldASTs);
return executeFields(exeContext, returnType, result, path, subFieldNodes);
}

@@ -723,3 +723,3 @@

*/
function defaultResolveFn(source, args, context, _ref) {
var defaultFieldResolver = exports.defaultFieldResolver = function defaultFieldResolver(source, args, context, _ref) {
var fieldName = _ref.fieldName;

@@ -735,3 +735,3 @@

}
}
};

@@ -738,0 +738,0 @@ /**

@@ -14,2 +14,8 @@ 'use strict';

}
});
Object.defineProperty(exports, 'defaultFieldResolver', {
enumerable: true,
get: function get() {
return _execute.defaultFieldResolver;
}
});

@@ -21,2 +21,6 @@ 'use strict';

var _isInvalid = require('../jsutils/isInvalid');
var _isInvalid2 = _interopRequireDefault(_isInvalid);
var _keyMap = require('../jsutils/keyMap');

@@ -32,2 +36,8 @@

var _isValidLiteralValue = require('../utilities/isValidLiteralValue');
var _kinds = require('../language/kinds');
var Kind = _interopRequireWildcard(_kinds);
var _printer = require('../language/printer');

@@ -37,2 +47,4 @@

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; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -45,4 +57,43 @@

*/
function getVariableValues(schema, varDefNodes, inputs) {
var coercedValues = Object.create(null);
for (var i = 0; i < varDefNodes.length; i++) {
var varDefNode = varDefNodes[i];
var varName = varDefNode.variable.name.value;
var varType = (0, _typeFromAST.typeFromAST)(schema, varDefNode.type);
if (!(0, _definition.isInputType)(varType)) {
throw new _error.GraphQLError('Variable "$' + varName + '" expected value of type ' + ('"' + (0, _printer.print)(varDefNode.type) + '" which cannot be used as an input type.'), [varDefNode.type]);
}
varType = varType;
var value = inputs[varName];
if ((0, _isInvalid2.default)(value)) {
var defaultValue = varDefNode.defaultValue;
if (defaultValue) {
coercedValues[varName] = (0, _valueFromAST.valueFromAST)(defaultValue, varType);
}
if (varType instanceof _definition.GraphQLNonNull) {
throw new _error.GraphQLError('Variable "$' + varName + '" of required type ' + ('"' + String(varType) + '" was not provided.'), [varDefNode]);
}
} else {
var errors = (0, _isValidJSValue.isValidJSValue)(value, varType);
if (errors.length) {
var message = errors ? '\n' + errors.join('\n') : '';
throw new _error.GraphQLError('Variable "$' + varName + '" got invalid value ' + (JSON.stringify(value) + '.' + message), [varDefNode]);
}
var coercedValue = coerceValue(varType, value);
(0, _invariant2.default)(!(0, _isInvalid2.default)(coercedValue), 'Should have reported error.');
coercedValues[varName] = coercedValue;
}
}
return coercedValues;
}
/**
* Prepares an object map of argument values given a list of argument
* definitions and list of argument AST nodes.
*/
/**
* Copyright (c) 2015, Facebook, Inc.

@@ -56,61 +107,48 @@ * All rights reserved.

function getVariableValues(schema, definitionASTs, inputs) {
return definitionASTs.reduce(function (values, defAST) {
var varName = defAST.variable.name.value;
values[varName] = getVariableValue(schema, defAST, inputs[varName]);
return values;
}, {});
}
/**
* Prepares an object map of argument values given a list of argument
* definitions and list of argument AST nodes.
*/
function getArgumentValues(argDefs, argASTs, variableValues) {
if (!argDefs || !argASTs) {
function getArgumentValues(def, node, variableValues) {
var argDefs = def.args;
var argNodes = node.arguments;
if (!argDefs || !argNodes) {
return {};
}
var argASTMap = (0, _keyMap2.default)(argASTs, function (arg) {
var coercedValues = Object.create(null);
var argNodeMap = (0, _keyMap2.default)(argNodes, function (arg) {
return arg.name.value;
});
return argDefs.reduce(function (result, argDef) {
for (var i = 0; i < argDefs.length; i++) {
var argDef = argDefs[i];
var name = argDef.name;
var valueAST = argASTMap[name] ? argASTMap[name].value : null;
var value = (0, _valueFromAST.valueFromAST)(valueAST, argDef.type, variableValues);
if ((0, _isNullish2.default)(value)) {
value = argDef.defaultValue;
}
if (!(0, _isNullish2.default)(value)) {
result[name] = value;
}
return result;
}, {});
}
/**
* Given a variable definition, and any value of input, return a value which
* adheres to the variable definition, or throw an error.
*/
function getVariableValue(schema, definitionAST, input) {
var type = (0, _typeFromAST.typeFromAST)(schema, definitionAST.type);
var variable = definitionAST.variable;
if (!type || !(0, _definition.isInputType)(type)) {
throw new _error.GraphQLError('Variable "$' + variable.name.value + '" expected value of type ' + ('"' + (0, _printer.print)(definitionAST.type) + '" which cannot be used as an input type.'), [definitionAST]);
}
var inputType = type;
var errors = (0, _isValidJSValue.isValidJSValue)(input, inputType);
if (!errors.length) {
if ((0, _isNullish2.default)(input)) {
var defaultValue = definitionAST.defaultValue;
if (defaultValue) {
return (0, _valueFromAST.valueFromAST)(defaultValue, inputType);
var argType = argDef.type;
var argumentNode = argNodeMap[name];
var defaultValue = argDef.defaultValue;
if (!argumentNode) {
if (!(0, _isInvalid2.default)(defaultValue)) {
coercedValues[name] = defaultValue;
} else if (argType instanceof _definition.GraphQLNonNull) {
throw new _error.GraphQLError('Argument "' + name + '" of required type ' + ('"' + String(argType) + '" was not provided.'), [node]);
}
} else if (argumentNode.value.kind === Kind.VARIABLE) {
var variableName = argumentNode.value.name.value;
if (variableValues && !(0, _isInvalid2.default)(variableValues[variableName])) {
// Note: this does not check that this variable value is correct.
// This assumes that this query has been validated and the variable
// usage here is of the correct type.
coercedValues[name] = variableValues[variableName];
} else if (!(0, _isInvalid2.default)(defaultValue)) {
coercedValues[name] = defaultValue;
} else if (argType instanceof _definition.GraphQLNonNull) {
throw new _error.GraphQLError('Argument "' + name + '" of required type "' + String(argType) + '" was ' + ('provided the variable "$' + variableName + '" which was not provided ') + 'a runtime value.', [argumentNode.value]);
}
} else {
var valueNode = argumentNode.value;
var coercedValue = (0, _valueFromAST.valueFromAST)(valueNode, argType, variableValues);
if ((0, _isInvalid2.default)(coercedValue)) {
var errors = (0, _isValidLiteralValue.isValidLiteralValue)(argType, valueNode);
var message = errors ? '\n' + errors.join('\n') : '';
throw new _error.GraphQLError('Argument "' + name + '" got invalid value ' + (0, _printer.print)(valueNode) + '.' + message, [argumentNode.value]);
}
coercedValues[name] = coercedValue;
}
return coerceValue(inputType, input);
}
if ((0, _isNullish2.default)(input)) {
throw new _error.GraphQLError('Variable "$' + variable.name.value + '" of required type ' + ('"' + (0, _printer.print)(definitionAST.type) + '" was not provided.'), [definitionAST]);
}
var message = errors ? '\n' + errors.join('\n') : '';
throw new _error.GraphQLError('Variable "$' + variable.name.value + '" got invalid value ' + (JSON.stringify(input) + '.' + message), [definitionAST]);
return coercedValues;
}

@@ -125,9 +163,15 @@

if ((0, _isInvalid2.default)(_value)) {
return; // Intentionally return no value.
}
if (type instanceof _definition.GraphQLNonNull) {
// Note: we're not checking that the result of coerceValue is non-null.
// We only call this function after calling isValidJSValue.
if (_value === null) {
return; // Intentionally return no value.
}
return coerceValue(type.ofType, _value);
}
if ((0, _isNullish2.default)(_value)) {
if (_value === null) {
// Intentionally return the value null.
return null;

@@ -137,51 +181,51 @@ }

if (type instanceof _definition.GraphQLList) {
var _ret = function () {
var itemType = type.ofType;
if ((0, _iterall.isCollection)(_value)) {
var _ret2 = function () {
var coercedValues = [];
(0, _iterall.forEach)(_value, function (item) {
coercedValues.push(coerceValue(itemType, item));
});
return {
v: {
v: coercedValues
}
};
}();
if (typeof _ret2 === "object") return _ret2.v;
var itemType = type.ofType;
if ((0, _iterall.isCollection)(_value)) {
var coercedValues = [];
var valueIter = (0, _iterall.createIterator)(_value);
if (!valueIter) {
return; // Intentionally return no value.
}
return {
v: [coerceValue(itemType, _value)]
};
}();
if (typeof _ret === "object") return _ret.v;
var step = void 0;
while (!(step = valueIter.next()).done) {
var itemValue = coerceValue(itemType, step.value);
if ((0, _isInvalid2.default)(itemValue)) {
return; // Intentionally return no value.
}
coercedValues.push(itemValue);
}
return coercedValues;
}
var coercedValue = coerceValue(itemType, _value);
if ((0, _isInvalid2.default)(coercedValue)) {
return; // Intentionally return no value.
}
return [coerceValue(itemType, _value)];
}
if (type instanceof _definition.GraphQLInputObjectType) {
var _ret3 = function () {
if (typeof _value !== 'object' || _value === null) {
return {
v: null
};
if (typeof _value !== 'object') {
return; // Intentionally return no value.
}
var coercedObj = Object.create(null);
var fields = type.getFields();
var fieldNames = Object.keys(fields);
for (var i = 0; i < fieldNames.length; i++) {
var fieldName = fieldNames[i];
var field = fields[fieldName];
if ((0, _isInvalid2.default)(_value[fieldName])) {
if (!(0, _isInvalid2.default)(field.defaultValue)) {
coercedObj[fieldName] = field.defaultValue;
} else if (field.type instanceof _definition.GraphQLNonNull) {
return; // Intentionally return no value.
}
continue;
}
var fields = type.getFields();
return {
v: Object.keys(fields).reduce(function (obj, fieldName) {
var field = fields[fieldName];
var fieldValue = coerceValue(field.type, _value[fieldName]);
if ((0, _isNullish2.default)(fieldValue)) {
fieldValue = field.defaultValue;
}
if (!(0, _isNullish2.default)(fieldValue)) {
obj[fieldName] = fieldValue;
}
return obj;
}, {})
};
}();
if (typeof _ret3 === "object") return _ret3.v;
var fieldValue = coerceValue(field.type, _value[fieldName]);
if ((0, _isInvalid2.default)(fieldValue)) {
return; // Intentionally return no value.
}
coercedObj[fieldName] = fieldValue;
}
return coercedObj;
}

@@ -192,5 +236,9 @@

var parsed = type.parseValue(_value);
if (!(0, _isNullish2.default)(parsed)) {
return parsed;
if ((0, _isNullish2.default)(parsed)) {
// null or invalid values represent a failure to parse correctly,
// in which case no value is returned.
return;
}
return parsed;
}

@@ -63,9 +63,2 @@ 'use strict';

});
}
/**
* The result of a GraphQL parse, validation and execution.
*
* `data` is the result of a successful execution of the query.
* `errors` is included when any errors occurred as a non-empty array.
*/
}

@@ -348,2 +348,8 @@ 'use strict';

});
Object.defineProperty(exports, 'defaultFieldResolver', {
enumerable: true,
get: function get() {
return _execution.defaultFieldResolver;
}
});

@@ -350,0 +356,0 @@ var _validation = require('./validation');

@@ -42,2 +42,3 @@ 'use strict';

var BOOLEAN = exports.BOOLEAN = 'BooleanValue';
var NULL = exports.NULL = 'NullValue';
var ENUM = exports.ENUM = 'EnumValue';

@@ -44,0 +45,0 @@ var LIST = exports.LIST = 'ListValue';

@@ -404,3 +404,3 @@ 'use strict';

case 47:
value += '\/';break;
value += '/';break;
case 92:

@@ -407,0 +407,0 @@ value += '\\';break;

@@ -387,2 +387,3 @@ 'use strict';

* - BooleanValue
* - NullValue
* - EnumValue

@@ -394,2 +395,4 @@ * - ListValue[?Const]

*
* NullValue : `null`
*
* EnumValue : Name but not `true`, `false` or `null`

@@ -433,11 +436,15 @@ */

};
} else if (token.value !== 'null') {
} else if (token.value === 'null') {
lexer.advance();
return {
kind: _kinds.ENUM,
value: token.value,
kind: _kinds.NULL,
loc: loc(lexer, token)
};
}
break;
lexer.advance();
return {
kind: _kinds.ENUM,
value: token.value,
loc: loc(lexer, token)
};
case _lexer.TokenKind.DOLLAR:

@@ -444,0 +451,0 @@ if (!isConst) {

@@ -52,5 +52,5 @@ 'use strict';

VariableDefinition: function VariableDefinition(_ref) {
var variable = _ref.variable;
var type = _ref.type;
var defaultValue = _ref.defaultValue;
var variable = _ref.variable,
type = _ref.type,
defaultValue = _ref.defaultValue;
return variable + ': ' + type + wrap(' = ', defaultValue);

@@ -65,7 +65,7 @@ },

Field: function Field(_ref3) {
var alias = _ref3.alias;
var name = _ref3.name;
var args = _ref3.arguments;
var directives = _ref3.directives;
var selectionSet = _ref3.selectionSet;
var alias = _ref3.alias,
name = _ref3.name,
args = _ref3.arguments,
directives = _ref3.directives,
selectionSet = _ref3.selectionSet;
return join([wrap('', alias, ': ') + name + wrap('(', join(args, ', '), ')'), join(directives, ' '), selectionSet], ' ');

@@ -75,4 +75,4 @@ },

Argument: function Argument(_ref4) {
var name = _ref4.name;
var value = _ref4.value;
var name = _ref4.name,
value = _ref4.value;
return name + ': ' + value;

@@ -84,4 +84,4 @@ },

FragmentSpread: function FragmentSpread(_ref5) {
var name = _ref5.name;
var directives = _ref5.directives;
var name = _ref5.name,
directives = _ref5.directives;
return '...' + name + wrap(' ', join(directives, ' '));

@@ -91,5 +91,5 @@ },

InlineFragment: function InlineFragment(_ref6) {
var typeCondition = _ref6.typeCondition;
var directives = _ref6.directives;
var selectionSet = _ref6.selectionSet;
var typeCondition = _ref6.typeCondition,
directives = _ref6.directives,
selectionSet = _ref6.selectionSet;
return join(['...', wrap('on ', typeCondition), join(directives, ' '), selectionSet], ' ');

@@ -99,6 +99,6 @@ },

FragmentDefinition: function FragmentDefinition(_ref7) {
var name = _ref7.name;
var typeCondition = _ref7.typeCondition;
var directives = _ref7.directives;
var selectionSet = _ref7.selectionSet;
var name = _ref7.name,
typeCondition = _ref7.typeCondition,
directives = _ref7.directives,
selectionSet = _ref7.selectionSet;
return 'fragment ' + name + ' on ' + typeCondition + ' ' + wrap('', join(directives, ' '), ' ') + selectionSet;

@@ -125,2 +125,5 @@ },

},
NullValue: function NullValue() {
return 'null';
},
EnumValue: function EnumValue(_ref12) {

@@ -139,4 +142,4 @@ var value = _ref12.value;

ObjectField: function ObjectField(_ref15) {
var name = _ref15.name;
var value = _ref15.value;
var name = _ref15.name,
value = _ref15.value;
return name + ': ' + value;

@@ -148,4 +151,4 @@ },

Directive: function Directive(_ref16) {
var name = _ref16.name;
var args = _ref16.arguments;
var name = _ref16.name,
args = _ref16.arguments;
return '@' + name + wrap('(', join(args, ', '), ')');

@@ -172,4 +175,4 @@ },

SchemaDefinition: function SchemaDefinition(_ref20) {
var directives = _ref20.directives;
var operationTypes = _ref20.operationTypes;
var directives = _ref20.directives,
operationTypes = _ref20.operationTypes;
return join(['schema', join(directives, ' '), block(operationTypes)], ' ');

@@ -179,4 +182,4 @@ },

OperationTypeDefinition: function OperationTypeDefinition(_ref21) {
var operation = _ref21.operation;
var type = _ref21.type;
var operation = _ref21.operation,
type = _ref21.type;
return operation + ': ' + type;

@@ -186,4 +189,4 @@ },

ScalarTypeDefinition: function ScalarTypeDefinition(_ref22) {
var name = _ref22.name;
var directives = _ref22.directives;
var name = _ref22.name,
directives = _ref22.directives;
return join(['scalar', name, join(directives, ' ')], ' ');

@@ -193,6 +196,6 @@ },

ObjectTypeDefinition: function ObjectTypeDefinition(_ref23) {
var name = _ref23.name;
var interfaces = _ref23.interfaces;
var directives = _ref23.directives;
var fields = _ref23.fields;
var name = _ref23.name,
interfaces = _ref23.interfaces,
directives = _ref23.directives,
fields = _ref23.fields;
return join(['type', name, wrap('implements ', join(interfaces, ', ')), join(directives, ' '), block(fields)], ' ');

@@ -202,6 +205,6 @@ },

FieldDefinition: function FieldDefinition(_ref24) {
var name = _ref24.name;
var args = _ref24.arguments;
var type = _ref24.type;
var directives = _ref24.directives;
var name = _ref24.name,
args = _ref24.arguments,
type = _ref24.type,
directives = _ref24.directives;
return name + wrap('(', join(args, ', '), ')') + ': ' + type + wrap(' ', join(directives, ' '));

@@ -211,6 +214,6 @@ },

InputValueDefinition: function InputValueDefinition(_ref25) {
var name = _ref25.name;
var type = _ref25.type;
var defaultValue = _ref25.defaultValue;
var directives = _ref25.directives;
var name = _ref25.name,
type = _ref25.type,
defaultValue = _ref25.defaultValue,
directives = _ref25.directives;
return join([name + ': ' + type, wrap('= ', defaultValue), join(directives, ' ')], ' ');

@@ -220,5 +223,5 @@ },

InterfaceTypeDefinition: function InterfaceTypeDefinition(_ref26) {
var name = _ref26.name;
var directives = _ref26.directives;
var fields = _ref26.fields;
var name = _ref26.name,
directives = _ref26.directives,
fields = _ref26.fields;
return join(['interface', name, join(directives, ' '), block(fields)], ' ');

@@ -228,5 +231,5 @@ },

UnionTypeDefinition: function UnionTypeDefinition(_ref27) {
var name = _ref27.name;
var directives = _ref27.directives;
var types = _ref27.types;
var name = _ref27.name,
directives = _ref27.directives,
types = _ref27.types;
return join(['union', name, join(directives, ' '), '= ' + join(types, ' | ')], ' ');

@@ -236,5 +239,5 @@ },

EnumTypeDefinition: function EnumTypeDefinition(_ref28) {
var name = _ref28.name;
var directives = _ref28.directives;
var values = _ref28.values;
var name = _ref28.name,
directives = _ref28.directives,
values = _ref28.values;
return join(['enum', name, join(directives, ' '), block(values)], ' ');

@@ -244,4 +247,4 @@ },

EnumValueDefinition: function EnumValueDefinition(_ref29) {
var name = _ref29.name;
var directives = _ref29.directives;
var name = _ref29.name,
directives = _ref29.directives;
return join([name, join(directives, ' ')], ' ');

@@ -251,5 +254,5 @@ },

InputObjectTypeDefinition: function InputObjectTypeDefinition(_ref30) {
var name = _ref30.name;
var directives = _ref30.directives;
var fields = _ref30.fields;
var name = _ref30.name,
directives = _ref30.directives,
fields = _ref30.fields;
return join(['input', name, join(directives, ' '), block(fields)], ' ');

@@ -264,5 +267,5 @@ },

DirectiveDefinition: function DirectiveDefinition(_ref32) {
var name = _ref32.name;
var args = _ref32.arguments;
var locations = _ref32.locations;
var name = _ref32.name,
args = _ref32.arguments,
locations = _ref32.locations;
return 'directive @' + name + wrap('(', join(args, ', '), ')') + ' on ' + join(locations, ' | ');

@@ -269,0 +272,0 @@ }

@@ -37,2 +37,3 @@ 'use strict';

BooleanValue: [],
NullValue: [],
EnumValue: [],

@@ -39,0 +40,0 @@ ListValue: ['values'],

@@ -1,1 +0,1 @@

{"name":"graphql","version":"0.7.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.2"}}
{"name":"graphql","version":"0.8.0-beta1","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.2"}}

@@ -170,5 +170,5 @@ 'use strict';

GraphQLScalarType.prototype.parseLiteral = function parseLiteral(valueAST) {
GraphQLScalarType.prototype.parseLiteral = function parseLiteral(valueNode) {
var parser = this._scalarConfig.parseLiteral;
return parser ? parser(valueAST) : null;
return parser ? parser(valueNode) : null;
};

@@ -295,3 +295,3 @@

type: arg.type,
defaultValue: arg.defaultValue === undefined ? null : arg.defaultValue
defaultValue: arg.defaultValue
};

@@ -466,5 +466,5 @@ });

GraphQLEnumType.prototype.parseLiteral = function parseLiteral(valueAST) /* T */{
if (valueAST.kind === _kinds.ENUM) {
var enumValue = this._getNameLookup()[valueAST.value];
GraphQLEnumType.prototype.parseLiteral = function parseLiteral(valueNode) /* T */{
if (valueNode.kind === _kinds.ENUM) {
var enumValue = this._getNameLookup()[valueNode.value];
if (enumValue) {

@@ -471,0 +471,0 @@ return enumValue.value;

@@ -82,3 +82,3 @@ 'use strict';

type: arg.type,
defaultValue: arg.defaultValue === undefined ? null : arg.defaultValue
defaultValue: arg.defaultValue
};

@@ -85,0 +85,0 @@ });

@@ -427,3 +427,3 @@ 'use strict';

/**
* Note that these are GraphQLFieldDefinition and not GraphQLFieldConfig,
* Note that these are GraphQLField and not GraphQLFieldConfig,
* so the format for args is different.

@@ -430,0 +430,0 @@ */

@@ -42,3 +42,3 @@ 'use strict';

}
throw new TypeError('Int cannot represent non 32-bit signed integer value: ' + value);
throw new TypeError('Int cannot represent non 32-bit signed integer value: ' + String(value));
}

@@ -70,3 +70,3 @@

}
throw new TypeError('Float cannot represent non numeric value: ' + value);
throw new TypeError('Float cannot represent non numeric value: ' + String(value));
}

@@ -73,0 +73,0 @@

@@ -18,2 +18,6 @@ 'use strict';

var _isInvalid = require('../jsutils/isInvalid');
var _isInvalid2 = _interopRequireDefault(_isInvalid);
var _kinds = require('../language/kinds');

@@ -41,14 +45,5 @@

* | Mixed | Enum Value |
* | null | NullValue |
*
*/
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function astFromValue(value, type) {

@@ -59,8 +54,16 @@ // Ensure flow knows that we treat function params as const.

if (type instanceof _definition.GraphQLNonNull) {
// Note: we're not checking that the result is non-null.
// This function is not responsible for validating the input value.
return astFromValue(_value, type.ofType);
var astValue = astFromValue(_value, type.ofType);
if (astValue && astValue.kind === _kinds.NULL) {
return null;
}
return astValue;
}
if ((0, _isNullish2.default)(_value)) {
// only explicit null, not undefined, NaN
if (_value === null) {
return { kind: _kinds.NULL };
}
// undefined, NaN
if ((0, _isInvalid2.default)(_value)) {
return null;

@@ -76,7 +79,7 @@ }

var _ret2 = function () {
var valuesASTs = [];
var valuesNodes = [];
(0, _iterall.forEach)(_value, function (item) {
var itemAST = astFromValue(item, itemType);
if (itemAST) {
valuesASTs.push(itemAST);
var itemNode = astFromValue(item, itemType);
if (itemNode) {
valuesNodes.push(itemNode);
}

@@ -86,3 +89,3 @@ });

v: {
v: { kind: _kinds.LIST, values: valuesASTs }
v: { kind: _kinds.LIST, values: valuesNodes }
}

@@ -112,3 +115,3 @@ };

var fields = type.getFields();
var fieldASTs = [];
var fieldNodes = [];
Object.keys(fields).forEach(function (fieldName) {

@@ -118,3 +121,3 @@ var fieldType = fields[fieldName].type;

if (fieldValue) {
fieldASTs.push({
fieldNodes.push({
kind: _kinds.OBJECT_FIELD,

@@ -127,3 +130,3 @@ name: { kind: _kinds.NAME, value: fieldName },

return {
v: { kind: _kinds.OBJECT, fields: fieldASTs }
v: { kind: _kinds.OBJECT, fields: fieldNodes }
};

@@ -176,2 +179,10 @@ }();

throw new TypeError('Cannot convert value to AST: ' + String(serialized));
}
}
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

@@ -44,8 +44,8 @@ 'use strict';

function buildWrappedType(innerType, inputTypeAST) {
if (inputTypeAST.kind === _kinds.LIST_TYPE) {
return new _definition.GraphQLList(buildWrappedType(innerType, inputTypeAST.type));
function buildWrappedType(innerType, inputTypeNode) {
if (inputTypeNode.kind === _kinds.LIST_TYPE) {
return new _definition.GraphQLList(buildWrappedType(innerType, inputTypeNode.type));
}
if (inputTypeAST.kind === _kinds.NON_NULL_TYPE) {
var wrappedType = buildWrappedType(innerType, inputTypeAST.type);
if (inputTypeNode.kind === _kinds.NON_NULL_TYPE) {
var wrappedType = buildWrappedType(innerType, inputTypeNode.type);
(0, _invariant2.default)(!(wrappedType instanceof _definition.GraphQLNonNull), 'No nesting nonnull.');

@@ -65,4 +65,4 @@ return new _definition.GraphQLNonNull(wrappedType);

function getNamedTypeAST(typeAST) {
var namedType = typeAST;
function getNamedTypeNode(typeNode) {
var namedType = typeNode;
while (namedType.kind === _kinds.LIST_TYPE || namedType.kind === _kinds.NON_NULL_TYPE) {

@@ -92,3 +92,3 @@ namedType = namedType.type;

var typeDefs = [];
var astMap = Object.create(null);
var nodeMap = Object.create(null);
var directiveDefs = [];

@@ -111,3 +111,3 @@ for (var i = 0; i < ast.definitions.length; i++) {

typeDefs.push(d);
astMap[d.name.value] = d;
nodeMap[d.name.value] = d;
break;

@@ -130,3 +130,3 @@ case _kinds.DIRECTIVE_DEFINITION:

}
if (!astMap[typeName]) {
if (!nodeMap[typeName]) {
throw new Error('Specified query type "' + typeName + '" not found in document.');

@@ -139,3 +139,3 @@ }

}
if (!astMap[typeName]) {
if (!nodeMap[typeName]) {
throw new Error('Specified mutation type "' + typeName + '" not found in document.');

@@ -148,3 +148,3 @@ }

}
if (!astMap[typeName]) {
if (!nodeMap[typeName]) {
throw new Error('Specified subscription type "' + typeName + '" not found in document.');

@@ -156,9 +156,9 @@ }

} else {
if (astMap.Query) {
if (nodeMap.Query) {
queryTypeName = 'Query';
}
if (astMap.Mutation) {
if (nodeMap.Mutation) {
mutationTypeName = 'Mutation';
}
if (astMap.Subscription) {
if (nodeMap.Subscription) {
subscriptionTypeName = 'Subscription';

@@ -214,5 +214,5 @@ }

return new _schema.GraphQLSchema({
query: getObjectType(astMap[queryTypeName]),
mutation: mutationTypeName ? getObjectType(astMap[mutationTypeName]) : null,
subscription: subscriptionTypeName ? getObjectType(astMap[subscriptionTypeName]) : null,
query: getObjectType(nodeMap[queryTypeName]),
mutation: mutationTypeName ? getObjectType(nodeMap[mutationTypeName]) : null,
subscription: subscriptionTypeName ? getObjectType(nodeMap[subscriptionTypeName]) : null,
types: types,

@@ -222,15 +222,15 @@ directives: directives

function getDirective(directiveAST) {
function getDirective(directiveNode) {
return new _directives.GraphQLDirective({
name: directiveAST.name.value,
description: getDescription(directiveAST),
locations: directiveAST.locations.map(function (node) {
name: directiveNode.name.value,
description: getDescription(directiveNode),
locations: directiveNode.locations.map(function (node) {
return node.value;
}),
args: directiveAST.arguments && makeInputValues(directiveAST.arguments)
args: directiveNode.arguments && makeInputValues(directiveNode.arguments)
});
}
function getObjectType(typeAST) {
var type = typeDefNamed(typeAST.name.value);
function getObjectType(typeNode) {
var type = typeDefNamed(typeNode.name.value);
(0, _invariant2.default)(type instanceof _definition.GraphQLObjectType, 'AST must provide object type.');

@@ -240,10 +240,10 @@ return type;

function produceType(typeAST) {
var typeName = getNamedTypeAST(typeAST).name.value;
function produceType(typeNode) {
var typeName = getNamedTypeNode(typeNode).name.value;
var typeDef = typeDefNamed(typeName);
return buildWrappedType(typeDef, typeAST);
return buildWrappedType(typeDef, typeNode);
}
function produceInputType(typeAST) {
var type = produceType(typeAST);
function produceInputType(typeNode) {
var type = produceType(typeNode);
(0, _invariant2.default)((0, _definition.isInputType)(type), 'Expected Input type.');

@@ -253,4 +253,4 @@ return type;

function produceOutputType(typeAST) {
var type = produceType(typeAST);
function produceOutputType(typeNode) {
var type = produceType(typeNode);
(0, _invariant2.default)((0, _definition.isOutputType)(type), 'Expected Output type.');

@@ -260,4 +260,4 @@ return type;

function produceObjectType(typeAST) {
var type = produceType(typeAST);
function produceObjectType(typeNode) {
var type = produceType(typeNode);
(0, _invariant2.default)(type instanceof _definition.GraphQLObjectType, 'Expected Object type.');

@@ -267,4 +267,4 @@ return type;

function produceInterfaceType(typeAST) {
var type = produceType(typeAST);
function produceInterfaceType(typeNode) {
var type = produceType(typeNode);
(0, _invariant2.default)(type instanceof _definition.GraphQLInterfaceType, 'Expected Object type.');

@@ -279,7 +279,7 @@ return type;

if (!astMap[typeName]) {
if (!nodeMap[typeName]) {
throw new Error('Type "' + typeName + '" not found in document.');
}
var innerTypeDef = makeSchemaDef(astMap[typeName]);
var innerTypeDef = makeSchemaDef(nodeMap[typeName]);
if (!innerTypeDef) {

@@ -439,6 +439,5 @@ throw new Error('Nothing constructed for "' + typeName + '".');

var _getArgumentValues = (0, _values.getArgumentValues)(_directives.GraphQLDeprecatedDirective.args, deprecatedAST.arguments);
var _getArgumentValues = (0, _values.getArgumentValues)(_directives.GraphQLDeprecatedDirective, deprecatedAST),
reason = _getArgumentValues.reason;
var reason = _getArgumentValues.reason;
return reason;

@@ -445,0 +444,0 @@ }

@@ -185,4 +185,4 @@ 'use strict';

var newDirectives = directiveDefinitions.map(function (directiveAST) {
return getDirective(directiveAST);
var newDirectives = directiveDefinitions.map(function (directiveNode) {
return getDirective(directiveNode);
});

@@ -198,6 +198,6 @@ return existingDirectives.concat(newDirectives);

function getTypeFromAST(astNode) {
var type = _getNamedType(astNode.name.value);
function getTypeFromAST(node) {
var type = _getNamedType(node.name.value);
if (!type) {
throw new _GraphQLError.GraphQLError('Unknown type: "' + astNode.name.value + '". Ensure that this type exists ' + 'either in the original schema, or is added in a type definition.', [astNode]);
throw new _GraphQLError.GraphQLError('Unknown type: "' + node.name.value + '". Ensure that this type exists ' + 'either in the original schema, or is added in a type definition.', [node]);
}

@@ -207,4 +207,4 @@ return type;

function getObjectTypeFromAST(astNode) {
var type = getTypeFromAST(astNode);
function getObjectTypeFromAST(node) {
var type = getTypeFromAST(node);
(0, _invariant2.default)(type instanceof _definition.GraphQLObjectType, 'Must be Object type.');

@@ -214,4 +214,4 @@ return type;

function getInterfaceTypeFromAST(astNode) {
var type = getTypeFromAST(astNode);
function getInterfaceTypeFromAST(node) {
var type = getTypeFromAST(node);
(0, _invariant2.default)(type instanceof _definition.GraphQLInterfaceType, 'Must be Interface type.');

@@ -221,4 +221,4 @@ return type;

function getInputTypeFromAST(astNode) {
var type = getTypeFromAST(astNode);
function getInputTypeFromAST(node) {
var type = getTypeFromAST(node);
(0, _invariant2.default)((0, _definition.isInputType)(type), 'Must be Input type.');

@@ -228,4 +228,4 @@ return type;

function getOutputTypeFromAST(astNode) {
var type = getTypeFromAST(astNode);
function getOutputTypeFromAST(node) {
var type = getTypeFromAST(node);
(0, _invariant2.default)((0, _definition.isOutputType)(type), 'Must be Output type.');

@@ -250,5 +250,5 @@ return type;

var typeAST = typeDefinitionMap[typeName];
if (typeAST) {
var _typeDef = buildType(typeAST);
var typeNode = typeDefinitionMap[typeName];
if (typeNode) {
var _typeDef = buildType(typeNode);
typeDefCache[typeName] = _typeDef;

@@ -377,29 +377,29 @@ return _typeDef;

function buildType(typeAST) {
switch (typeAST.kind) {
function buildType(typeNode) {
switch (typeNode.kind) {
case _kinds.OBJECT_TYPE_DEFINITION:
return buildObjectType(typeAST);
return buildObjectType(typeNode);
case _kinds.INTERFACE_TYPE_DEFINITION:
return buildInterfaceType(typeAST);
return buildInterfaceType(typeNode);
case _kinds.UNION_TYPE_DEFINITION:
return buildUnionType(typeAST);
return buildUnionType(typeNode);
case _kinds.SCALAR_TYPE_DEFINITION:
return buildScalarType(typeAST);
return buildScalarType(typeNode);
case _kinds.ENUM_TYPE_DEFINITION:
return buildEnumType(typeAST);
return buildEnumType(typeNode);
case _kinds.INPUT_OBJECT_TYPE_DEFINITION:
return buildInputObjectType(typeAST);
return buildInputObjectType(typeNode);
}
throw new TypeError('Unknown type kind ' + typeAST.kind);
throw new TypeError('Unknown type kind ' + typeNode.kind);
}
function buildObjectType(typeAST) {
function buildObjectType(typeNode) {
return new _definition.GraphQLObjectType({
name: typeAST.name.value,
description: (0, _buildASTSchema.getDescription)(typeAST),
name: typeNode.name.value,
description: (0, _buildASTSchema.getDescription)(typeNode),
interfaces: function interfaces() {
return buildImplementedInterfaces(typeAST);
return buildImplementedInterfaces(typeNode);
},
fields: function fields() {
return buildFieldMap(typeAST);
return buildFieldMap(typeNode);
}

@@ -409,8 +409,8 @@ });

function buildInterfaceType(typeAST) {
function buildInterfaceType(typeNode) {
return new _definition.GraphQLInterfaceType({
name: typeAST.name.value,
description: (0, _buildASTSchema.getDescription)(typeAST),
name: typeNode.name.value,
description: (0, _buildASTSchema.getDescription)(typeNode),
fields: function fields() {
return buildFieldMap(typeAST);
return buildFieldMap(typeNode);
},

@@ -421,7 +421,7 @@ resolveType: cannotExecuteExtendedSchema

function buildUnionType(typeAST) {
function buildUnionType(typeNode) {
return new _definition.GraphQLUnionType({
name: typeAST.name.value,
description: (0, _buildASTSchema.getDescription)(typeAST),
types: typeAST.types.map(getObjectTypeFromAST),
name: typeNode.name.value,
description: (0, _buildASTSchema.getDescription)(typeNode),
types: typeNode.types.map(getObjectTypeFromAST),
resolveType: cannotExecuteExtendedSchema

@@ -431,6 +431,6 @@ });

function buildScalarType(typeAST) {
function buildScalarType(typeNode) {
return new _definition.GraphQLScalarType({
name: typeAST.name.value,
description: (0, _buildASTSchema.getDescription)(typeAST),
name: typeNode.name.value,
description: (0, _buildASTSchema.getDescription)(typeNode),
serialize: function serialize(id) {

@@ -452,7 +452,7 @@ return id;

function buildEnumType(typeAST) {
function buildEnumType(typeNode) {
return new _definition.GraphQLEnumType({
name: typeAST.name.value,
description: (0, _buildASTSchema.getDescription)(typeAST),
values: (0, _keyValMap2.default)(typeAST.values, function (v) {
name: typeNode.name.value,
description: (0, _buildASTSchema.getDescription)(typeNode),
values: (0, _keyValMap2.default)(typeNode.values, function (v) {
return v.name.value;

@@ -465,8 +465,8 @@ }, function () {

function buildInputObjectType(typeAST) {
function buildInputObjectType(typeNode) {
return new _definition.GraphQLInputObjectType({
name: typeAST.name.value,
description: (0, _buildASTSchema.getDescription)(typeAST),
name: typeNode.name.value,
description: (0, _buildASTSchema.getDescription)(typeNode),
fields: function fields() {
return buildInputValues(typeAST.fields);
return buildInputValues(typeNode.fields);
}

@@ -476,18 +476,18 @@ });

function getDirective(directiveAST) {
function getDirective(directiveNode) {
return new _directives.GraphQLDirective({
name: directiveAST.name.value,
locations: directiveAST.locations.map(function (node) {
name: directiveNode.name.value,
locations: directiveNode.locations.map(function (node) {
return node.value;
}),
args: directiveAST.arguments && buildInputValues(directiveAST.arguments)
args: directiveNode.arguments && buildInputValues(directiveNode.arguments)
});
}
function buildImplementedInterfaces(typeAST) {
return typeAST.interfaces && typeAST.interfaces.map(getInterfaceTypeFromAST);
function buildImplementedInterfaces(typeNode) {
return typeNode.interfaces && typeNode.interfaces.map(getInterfaceTypeFromAST);
}
function buildFieldMap(typeAST) {
return (0, _keyValMap2.default)(typeAST.fields, function (field) {
function buildFieldMap(typeNode) {
return (0, _keyValMap2.default)(typeNode.fields, function (field) {
return field.name.value;

@@ -516,24 +516,24 @@ }, function (field) {

function buildInputFieldType(typeAST) {
if (typeAST.kind === _kinds.LIST_TYPE) {
return new _definition.GraphQLList(buildInputFieldType(typeAST.type));
function buildInputFieldType(typeNode) {
if (typeNode.kind === _kinds.LIST_TYPE) {
return new _definition.GraphQLList(buildInputFieldType(typeNode.type));
}
if (typeAST.kind === _kinds.NON_NULL_TYPE) {
var nullableType = buildInputFieldType(typeAST.type);
if (typeNode.kind === _kinds.NON_NULL_TYPE) {
var nullableType = buildInputFieldType(typeNode.type);
(0, _invariant2.default)(!(nullableType instanceof _definition.GraphQLNonNull), 'Must be nullable');
return new _definition.GraphQLNonNull(nullableType);
}
return getInputTypeFromAST(typeAST);
return getInputTypeFromAST(typeNode);
}
function buildOutputFieldType(typeAST) {
if (typeAST.kind === _kinds.LIST_TYPE) {
return new _definition.GraphQLList(buildOutputFieldType(typeAST.type));
function buildOutputFieldType(typeNode) {
if (typeNode.kind === _kinds.LIST_TYPE) {
return new _definition.GraphQLList(buildOutputFieldType(typeNode.type));
}
if (typeAST.kind === _kinds.NON_NULL_TYPE) {
var nullableType = buildOutputFieldType(typeAST.type);
if (typeNode.kind === _kinds.NON_NULL_TYPE) {
var nullableType = buildOutputFieldType(typeNode.type);
(0, _invariant2.default)(!(nullableType instanceof _definition.GraphQLNonNull), 'Must be nullable');
return new _definition.GraphQLNonNull(nullableType);
}
return getOutputTypeFromAST(typeAST);
return getOutputTypeFromAST(typeNode);
}

@@ -540,0 +540,0 @@ }

@@ -41,6 +41,3 @@ 'use strict';

if ((0, _isNullish2.default)(value)) {
if (type.ofType.name) {
return ['Expected "' + String(type.ofType.name) + '!", found null.'];
}
return ['Expected non-null value, found null.'];
return ['Expected "' + String(type) + '", found null.'];
}

@@ -47,0 +44,0 @@ return isValidJSValue(value, type.ofType);

@@ -29,4 +29,4 @@ 'use strict';

/**
* Utility for validators which determines if a value literal AST is valid given
* an input type.
* Utility for validators which determines if a value literal node is valid
* given an input type.
*

@@ -46,15 +46,12 @@ * Note that this only validates literal values, variables are assumed to

function isValidLiteralValue(type, valueAST) {
function isValidLiteralValue(type, valueNode) {
// A value must be provided if the type is non-null.
if (type instanceof _definition.GraphQLNonNull) {
if (!valueAST) {
if (type.ofType.name) {
return ['Expected "' + String(type.ofType.name) + '!", found null.'];
}
return ['Expected non-null value, found null.'];
if (!valueNode || valueNode.kind === _kinds.NULL) {
return ['Expected "' + String(type) + '", found null.'];
}
return isValidLiteralValue(type.ofType, valueAST);
return isValidLiteralValue(type.ofType, valueNode);
}
if (!valueAST) {
if (!valueNode || valueNode.kind === _kinds.NULL) {
return [];

@@ -65,3 +62,3 @@ }

// values of the correct type.
if (valueAST.kind === _kinds.VARIABLE) {
if (valueNode.kind === _kinds.VARIABLE) {
return [];

@@ -74,6 +71,6 @@ }

var itemType = type.ofType;
if (valueAST.kind === _kinds.LIST) {
if (valueNode.kind === _kinds.LIST) {
return {
v: valueAST.values.reduce(function (acc, itemAST, index) {
var errors = isValidLiteralValue(itemType, itemAST);
v: valueNode.values.reduce(function (acc, item, index) {
var errors = isValidLiteralValue(itemType, item);
return acc.concat(errors.map(function (error) {

@@ -86,3 +83,3 @@ return 'In element #' + index + ': ' + error;

return {
v: isValidLiteralValue(itemType, valueAST)
v: isValidLiteralValue(itemType, valueNode)
};

@@ -97,3 +94,3 @@ }();

var _ret2 = function () {
if (valueAST.kind !== _kinds.OBJECT) {
if (valueNode.kind !== _kinds.OBJECT) {
return {

@@ -108,6 +105,6 @@ v: ['Expected "' + type.name + '", found not an object.']

// Ensure every provided field is defined.
var fieldASTs = valueAST.fields;
fieldASTs.forEach(function (providedFieldAST) {
if (!fields[providedFieldAST.name.value]) {
errors.push('In field "' + providedFieldAST.name.value + '": Unknown field.');
var fieldNodes = valueNode.fields;
fieldNodes.forEach(function (providedFieldNode) {
if (!fields[providedFieldNode.name.value]) {
errors.push('In field "' + providedFieldNode.name.value + '": Unknown field.');
}

@@ -117,7 +114,7 @@ });

// Ensure every defined field is valid.
var fieldASTMap = (0, _keyMap2.default)(fieldASTs, function (fieldAST) {
return fieldAST.name.value;
var fieldNodeMap = (0, _keyMap2.default)(fieldNodes, function (fieldNode) {
return fieldNode.name.value;
});
Object.keys(fields).forEach(function (fieldName) {
var result = isValidLiteralValue(fields[fieldName].type, fieldASTMap[fieldName] && fieldASTMap[fieldName].value);
var result = isValidLiteralValue(fields[fieldName].type, fieldNodeMap[fieldName] && fieldNodeMap[fieldName].value);
errors.push.apply(errors, result.map(function (error) {

@@ -140,5 +137,5 @@ return 'In field "' + fieldName + '": ' + error;

// a non-null value.
var parseResult = type.parseLiteral(valueAST);
var parseResult = type.parseLiteral(valueNode);
if ((0, _isNullish2.default)(parseResult)) {
return ['Expected type "' + type.name + '", found ' + (0, _printer.print)(valueAST) + '.'];
return ['Expected type "' + type.name + '", found ' + (0, _printer.print)(valueNode) + '.'];
}

@@ -145,0 +142,0 @@

@@ -17,2 +17,6 @@ 'use strict';

var _isInvalid = require('../jsutils/isInvalid');
var _isInvalid2 = _interopRequireDefault(_isInvalid);
var _astFromValue = require('../utilities/astFromValue');

@@ -30,7 +34,2 @@

function printSchema(schema) {
return printFilteredSchema(schema, function (n) {
return !isSpecDirective(n);
}, isDefinedType);
}
/**

@@ -45,2 +44,8 @@ * Copyright (c) 2015, Facebook, Inc.

function printSchema(schema) {
return printFilteredSchema(schema, function (n) {
return !isSpecDirective(n);
}, isDefinedType);
}
function printIntrospectionSchema(schema) {

@@ -203,3 +208,3 @@ return printFilteredSchema(schema, isSpecDirective, isIntrospectionType);

function printArgs(args) {
var indentation = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
var indentation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

@@ -224,3 +229,3 @@ if (args.length === 0) {

var argDecl = arg.name + ': ' + String(arg.type);
if (!(0, _isNullish2.default)(arg.defaultValue)) {
if (!(0, _isInvalid2.default)(arg.defaultValue)) {
argDecl += ' = ' + (0, _printer.print)((0, _astFromValue.astFromValue)(arg.defaultValue, arg.type));

@@ -247,4 +252,4 @@ }

function printDescription(def) {
var indentation = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
var firstInBlock = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2];
var indentation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var firstInBlock = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;

@@ -251,0 +256,0 @@ if (!def.description) {

@@ -18,14 +18,14 @@ 'use strict';

function typeFromAST(schema, inputTypeAST) {
function typeFromAST(schema, typeNode) {
var innerType = void 0;
if (inputTypeAST.kind === _kinds.LIST_TYPE) {
innerType = typeFromAST(schema, inputTypeAST.type);
if (typeNode.kind === _kinds.LIST_TYPE) {
innerType = typeFromAST(schema, typeNode.type);
return innerType && new _definition.GraphQLList(innerType);
}
if (inputTypeAST.kind === _kinds.NON_NULL_TYPE) {
innerType = typeFromAST(schema, inputTypeAST.type);
if (typeNode.kind === _kinds.NON_NULL_TYPE) {
innerType = typeFromAST(schema, typeNode.type);
return innerType && new _definition.GraphQLNonNull(innerType);
}
(0, _invariant2.default)(inputTypeAST.kind === _kinds.NAMED_TYPE, 'Must be a named type.');
return schema.getType(inputTypeAST.name.value);
(0, _invariant2.default)(typeNode.kind === _kinds.NAMED_TYPE, 'Must be a named type.');
return schema.getType(typeNode.name.value);
}

@@ -32,0 +32,0 @@ /**

@@ -93,3 +93,3 @@ 'use strict';

TypeInfo.prototype.enter = function enter(node /* Node */) {
TypeInfo.prototype.enter = function enter(node /* ASTNode */) {
var schema = this._schema;

@@ -211,4 +211,4 @@ switch (node.kind) {

function getFieldDef(schema, parentType, fieldAST) {
var name = fieldAST.name.value;
function getFieldDef(schema, parentType, fieldNode) {
var name = fieldNode.name.value;
if (name === _introspection.SchemaMetaFieldDef.name && schema.getQueryType() === parentType) {

@@ -215,0 +215,0 @@ return _introspection.SchemaMetaFieldDef;

@@ -20,2 +20,6 @@ 'use strict';

var _isInvalid = require('../jsutils/isInvalid');
var _isInvalid2 = _interopRequireDefault(_isInvalid);
var _kinds = require('../language/kinds');

@@ -37,2 +41,5 @@

*
* Returns `undefined` when the value could not be validly coerced according to
* the provided type.
*
* | GraphQL Value | JSON Value |

@@ -46,20 +53,39 @@ * | -------------------- | ------------- |

* | Enum Value | Mixed |
* | NullValue | null |
*
*/
function valueFromAST(valueAST, type, variables) {
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function valueFromAST(valueNode, type, variables) {
if (!valueNode) {
// When there is no node, then there is also no value.
// Importantly, this is different from returning the value null.
return;
}
if (type instanceof _definition.GraphQLNonNull) {
// Note: we're not checking that the result of valueFromAST is non-null.
// We're assuming that this query has been validated and the value used
// here is of the correct type.
return valueFromAST(valueAST, type.ofType, variables);
if (valueNode.kind === Kind.NULL) {
return; // Invalid: intentionally return no value.
}
return valueFromAST(valueNode, type.ofType, variables);
}
if (!valueAST) {
if (valueNode.kind === Kind.NULL) {
// This is explicitly returning the value null.
return null;
}
if (valueAST.kind === Kind.VARIABLE) {
var variableName = valueAST.name.value;
if (!variables || !variables.hasOwnProperty(variableName)) {
return null;
if (valueNode.kind === Kind.VARIABLE) {
var variableName = valueNode.name.value;
if (!variables || (0, _isInvalid2.default)(variables[variableName])) {
// No valid return value.
return;
}

@@ -73,47 +99,60 @@ // Note: we're not doing any checking that this variable is correct. We're

if (type instanceof _definition.GraphQLList) {
var _ret = function () {
var itemType = type.ofType;
if (valueAST.kind === Kind.LIST) {
return {
v: valueAST.values.map(function (itemAST) {
return valueFromAST(itemAST, itemType, variables);
})
};
var itemType = type.ofType;
if (valueNode.kind === Kind.LIST) {
var coercedValues = [];
var itemNodes = valueNode.values;
for (var i = 0; i < itemNodes.length; i++) {
if (isMissingVariable(itemNodes[i], variables)) {
// If an array contains a missing variable, it is either coerced to
// null or if the item type is non-null, it considered invalid.
if (itemType instanceof _definition.GraphQLNonNull) {
return; // Invalid: intentionally return no value.
}
coercedValues.push(null);
} else {
var itemValue = valueFromAST(itemNodes[i], itemType, variables);
if ((0, _isInvalid2.default)(itemValue)) {
return; // Invalid: intentionally return no value.
}
coercedValues.push(itemValue);
}
}
return {
v: [valueFromAST(valueAST, itemType, variables)]
};
}();
if (typeof _ret === "object") return _ret.v;
return coercedValues;
}
var coercedValue = valueFromAST(valueNode, itemType, variables);
if ((0, _isInvalid2.default)(coercedValue)) {
return; // Invalid: intentionally return no value.
}
return [coercedValue];
}
if (type instanceof _definition.GraphQLInputObjectType) {
var _ret2 = function () {
if (valueAST.kind !== Kind.OBJECT) {
return {
v: null
};
if (valueNode.kind !== Kind.OBJECT) {
return; // Invalid: intentionally return no value.
}
var coercedObj = Object.create(null);
var fields = type.getFields();
var fieldNodes = (0, _keyMap2.default)(valueNode.fields, function (field) {
return field.name.value;
});
var fieldNames = Object.keys(fields);
for (var _i = 0; _i < fieldNames.length; _i++) {
var fieldName = fieldNames[_i];
var field = fields[fieldName];
var fieldNode = fieldNodes[fieldName];
if (!fieldNode || isMissingVariable(fieldNode.value, variables)) {
if (!(0, _isInvalid2.default)(field.defaultValue)) {
coercedObj[fieldName] = field.defaultValue;
} else if (field.type instanceof _definition.GraphQLNonNull) {
return; // Invalid: intentionally return no value.
}
continue;
}
var fields = type.getFields();
var fieldASTs = (0, _keyMap2.default)(valueAST.fields, function (field) {
return field.name.value;
});
return {
v: Object.keys(fields).reduce(function (obj, fieldName) {
var field = fields[fieldName];
var fieldAST = fieldASTs[fieldName];
var fieldValue = valueFromAST(fieldAST && fieldAST.value, field.type, variables);
if ((0, _isNullish2.default)(fieldValue)) {
fieldValue = field.defaultValue;
}
if (!(0, _isNullish2.default)(fieldValue)) {
obj[fieldName] = fieldValue;
}
return obj;
}, {})
};
}();
if (typeof _ret2 === "object") return _ret2.v;
var fieldValue = valueFromAST(fieldNode.value, field.type, variables);
if ((0, _isInvalid2.default)(fieldValue)) {
return; // Invalid: intentionally return no value.
}
coercedObj[fieldName] = fieldValue;
}
return coercedObj;
}

@@ -123,14 +162,16 @@

var parsed = type.parseLiteral(valueAST);
if (!(0, _isNullish2.default)(parsed)) {
return parsed;
var parsed = type.parseLiteral(valueNode);
if ((0, _isNullish2.default)(parsed)) {
// null or invalid values represent a failure to parse correctly,
// in which case no value is returned.
return;
}
return parsed;
}
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// Returns true if the provided valueNode is a variable which is not defined
// in the set of variables.
function isMissingVariable(valueNode, variables) {
return valueNode.kind === Kind.VARIABLE && (!variables || (0, _isInvalid2.default)(variables[valueNode.name.value]));
}

@@ -37,8 +37,8 @@ 'use strict';

return {
Argument: function Argument(argAST) {
Argument: function Argument(node) {
var argDef = context.getArgument();
if (argDef) {
var errors = (0, _isValidLiteralValue.isValidLiteralValue)(argDef.type, argAST.value);
var errors = (0, _isValidLiteralValue.isValidLiteralValue)(argDef.type, node.value);
if (errors && errors.length > 0) {
context.reportError(new _error.GraphQLError(badValueMessage(argAST.name.value, argDef.type, (0, _printer.print)(argAST.value), errors), [argAST.value]));
context.reportError(new _error.GraphQLError(badValueMessage(node.name.value, argDef.type, (0, _printer.print)(node.value), errors), [node.value]));
}

@@ -45,0 +45,0 @@ }

@@ -43,5 +43,5 @@ 'use strict';

return {
VariableDefinition: function VariableDefinition(varDefAST) {
var name = varDefAST.variable.name.value;
var defaultValue = varDefAST.defaultValue;
VariableDefinition: function VariableDefinition(node) {
var name = node.variable.name.value;
var defaultValue = node.defaultValue;
var type = context.getInputType();

@@ -48,0 +48,0 @@ if (type instanceof _definition.GraphQLNonNull && defaultValue) {

@@ -51,6 +51,6 @@ 'use strict';

},
VariableDefinition: function VariableDefinition(varDefAST) {
variableNameDefined[varDefAST.variable.name.value] = true;
VariableDefinition: function VariableDefinition(node) {
variableNameDefined[node.variable.name.value] = true;
}
};
}

@@ -42,4 +42,4 @@ 'use strict';

return reason.map(function (_ref) {
var responseName = _ref[0];
var subreason = _ref[1];
var responseName = _ref[0],
subreason = _ref[1];
return 'subfields "' + responseName + '" conflict because ' + reasonMessage(subreason);

@@ -73,7 +73,7 @@ }).join(' and ');

conflicts.forEach(function (_ref2) {
var _ref2$ = _ref2[0];
var responseName = _ref2$[0];
var reason = _ref2$[1];
var fields1 = _ref2[1];
var fields2 = _ref2[2];
var _ref2$ = _ref2[0],
responseName = _ref2$[0],
reason = _ref2$[1],
fields1 = _ref2[1],
fields2 = _ref2[2];
return context.reportError(new _error.GraphQLError(fieldsConflictMessage(responseName, reason), fields1.concat(fields2)));

@@ -88,3 +88,3 @@ });

// Tuple defining an AST in a context
// Tuple defining a field node in a context.

@@ -155,10 +155,10 @@ // Map of array of those.

var _getFieldsAndFragment = getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType, selectionSet);
var _getFieldsAndFragment = getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType, selectionSet),
fieldMap = _getFieldsAndFragment[0],
fragmentNames = _getFieldsAndFragment[1];
var fieldMap = _getFieldsAndFragment[0];
var fragmentNames = _getFieldsAndFragment[1];
// (A) Find find all conflicts "within" the fields of this selection set.
// Note: this is the *only place* `collectConflictsWithin` is called.
collectConflictsWithin(context, conflicts, cachedFieldsAndFragmentNames, comparedFragments, fieldMap);

@@ -189,10 +189,10 @@

var _getReferencedFieldsA = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment);
var _getReferencedFieldsA = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment),
fieldMap2 = _getReferencedFieldsA[0],
fragmentNames2 = _getReferencedFieldsA[1];
var fieldMap2 = _getReferencedFieldsA[0];
var fragmentNames2 = _getReferencedFieldsA[1];
// (D) First collect any conflicts between the provided collection of fields
// and the collection of fields represented by the given fragment.
collectConflictsBetween(context, conflicts, cachedFieldsAndFragmentNames, comparedFragments, areMutuallyExclusive, fieldMap, fieldMap2);

@@ -227,15 +227,14 @@

var _getReferencedFieldsA2 = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment1);
var _getReferencedFieldsA2 = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment1),
fieldMap1 = _getReferencedFieldsA2[0],
fragmentNames1 = _getReferencedFieldsA2[1];
var fieldMap1 = _getReferencedFieldsA2[0];
var fragmentNames1 = _getReferencedFieldsA2[1];
var _getReferencedFieldsA3 = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment2),
fieldMap2 = _getReferencedFieldsA3[0],
fragmentNames2 = _getReferencedFieldsA3[1];
var _getReferencedFieldsA3 = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment2);
var fieldMap2 = _getReferencedFieldsA3[0];
var fragmentNames2 = _getReferencedFieldsA3[1];
// (F) First, collect all conflicts between these two collections of fields
// (not including any nested fragments).
collectConflictsBetween(context, conflicts, cachedFieldsAndFragmentNames, comparedFragments, areMutuallyExclusive, fieldMap1, fieldMap2);

@@ -262,14 +261,13 @@

var _getFieldsAndFragment2 = getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType1, selectionSet1);
var _getFieldsAndFragment2 = getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType1, selectionSet1),
fieldMap1 = _getFieldsAndFragment2[0],
fragmentNames1 = _getFieldsAndFragment2[1];
var fieldMap1 = _getFieldsAndFragment2[0];
var fragmentNames1 = _getFieldsAndFragment2[1];
var _getFieldsAndFragment3 = getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType2, selectionSet2),
fieldMap2 = _getFieldsAndFragment3[0],
fragmentNames2 = _getFieldsAndFragment3[1];
var _getFieldsAndFragment3 = getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType2, selectionSet2);
// (H) First, collect all conflicts between these two collections of field.
var fieldMap2 = _getFieldsAndFragment3[0];
var fragmentNames2 = _getFieldsAndFragment3[1];
// (H) First, collect all conflicts between these two collections of field.
collectConflictsBetween(context, conflicts, cachedFieldsAndFragmentNames, comparedFragments, areMutuallyExclusive, fieldMap1, fieldMap2);

@@ -355,8 +353,8 @@

function findConflict(context, cachedFieldsAndFragmentNames, comparedFragments, parentFieldsAreMutuallyExclusive, responseName, field1, field2) {
var parentType1 = field1[0];
var ast1 = field1[1];
var def1 = field1[2];
var parentType2 = field2[0];
var ast2 = field2[1];
var def2 = field2[2];
var parentType1 = field1[0],
node1 = field1[1],
def1 = field1[2];
var parentType2 = field2[0],
node2 = field2[1],
def2 = field2[2];

@@ -380,11 +378,11 @@ // If it is known that two fields could not possibly apply at the same

// Two aliases must refer to the same field.
var name1 = ast1.name.value;
var name2 = ast2.name.value;
var name1 = node1.name.value;
var name2 = node2.name.value;
if (name1 !== name2) {
return [[responseName, name1 + ' and ' + name2 + ' are different fields'], [ast1], [ast2]];
return [[responseName, name1 + ' and ' + name2 + ' are different fields'], [node1], [node2]];
}
// Two field calls must have the same arguments.
if (!sameArguments(ast1.arguments || [], ast2.arguments || [])) {
return [[responseName, 'they have differing arguments'], [ast1], [ast2]];
if (!sameArguments(node1.arguments || [], node2.arguments || [])) {
return [[responseName, 'they have differing arguments'], [node1], [node2]];
}

@@ -394,3 +392,3 @@ }

if (type1 && type2 && doTypesConflict(type1, type2)) {
return [[responseName, 'they return conflicting types ' + String(type1) + ' and ' + String(type2)], [ast1], [ast2]];
return [[responseName, 'they return conflicting types ' + String(type1) + ' and ' + String(type2)], [node1], [node2]];
}

@@ -401,7 +399,7 @@

// compared to themselves.
var selectionSet1 = ast1.selectionSet;
var selectionSet2 = ast2.selectionSet;
var selectionSet1 = node1.selectionSet;
var selectionSet2 = node2.selectionSet;
if (selectionSet1 && selectionSet2) {
var conflicts = findConflictsBetweenSubSelectionSets(context, cachedFieldsAndFragmentNames, comparedFragments, areMutuallyExclusive, (0, _definition.getNamedType)(type1), selectionSet1, (0, _definition.getNamedType)(type2), selectionSet2);
return subfieldConflicts(conflicts, responseName, ast1, ast2);
return subfieldConflicts(conflicts, responseName, node1, node2);
}

@@ -452,3 +450,3 @@ }

// Given a selection set, return the collection of fields (a mapping of response
// name to field ASTs and definitions) as well as a list of fragment names
// name to field nodes and definitions) as well as a list of fragment names
// referenced via fragment spreads.

@@ -458,6 +456,6 @@ function getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType, selectionSet) {

if (!cached) {
var astAndDefs = {};
var nodeAndDefs = {};
var fragmentNames = {};
_collectFieldsAndFragmentNames(context, parentType, selectionSet, astAndDefs, fragmentNames);
cached = [astAndDefs, Object.keys(fragmentNames)];
_collectFieldsAndFragmentNames(context, parentType, selectionSet, nodeAndDefs, fragmentNames);
cached = [nodeAndDefs, Object.keys(fragmentNames)];
cachedFieldsAndFragmentNames.set(selectionSet, cached);

@@ -471,3 +469,3 @@ }

function getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment) {
// Short-circuit building a type from the AST if possible.
// Short-circuit building a type from the node if possible.
var cached = cachedFieldsAndFragmentNames.get(fragment.selectionSet);

@@ -482,3 +480,3 @@ if (cached) {

function _collectFieldsAndFragmentNames(context, parentType, selectionSet, astAndDefs, fragmentNames) {
function _collectFieldsAndFragmentNames(context, parentType, selectionSet, nodeAndDefs, fragmentNames) {
for (var i = 0; i < selectionSet.selections.length; i++) {

@@ -494,6 +492,6 @@ var selection = selectionSet.selections[i];

var responseName = selection.alias ? selection.alias.value : fieldName;
if (!astAndDefs[responseName]) {
astAndDefs[responseName] = [];
if (!nodeAndDefs[responseName]) {
nodeAndDefs[responseName] = [];
}
astAndDefs[responseName].push([parentType, selection, fieldDef]);
nodeAndDefs[responseName].push([parentType, selection, fieldDef]);
break;

@@ -506,3 +504,3 @@ case _kinds.FRAGMENT_SPREAD:

var inlineFragmentType = typeCondition ? (0, _typeFromAST.typeFromAST)(context.getSchema(), typeCondition) : parentType;
_collectFieldsAndFragmentNames(context, inlineFragmentType, selection.selectionSet, astAndDefs, fragmentNames);
_collectFieldsAndFragmentNames(context, inlineFragmentType, selection.selectionSet, nodeAndDefs, fragmentNames);
break;

@@ -515,3 +513,3 @@ }

// a single Conflict.
function subfieldConflicts(conflicts, responseName, ast1, ast2) {
function subfieldConflicts(conflicts, responseName, node1, node2) {
if (conflicts.length > 0) {

@@ -524,6 +522,6 @@ return [[responseName, conflicts.map(function (_ref3) {

return allFields.concat(fields1);
}, [ast1]), conflicts.reduce(function (allFields, _ref5) {
}, [node1]), conflicts.reduce(function (allFields, _ref5) {
var fields2 = _ref5[2];
return allFields.concat(fields2);
}, [ast2])];
}, [node2])];
}

@@ -530,0 +528,0 @@ }

@@ -47,3 +47,3 @@ 'use strict';

// Validate on leave to allow for deeper errors to appear first.
leave: function leave(fieldAST) {
leave: function leave(node) {
var fieldDef = context.getFieldDef();

@@ -53,11 +53,11 @@ if (!fieldDef) {

}
var argASTs = fieldAST.arguments || [];
var argNodes = node.arguments || [];
var argASTMap = (0, _keyMap2.default)(argASTs, function (arg) {
var argNodeMap = (0, _keyMap2.default)(argNodes, function (arg) {
return arg.name.value;
});
fieldDef.args.forEach(function (argDef) {
var argAST = argASTMap[argDef.name];
if (!argAST && argDef.type instanceof _definition.GraphQLNonNull) {
context.reportError(new _error.GraphQLError(missingFieldArgMessage(fieldAST.name.value, argDef.name, argDef.type), [fieldAST]));
var argNode = argNodeMap[argDef.name];
if (!argNode && argDef.type instanceof _definition.GraphQLNonNull) {
context.reportError(new _error.GraphQLError(missingFieldArgMessage(node.name.value, argDef.name, argDef.type), [node]));
}

@@ -70,3 +70,3 @@ });

// Validate on leave to allow for deeper errors to appear first.
leave: function leave(directiveAST) {
leave: function leave(node) {
var directiveDef = context.getDirective();

@@ -76,11 +76,11 @@ if (!directiveDef) {

}
var argASTs = directiveAST.arguments || [];
var argNodes = node.arguments || [];
var argASTMap = (0, _keyMap2.default)(argASTs, function (arg) {
var argNodeMap = (0, _keyMap2.default)(argNodes, function (arg) {
return arg.name.value;
});
directiveDef.args.forEach(function (argDef) {
var argAST = argASTMap[argDef.name];
if (!argAST && argDef.type instanceof _definition.GraphQLNonNull) {
context.reportError(new _error.GraphQLError(missingDirectiveArgMessage(directiveAST.name.value, argDef.name, argDef.type), [directiveAST]));
var argNode = argNodeMap[argDef.name];
if (!argNode && argDef.type instanceof _definition.GraphQLNonNull) {
context.reportError(new _error.GraphQLError(missingDirectiveArgMessage(node.name.value, argDef.name, argDef.type), [node]));
}

@@ -87,0 +87,0 @@ });

@@ -46,4 +46,4 @@ 'use strict';

usages.forEach(function (_ref) {
var node = _ref.node;
var type = _ref.type;
var node = _ref.node,
type = _ref.type;

@@ -67,4 +67,4 @@ var varName = node.name.value;

},
VariableDefinition: function VariableDefinition(varDefAST) {
varDefMap[varDefAST.variable.name.value] = varDefAST;
VariableDefinition: function VariableDefinition(node) {
varDefMap[node.variable.name.value] = node;
}

@@ -71,0 +71,0 @@ };

@@ -40,2 +40,4 @@ 'use strict';

var _UniqueDirectivesPerLocation = require('./rules/UniqueDirectivesPerLocation');
var _KnownArgumentNames = require('./rules/KnownArgumentNames');

@@ -74,33 +76,25 @@

// Spec Section: "All Variables Used"
// Spec Section: "Directives Are Defined"
// Spec Section: "Variable Uniqueness"
// Spec Section: "All Variable Used Defined"
// Spec Section: "Fragment spread is possible"
// Spec Section: "Fragments must not form cycles"
// Spec Section: "Fragment spread target defined"
// Spec Section: "Fragments must be used"
// Spec Section: "Field Selections on Objects, Interfaces, and Unions Types"
// Spec Section: "Fragment Name Uniqueness"
// Spec Section: "Variables are Input Types"
// Spec Section: "Leaf Field Selections"
// Spec Section: "Fragment Spread Type Existence"
// Spec Section: "Fragments on Composite Types"
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// Spec Section: "Operation Name Uniqueness"
var specifiedRules = exports.specifiedRules = [_UniqueOperationNames.UniqueOperationNames, _LoneAnonymousOperation.LoneAnonymousOperation, _KnownTypeNames.KnownTypeNames, _FragmentsOnCompositeTypes.FragmentsOnCompositeTypes, _VariablesAreInputTypes.VariablesAreInputTypes, _ScalarLeafs.ScalarLeafs, _FieldsOnCorrectType.FieldsOnCorrectType, _UniqueFragmentNames.UniqueFragmentNames, _KnownFragmentNames.KnownFragmentNames, _NoUnusedFragments.NoUnusedFragments, _PossibleFragmentSpreads.PossibleFragmentSpreads, _NoFragmentCycles.NoFragmentCycles, _UniqueVariableNames.UniqueVariableNames, _NoUndefinedVariables.NoUndefinedVariables, _NoUnusedVariables.NoUnusedVariables, _KnownDirectives.KnownDirectives, _KnownArgumentNames.KnownArgumentNames, _UniqueArgumentNames.UniqueArgumentNames, _ArgumentsOfCorrectType.ArgumentsOfCorrectType, _ProvidedNonNullArguments.ProvidedNonNullArguments, _DefaultValuesOfCorrectType.DefaultValuesOfCorrectType, _VariablesInAllowedPosition.VariablesInAllowedPosition, _OverlappingFieldsCanBeMerged.OverlappingFieldsCanBeMerged, _UniqueInputFieldNames.UniqueInputFieldNames];
// Spec Section: "Lone Anonymous Operation"
var specifiedRules = exports.specifiedRules = [_UniqueOperationNames.UniqueOperationNames, _LoneAnonymousOperation.LoneAnonymousOperation, _KnownTypeNames.KnownTypeNames, _FragmentsOnCompositeTypes.FragmentsOnCompositeTypes, _VariablesAreInputTypes.VariablesAreInputTypes, _ScalarLeafs.ScalarLeafs, _FieldsOnCorrectType.FieldsOnCorrectType, _UniqueFragmentNames.UniqueFragmentNames, _KnownFragmentNames.KnownFragmentNames, _NoUnusedFragments.NoUnusedFragments, _PossibleFragmentSpreads.PossibleFragmentSpreads, _NoFragmentCycles.NoFragmentCycles, _UniqueVariableNames.UniqueVariableNames, _NoUndefinedVariables.NoUndefinedVariables, _NoUnusedVariables.NoUnusedVariables, _KnownDirectives.KnownDirectives, _UniqueDirectivesPerLocation.UniqueDirectivesPerLocation, _KnownArgumentNames.KnownArgumentNames, _UniqueArgumentNames.UniqueArgumentNames, _ArgumentsOfCorrectType.ArgumentsOfCorrectType, _ProvidedNonNullArguments.ProvidedNonNullArguments, _DefaultValuesOfCorrectType.DefaultValuesOfCorrectType, _VariablesInAllowedPosition.VariablesInAllowedPosition, _OverlappingFieldsCanBeMerged.OverlappingFieldsCanBeMerged, _UniqueInputFieldNames.UniqueInputFieldNames];

@@ -119,23 +113,34 @@ // Spec Section: "Input Object Field Uniqueness"

// Spec Section: "Directives Are Defined"
// Spec Section: "Directives Are Unique Per Location"
// Spec Section: "All Variable Used Defined"
// Spec Section: "All Variables Used"
// Spec Section: "Fragments must not form cycles"
// Spec Section: "Variable Uniqueness"
// Spec Section: "Fragments must be used"
// Spec Section: "Fragment spread is possible"
// Spec Section: "Fragment Name Uniqueness"
// Spec Section: "Fragment spread target defined"
// Spec Section: "Leaf Field Selections"
// Spec Section: "Field Selections on Objects, Interfaces, and Unions Types"
// Spec Section: "Fragments on Composite Types"
// Spec Section: "Variables are Input Types"
// Spec Section: "Lone Anonymous Operation"
// Spec Section: "Fragment Spread Type Existence"
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// Spec Section: "Operation Name Uniqueness"
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc