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

graphql

Package Overview
Dependencies
Maintainers
3
Versions
259
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.3.0 to 0.4.1

50

error/GraphQLError.js

@@ -35,5 +35,25 @@

this.message = message;
this.stack = stack || message;
Object.defineProperty(this, 'stack', { value: stack || message });
Object.defineProperty(this, 'nodes', { value: nodes });
}
// Note: flow does not yet know about Object.defineProperty with `get`.
return GraphQLError;
})(Error);
exports.GraphQLError = GraphQLError;
Object.defineProperty(GraphQLError.prototype, 'source', {
get: function get() {
var nodes = this.nodes;
if (nodes && nodes.length > 0) {
var node = nodes[0];
return node && node.loc && node.loc.source;
}
}
});
Object.defineProperty(GraphQLError.prototype, 'positions', {
get: function get() {
var nodes = this.nodes;
if (nodes) {
this.nodes = nodes;
var positions = nodes.map(function (node) {

@@ -45,18 +65,18 @@ return node.loc && node.loc.start;

})) {
this.positions = positions;
var loc = nodes[0].loc;
var source = loc && loc.source;
if (source) {
this.locations = positions.map(function (pos) {
return (0, _language.getLocation)(source, pos);
});
this.source = source;
}
return positions;
}
}
}
});
return GraphQLError;
})(Error);
exports.GraphQLError = GraphQLError;
Object.defineProperty(GraphQLError.prototype, 'locations', {
get: function get() {
var positions = this.positions;
var source = this.source;
if (positions && source) {
return positions.map(function (pos) {
return (0, _language.getLocation)(source, pos);
});
}
}
});

@@ -78,2 +78,4 @@

var _typeSchema = require('../type/schema');
var _typeIntrospection = require('../type/introspection');

@@ -94,2 +96,3 @@

(0, _jsutilsInvariant2['default'])(schema, 'Must provide schema');
(0, _jsutilsInvariant2['default'])(schema instanceof _typeSchema.GraphQLSchema, 'Schema must be an instance of GraphQLSchema. Also ensure that there are ' + 'not multiple versions of GraphQL installed in your node_modules directory.');

@@ -469,3 +472,3 @@ // If a valid context cannot be created due to incorrect arguments,

if (completed === null) {
throw new _error.GraphQLError('Cannot return null for non-nullable type.', fieldASTs);
throw new _error.GraphQLError('Cannot return null for non-nullable ' + ('field ' + info.parentType + '.' + info.fieldName + '.'), fieldASTs);
}

@@ -508,4 +511,14 @@ return completed;

// Field type must be Object, Interface or Union and expect sub-selections.
var objectType = returnType instanceof _typeDefinition.GraphQLObjectType ? returnType : (0, _typeDefinition.isAbstractType)(returnType) ? returnType.resolveType(result, info) : null;
var objectType;
if (returnType instanceof _typeDefinition.GraphQLObjectType) {
objectType = returnType;
} else if ((0, _typeDefinition.isAbstractType)(returnType)) {
var abstractType = returnType;
objectType = abstractType.getObjectType(result, info);
if (objectType && !abstractType.isPossibleType(objectType)) {
throw new _error.GraphQLError('Runtime Object type "' + objectType + '" is not a possible type ' + ('for "' + abstractType + '".'), fieldASTs);
}
}
if (!objectType) {

@@ -512,0 +525,0 @@ return null;

@@ -92,4 +92,5 @@

var type = (0, _utilitiesTypeFromAST.typeFromAST)(schema, definitionAST.type);
var variable = definitionAST.variable;
if (!type || !(0, _typeDefinition.isInputType)(type)) {
throw new _error.GraphQLError('Variable $' + definitionAST.variable.name.value + ' expected value of type ' + ((0, _languagePrinter.print)(definitionAST.type) + ' which cannot be used as an input type.'), [definitionAST]);
throw new _error.GraphQLError('Variable "$' + variable.name.value + '" expected value of type ' + ('"' + (0, _languagePrinter.print)(definitionAST.type) + '" which cannot be used as an input type.'), [definitionAST]);
}

@@ -105,3 +106,6 @@ if ((0, _utilitiesIsValidJSValue.isValidJSValue)(input, type)) {

}
throw new _error.GraphQLError('Variable $' + definitionAST.variable.name.value + ' expected value of type ' + ((0, _languagePrinter.print)(definitionAST.type) + ' but got: ' + JSON.stringify(input) + '.'), [definitionAST]);
if ((0, _jsutilsIsNullish2['default'])(input)) {
throw new _error.GraphQLError('Variable "$' + variable.name.value + '" of required type ' + ('"' + (0, _languagePrinter.print)(definitionAST.type) + '" was not provided.'), [definitionAST]);
}
throw new _error.GraphQLError('Variable "$' + variable.name.value + '" expected value of type ' + ('"' + (0, _languagePrinter.print)(definitionAST.type) + '" but got: ' + JSON.stringify(input) + '.'), [definitionAST]);
}

@@ -108,0 +112,0 @@

@@ -126,3 +126,3 @@ /* /

* token, then lexes punctuators immediately or calls the appropriate helper
* fucntion for more complicated tokens.
* function for more complicated tokens.
*/

@@ -129,0 +129,0 @@ function readToken(source, fromPosition) {

{
"name": "graphql",
"version": "0.3.0",
"version": "0.4.1",
"description": "A Query Language and Runtime which can target any service.",

@@ -20,3 +20,3 @@ "contributors": [

"options": {
"mocha": "--require scripts/mocha-bootload src/**/__tests__/**/*.js"
"mocha": "--require resources/mocha-bootload src/**/__tests__/**/*.js"
},

@@ -35,7 +35,7 @@ "babel": {

"build": "babel src --ignore __tests__ --out-dir dist/ && cp package.json dist/",
"watch": "babel scripts/watch.js | node",
"watch": "babel resources/watch.js | node",
"cover": "babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha",
"cover:lcov": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha",
"preversion": "npm test",
"prepublish": ". ./scripts/prepublish.sh"
"preversion": ". ./resources/checkgit.sh && npm test",
"prepublish": ". ./resources/prepublish.sh"
},

@@ -42,0 +42,0 @@ "dependencies": {

@@ -75,3 +75,5 @@ # GraphQL.js

type: GraphQLString,
resolve: () => 'world'
resolve() {
return 'world';
}
}

@@ -78,0 +80,0 @@ }

@@ -11,2 +11,4 @@

// Predicates
/**

@@ -17,8 +19,2 @@ * These are all of the possible kinds of types.

// Predicates
/**
* These types may be used as input types for arguments and directives.
*/
var _createClass = require('babel-runtime/helpers/create-class')['default'];

@@ -32,2 +28,4 @@

var _Object$create = require('babel-runtime/core-js/object/create')['default'];
var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];

@@ -38,2 +36,7 @@

});
exports.isType = isType;
/**
* These types may be used as input types for arguments and directives.
*/
exports.isInputType = isInputType;

@@ -75,4 +78,16 @@

var _jsutilsIsNullish = require('../jsutils/isNullish');
var _jsutilsIsNullish2 = _interopRequireDefault(_jsutilsIsNullish);
var _jsutilsKeyMap = require('../jsutils/keyMap');
var _jsutilsKeyMap2 = _interopRequireDefault(_jsutilsKeyMap);
var _languageKinds = require('../language/kinds');
function isType(type) {
return type instanceof GraphQLScalarType || type instanceof GraphQLObjectType || type instanceof GraphQLInterfaceType || type instanceof GraphQLUnionType || type instanceof GraphQLEnumType || type instanceof GraphQLInputObjectType || type instanceof GraphQLList || type instanceof GraphQLNonNull;
}
function isInputType(type) {

@@ -139,2 +154,6 @@ var namedType = getNamedType(type);

this.description = config.description;
(0, _jsutilsInvariant2['default'])(typeof config.serialize === 'function', this + ' must provide "serialize" function. If this custom Scalar is ' + 'also used as an input type, ensure "parseValue" and "parseLiteral" ' + 'functions are also provided.');
if (config.parseValue || config.parseLiteral) {
(0, _jsutilsInvariant2['default'])(typeof config.parseValue === 'function' && typeof config.parseLiteral === 'function', this + ' must provide both "parseValue" and "parseLiteral" functions.');
}
this._scalarConfig = config;

@@ -219,2 +238,5 @@ }

this.description = config.description;
if (config.isTypeOf) {
(0, _jsutilsInvariant2['default'])(typeof config.isTypeOf === 'function', this + ' must provide "isTypeOf" as a function.');
}
this.isTypeOf = config.isTypeOf;

@@ -228,3 +250,3 @@ this._typeConfig = config;

value: function getFields() {
return this._fields || (this._fields = defineFieldMap(this._typeConfig.fields));
return this._fields || (this._fields = defineFieldMap(this, this._typeConfig.fields));
}

@@ -234,3 +256,3 @@ }, {

value: function getInterfaces() {
return this._interfaces || (this._interfaces = defineInterfaces(this._typeConfig.interfaces || []));
return this._interfaces || (this._interfaces = defineInterfaces(this, this._typeConfig.interfaces));
}

@@ -253,17 +275,33 @@ }, {

function defineInterfaces(interfacesOrThunk) {
return resolveMaybeThunk(interfacesOrThunk);
function defineInterfaces(type, interfacesOrThunk) {
var interfaces = resolveMaybeThunk(interfacesOrThunk);
if (!interfaces) {
return [];
}
(0, _jsutilsInvariant2['default'])(Array.isArray(interfaces), type + ' interfaces must be an Array or a function which returns an Array.');
interfaces.forEach(function (iface) {
(0, _jsutilsInvariant2['default'])(iface instanceof GraphQLInterfaceType, type + ' may only implement Interface types, it cannot ' + ('implement: ' + iface + '.'));
if (typeof iface.resolveType !== 'function') {
(0, _jsutilsInvariant2['default'])(typeof type.isTypeOf === 'function', 'Interface Type ' + iface + ' does not provide a "resolveType" function ' + ('and implementing Type ' + type + ' does not provide a "isTypeOf" ') + 'function. There is no way to resolve this implementing type ' + 'during execution.');
}
});
return interfaces;
}
function defineFieldMap(fields) {
function defineFieldMap(type, fields) {
var fieldMap = resolveMaybeThunk(fields);
_Object$keys(fieldMap).forEach(function (fieldName) {
(0, _jsutilsInvariant2['default'])(isPlainObj(fieldMap), type + ' fields must be an object with field names as keys or a ' + 'function which returns such an object.');
var fieldNames = _Object$keys(fieldMap);
(0, _jsutilsInvariant2['default'])(fieldNames.length > 0, type + ' fields must be an object with field names as keys or a ' + 'function which returns such an object.');
fieldNames.forEach(function (fieldName) {
var field = fieldMap[fieldName];
field.name = fieldName;
(0, _jsutilsInvariant2['default'])(isOutputType(field.type), type + '.' + fieldName + ' field type must be Output Type but ' + ('got: ' + field.type + '.'));
if (!field.args) {
field.args = [];
} else {
(0, _jsutilsInvariant2['default'])(isPlainObj(field.args), type + '.' + fieldName + ' args must be an object with argument names ' + 'as keys.');
field.args = _Object$keys(field.args).map(function (argName) {
var arg = field.args[argName];
(0, _jsutilsInvariant2['default'])(arg.type, 'Arg must supply type. ' + fieldName + '.' + argName);
(0, _jsutilsInvariant2['default'])(isInputType(arg.type), type + '.' + fieldName + '(' + argName + ':) argument type must be ' + ('Input Type but got: ' + arg.type + '.'));
return {

@@ -281,2 +319,6 @@ name: argName,

function isPlainObj(obj) {
return obj && typeof obj === 'object' && !Array.isArray(obj);
}
/**

@@ -320,2 +362,6 @@ * Update the interfaces to know about this implementation.

this.description = config.description;
if (config.resolveType) {
(0, _jsutilsInvariant2['default'])(typeof config.resolveType === 'function', this + ' must provide "resolveType" as a function.');
}
this.resolveType = config.resolveType;
this._typeConfig = config;

@@ -328,3 +374,3 @@ this._implementations = [];

value: function getFields() {
return this._fields || (this._fields = defineFieldMap(this._typeConfig.fields));
return this._fields || (this._fields = defineFieldMap(this, this._typeConfig.fields));
}

@@ -339,14 +385,11 @@ }, {

value: function isPossibleType(type) {
var possibleTypeNames = this._possibleTypeNames;
if (!possibleTypeNames) {
this._possibleTypeNames = possibleTypeNames = this.getPossibleTypes().reduce(function (map, possibleType) {
return (map[possibleType.name] = true, map);
}, {});
}
return possibleTypeNames[type.name] === true;
var possibleTypes = this._possibleTypes || (this._possibleTypes = (0, _jsutilsKeyMap2['default'])(this.getPossibleTypes(), function (possibleType) {
return possibleType.name;
}));
return Boolean(possibleTypes[type.name]);
}
}, {
key: 'resolveType',
value: function resolveType(value, info) {
var resolver = this._typeConfig.resolveType;
key: 'getObjectType',
value: function getObjectType(value, info) {
var resolver = this.resolveType;
return resolver ? resolver(value, info) : getTypeOf(value, info, this);

@@ -370,8 +413,3 @@ }

var type = possibleTypes[i];
if (typeof type.isTypeOf !== 'function') {
// TODO: move this to a JS impl specific type system validation step
// so the error can be found before execution.
throw new Error('Non-Object Type ' + abstractType.name + ' does not implement ' + 'resolveType and Object Type ' + type.name + ' does not implement ' + 'isTypeOf. There is no way to determine if a value is of this type.');
}
if (type.isTypeOf(value, info)) {
if (typeof type.isTypeOf === 'function' && type.isTypeOf(value, info)) {
return type;

@@ -408,2 +446,4 @@ }

function GraphQLUnionType(config) {
var _this = this;
_classCallCheck(this, GraphQLUnionType);

@@ -414,11 +454,13 @@

this.description = config.description;
(0, _jsutilsInvariant2['default'])(config.types && config.types.length, 'Must provide types for Union ' + config.name + '.');
if (!config.types.every(function (x) {
return x instanceof GraphQLObjectType;
})) {
var nonObjectTypes = config.types.filter(function (x) {
return !(x instanceof GraphQLObjectType);
});
throw new Error('Union ' + config.name + ' may only contain object types, it cannot ' + ('contain: ' + nonObjectTypes.join(', ') + '.'));
if (config.resolveType) {
(0, _jsutilsInvariant2['default'])(typeof config.resolveType === 'function', this + ' must provide "resolveType" as a function.');
}
this.resolveType = config.resolveType;
(0, _jsutilsInvariant2['default'])(Array.isArray(config.types) && config.types.length > 0, 'Must provide Array of types for Union ' + config.name + '.');
config.types.forEach(function (type) {
(0, _jsutilsInvariant2['default'])(type instanceof GraphQLObjectType, _this + ' may only contain Object types, it cannot contain: ' + type + '.');
if (typeof _this.resolveType !== 'function') {
(0, _jsutilsInvariant2['default'])(typeof type.isTypeOf === 'function', 'Union Type ' + _this + ' does not provide a "resolveType" function ' + ('and possible Type ' + type + ' does not provide a "isTypeOf" ') + 'function. There is no way to resolve this possible type ' + 'during execution.');
}
});
this._types = config.types;

@@ -445,4 +487,4 @@ this._typeConfig = config;

}, {
key: 'resolveType',
value: function resolveType(value, info) {
key: 'getObjectType',
value: function getObjectType(value, info) {
var resolver = this._typeConfig.resolveType;

@@ -491,2 +533,3 @@ return resolver ? resolver(value, info) : getTypeOf(value, info, this);

this.description = config.description;
this._values = defineEnumValues(this, config.values);
this._enumConfig = config;

@@ -498,3 +541,3 @@ }

value: function getValues() /* <T> */{
return this._values || (this._values = this._defineValueMap());
return this._values;
}

@@ -510,4 +553,6 @@ }, {

value: function parseValue(value) /* T */{
var enumValue = this._getValueLookup().get(value);
return enumValue ? enumValue.name : null;
var enumValue = this._getNameLookup()[value];
if (enumValue) {
return enumValue.value;
}
}

@@ -518,3 +563,3 @@ }, {

if (valueAST.kind === _languageKinds.ENUM) {
var enumValue = this._getNameLookup().get(valueAST.value);
var enumValue = this._getNameLookup()[valueAST.value];
if (enumValue) {

@@ -526,15 +571,2 @@ return enumValue.value;

}, {
key: '_defineValueMap',
value: function _defineValueMap() /* <T> */{
var valueMap = this._enumConfig.values;
_Object$keys(valueMap).forEach(function (valueName) {
var value = valueMap[valueName];
value.name = valueName;
if (!value.hasOwnProperty('value')) {
value.value = valueName;
}
});
return valueMap;
}
}, {
key: '_getValueLookup',

@@ -544,5 +576,3 @@ value: function _getValueLookup() {

var lookup = new _Map();
var values = this.getValues();
_Object$keys(values).forEach(function (valueName) {
var value = values[valueName];
this.getValues().forEach(function (value) {
lookup.set(value.value, value);

@@ -558,7 +588,5 @@ });

if (!this._nameLookup) {
var lookup = new _Map();
var values = this.getValues();
_Object$keys(values).forEach(function (valueName) {
var value = values[valueName];
lookup.set(value.name, value);
var lookup = _Object$create(null);
this.getValues().forEach(function (value) {
lookup[value.name] = value;
});

@@ -580,4 +608,21 @@ this._nameLookup = lookup;

exports.GraphQLEnumType = GraphQLEnumType;
/* <T> */ /* <T> */
function defineEnumValues(type, valueMap /* <T> */
) /* <T> */{
(0, _jsutilsInvariant2['default'])(isPlainObj(valueMap), type + ' values must be an object with value names as keys.');
var valueNames = _Object$keys(valueMap);
(0, _jsutilsInvariant2['default'])(valueNames.length > 0, type + ' values must be an object with value names as keys.');
return valueNames.map(function (valueName) {
var value = valueMap[valueName];
(0, _jsutilsInvariant2['default'])(isPlainObj(value), type + '.' + valueName + ' must refer to an object with a "value" key ' + ('representing an internal value but got: ' + value + '.'));
value.name = valueName;
if ((0, _jsutilsIsNullish2['default'])(value.value)) {
value.value = valueName;
}
return value;
});
}
/* <T> */
/**

@@ -622,7 +667,12 @@ * Input Object Type Definition

value: function _defineFieldMap() {
var fields = this._typeConfig.fields;
var fieldMap = typeof fields === 'function' ? fields() : fields;
_Object$keys(fieldMap).forEach(function (fieldName) {
var _this2 = this;
var fieldMap = resolveMaybeThunk(this._typeConfig.fields);
(0, _jsutilsInvariant2['default'])(isPlainObj(fieldMap), this + ' fields must be an object with field names as keys or a ' + 'function which returns such an object.');
var fieldNames = _Object$keys(fieldMap);
(0, _jsutilsInvariant2['default'])(fieldNames.length > 0, this + ' fields must be an object with field names as keys or a ' + 'function which returns such an object.');
fieldNames.forEach(function (fieldName) {
var field = fieldMap[fieldName];
field.name = fieldName;
(0, _jsutilsInvariant2['default'])(isInputType(field.type), _this2 + '.' + fieldName + ' field type must be Input Type but ' + ('got: ' + field.type + '.'));
});

@@ -666,2 +716,3 @@ return fieldMap;

(0, _jsutilsInvariant2['default'])(isType(type), 'Can only create List of a GraphQLType but got: ' + type + '.');
this.ofType = type;

@@ -694,3 +745,3 @@ }

value: function toString() {
return '[' + this.ofType.toString() + ']';
return '[' + String(this.ofType) + ']';
}

@@ -708,3 +759,3 @@ }]);

(0, _jsutilsInvariant2['default'])(!(type instanceof GraphQLNonNull), 'Cannot nest NonNull inside NonNull.');
(0, _jsutilsInvariant2['default'])(isType(type) && !(type instanceof GraphQLNonNull), 'Can only create NonNull of a Nullable GraphQLType but got: ' + type + '.');
this.ofType = type;

@@ -736,2 +787,2 @@ }

*/
/* <T> */ /* <T> */ /* T */ /* T */ /* <T> */ /* <T> */ /* <T> */ /* <T> */ /* T */ /* <T> */ /* <T> */ /* T */
/* <T> */ /* <T> */ /* T */ /* T */ /* <T> */ /* <T> */ /* <T> */ /* <T> */ /* T */ /* <T> */ /* T */

@@ -29,2 +29,8 @@

Object.defineProperty(exports, 'isType', {
enumerable: true,
get: function get() {
return _definition.isType;
}
});
Object.defineProperty(exports, 'isInputType', {

@@ -31,0 +37,0 @@ enumerable: true,

@@ -170,6 +170,3 @@ /* weak */

if (type instanceof _definition.GraphQLEnumType) {
var valueMap = type.getValues();
var values = _Object$keys(valueMap).map(function (valueName) {
return valueMap[valueName];
});
var values = type.getValues();
if (!includeDeprecated) {

@@ -176,0 +173,0 @@ values = values.filter(function (value) {

@@ -35,2 +35,6 @@

var _jsutilsInvariant = require('../jsutils/invariant');
var _jsutilsInvariant2 = _interopRequireDefault(_jsutilsInvariant);
/**

@@ -54,5 +58,23 @@ * Schema Definition

function GraphQLSchema(config) {
var _this = this;
_classCallCheck(this, GraphQLSchema);
(0, _jsutilsInvariant2['default'])(typeof config === 'object', 'Must provide configuration object.');
(0, _jsutilsInvariant2['default'])(config.query instanceof _definition.GraphQLObjectType, 'Schema query must be Object Type but got: ' + config.query + '.');
(0, _jsutilsInvariant2['default'])(!config.mutation || config.mutation instanceof _definition.GraphQLObjectType, 'Schema mutation must be Object Type if provided but ' + ('got: ' + config.mutation + '.'));
this._schemaConfig = config;
// Build type map now to detect any errors within this schema.
this._typeMap = [this.getQueryType(), this.getMutationType(), _introspection.__Schema].reduce(typeMapReducer, {});
// Enforce correct interface implementations
_Object$keys(this._typeMap).forEach(function (typeName) {
var type = _this._typeMap[typeName];
if (type instanceof _definition.GraphQLObjectType) {
type.getInterfaces().forEach(function (iface) {
return assertObjectImplementsInterface(type, iface);
});
}
});
}

@@ -73,3 +95,3 @@

value: function getTypeMap() {
return this._typeMap || (this._typeMap = [this.getQueryType(), this.getMutationType(), _introspection.__Schema].reduce(typeMapReducer, {}));
return this._typeMap;
}

@@ -109,2 +131,5 @@ }, {

if (!type) {
return map;
}
if (type instanceof _definition.GraphQLList || type instanceof _definition.GraphQLNonNull) {

@@ -116,3 +141,4 @@ _x = map;

}
if (!type || map[type.name]) {
if (map[type.name]) {
(0, _jsutilsInvariant2['default'])(map[type.name] === type, 'Schema must contain unique named types but contains multiple ' + ('types named "' + type + '".'));
return map;

@@ -148,2 +174,67 @@ }

}
}
function assertObjectImplementsInterface(object, iface) {
var objectFieldMap = object.getFields();
var ifaceFieldMap = iface.getFields();
// Assert each interface field is implemented.
_Object$keys(ifaceFieldMap).forEach(function (fieldName) {
var objectField = objectFieldMap[fieldName];
var ifaceField = ifaceFieldMap[fieldName];
// Assert interface field exists on object.
(0, _jsutilsInvariant2['default'])(objectField, '"' + iface + '" expects field "' + fieldName + '" but "' + object + '" does not ' + 'provide it.');
// Assert interface field type matches object field type. (invariant)
(0, _jsutilsInvariant2['default'])(isEqualType(ifaceField.type, objectField.type), iface + '.' + fieldName + ' expects type "' + ifaceField.type + '" but ' + (object + '.' + fieldName + ' provides type "' + objectField.type + '".'));
// Assert each interface field arg is implemented.
ifaceField.args.forEach(function (ifaceArg) {
var argName = ifaceArg.name;
var objectArg = (0, _jsutilsFind2['default'])(objectField.args, function (arg) {
return arg.name === argName;
});
// Assert interface field arg exists on object field.
(0, _jsutilsInvariant2['default'])(objectArg, iface + '.' + fieldName + ' expects argument "' + argName + '" but ' + (object + '.' + fieldName + ' does not provide it.'));
// Assert interface field arg type matches object field arg type.
// (invariant)
(0, _jsutilsInvariant2['default'])(isEqualType(ifaceArg.type, objectArg.type), iface + '.' + fieldName + '(' + argName + ':) expects type "' + ifaceArg.type + '" ' + ('but ' + object + '.' + fieldName + '(' + argName + ':) provides ') + ('type "' + objectArg.type + '".'));
});
// Assert argument set invariance.
objectField.args.forEach(function (objectArg) {
var argName = objectArg.name;
var ifaceArg = (0, _jsutilsFind2['default'])(ifaceField.args, function (arg) {
return arg.name === argName;
});
(0, _jsutilsInvariant2['default'])(ifaceArg, iface + '.' + fieldName + ' does not define argument "' + argName + '" but ' + (object + '.' + fieldName + ' provides it.'));
});
});
}
function isEqualType(_x3, _x4) {
var _again2 = true;
_function2: while (_again2) {
var typeA = _x3,
typeB = _x4;
_again2 = false;
if (typeA instanceof _definition.GraphQLNonNull && typeB instanceof _definition.GraphQLNonNull) {
_x3 = typeA.ofType;
_x4 = typeB.ofType;
_again2 = true;
continue _function2;
}
if (typeA instanceof _definition.GraphQLList && typeB instanceof _definition.GraphQLList) {
_x3 = typeA.ofType;
_x4 = typeB.ofType;
_again2 = true;
continue _function2;
}
return typeA === typeB;
}
}

@@ -147,6 +147,2 @@ /**

// This actually constructs all the types by iterating over the schema
// This makes it so that errors actually get caught before this function
// exits.
schema.getTypeMap();
return schema;

@@ -220,2 +216,5 @@

name: typeName,
resolveType: function resolveType() {
return null;
},
fields: function fields() {

@@ -244,2 +243,5 @@ return makeFieldDefMap(def);

name: def.name.value,
resolveType: function resolveType() {
return null;
},
types: def.types.map(function (t) {

@@ -253,3 +255,16 @@ return produceTypeDef(t);

return new _type.GraphQLScalarType({
name: def.name.value
name: def.name.value,
serialize: function serialize() {
return null;
},
// Note: validation calls the parse functions to determine if a
// literal value is correct. Returning null would cause use of custom
// scalars to always fail validation. Returning false causes them to
// always pass validation.
parseValue: function parseValue() {
return false;
},
parseLiteral: function parseLiteral() {
return false;
}
});

@@ -256,0 +271,0 @@ }

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

description: scalarIntrospection.description,
// Note: validation calls the serialize functions to determine if a
// query value is correct. Returning null would cause use of custom
serialize: function serialize() {
return null;
},
// Note: validation calls the parse functions to determine if a
// literal value is correct. Returning null would cause use of custom
// scalars to always fail validation. Returning false causes them to
// always pass validation.
serialize: function serialize() {
return false;
},
parseValue: function parseValue() {

@@ -190,2 +190,5 @@ return false;

return buildFieldDefMap(interfaceIntrospection);
},
resolveType: function resolveType() {
throw new Error('Client Schema cannot be used for execution.');
}

@@ -199,3 +202,6 @@ });

description: unionIntrospection.description,
types: unionIntrospection.possibleTypes.map(getObjectType)
types: unionIntrospection.possibleTypes.map(getObjectType),
resolveType: function resolveType() {
throw new Error('Client Schema cannot be used for execution.');
}
});

@@ -273,8 +279,3 @@ }

// The schema is lazy by default, getting the type map will resolve any
// deferred functions, ensuring that any errors are presented before this
// function exits.
schema.getTypeMap();
return schema;
}

@@ -104,6 +104,3 @@

function printEnum(type) {
var valueMap = type.getValues();
var values = _Object$keys(valueMap).map(function (valueName) {
return valueMap[valueName];
});
var values = type.getValues();
return 'enum ' + type.name + ' {\n' + values.map(function (v) {

@@ -110,0 +107,0 @@ return ' ' + v.name;

@@ -26,3 +26,3 @@

function badValueMessage(argName, type, value) {
return 'Argument "' + argName + '" expected type "' + type + '" but got: "' + value + '".';
return 'Argument "' + argName + '" expected type "' + type + '" but got: ' + value + '.';
}

@@ -29,0 +29,0 @@

@@ -33,3 +33,3 @@

function badValueForDefaultArgMessage(varName, type, value) {
return 'Variable "$' + varName + '" of type "' + type + '" has invalid default ' + ('value: "' + value + '".');
return 'Variable "$' + varName + '" of type "' + type + '" has invalid default ' + ('value: ' + value + '.');
}

@@ -36,0 +36,0 @@

@@ -38,2 +38,4 @@

var _typeSchema = require('../type/schema');
var _utilitiesTypeInfo = require('../utilities/TypeInfo');

@@ -64,2 +66,3 @@

(0, _jsutilsInvariant2['default'])(ast, 'Must provide document');
(0, _jsutilsInvariant2['default'])(schema instanceof _typeSchema.GraphQLSchema, 'Schema must be an instance of GraphQLSchema. Also ensure that there are ' + 'not multiple versions of GraphQL installed in your node_modules directory.');
return visitUsingRules(schema, ast, rules || _specifiedRules.specifiedRules);

@@ -66,0 +69,0 @@ }

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