Initial Save
This commit is contained in:
49
node_modules/graphql/utilities/TypeInfo.d.ts
generated
vendored
Normal file
49
node_modules/graphql/utilities/TypeInfo.d.ts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import Maybe from '../tsutils/Maybe';
|
||||
import { ASTNode, FieldNode } from '../language/ast';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { GraphQLDirective } from '../type/directives';
|
||||
import {
|
||||
GraphQLType,
|
||||
GraphQLInputType,
|
||||
GraphQLOutputType,
|
||||
GraphQLCompositeType,
|
||||
GraphQLField,
|
||||
GraphQLArgument,
|
||||
GraphQLEnumValue,
|
||||
} from '../type/definition';
|
||||
|
||||
/**
|
||||
* TypeInfo is a utility class which, given a GraphQL schema, can keep track
|
||||
* of the current field and type definitions at any point in a GraphQL document
|
||||
* AST during a recursive descent by calling `enter(node)` and `leave(node)`.
|
||||
*/
|
||||
export class TypeInfo {
|
||||
constructor(
|
||||
schema: GraphQLSchema,
|
||||
// NOTE: this experimental optional second parameter is only needed in order
|
||||
// to support non-spec-compliant codebases. You should never need to use it.
|
||||
// It may disappear in the future.
|
||||
getFieldDefFn?: getFieldDef,
|
||||
// Initial type may be provided in rare cases to facilitate traversals
|
||||
// beginning somewhere other than documents.
|
||||
initialType?: GraphQLType,
|
||||
);
|
||||
|
||||
getType(): Maybe<GraphQLOutputType>;
|
||||
getParentType(): Maybe<GraphQLCompositeType>;
|
||||
getInputType(): Maybe<GraphQLInputType>;
|
||||
getParentInputType(): Maybe<GraphQLInputType>;
|
||||
getFieldDef(): GraphQLField<any, Maybe<any>>;
|
||||
getDefaultValue(): Maybe<any>;
|
||||
getDirective(): Maybe<GraphQLDirective>;
|
||||
getArgument(): Maybe<GraphQLArgument>;
|
||||
getEnumValue(): Maybe<GraphQLEnumValue>;
|
||||
enter(node: ASTNode): any;
|
||||
leave(node: ASTNode): any;
|
||||
}
|
||||
|
||||
type getFieldDef = (
|
||||
schema: GraphQLSchema,
|
||||
parentType: GraphQLType,
|
||||
fieldNode: FieldNode,
|
||||
) => Maybe<GraphQLField<any, any>>;
|
||||
343
node_modules/graphql/utilities/TypeInfo.js
generated
vendored
Normal file
343
node_modules/graphql/utilities/TypeInfo.js
generated
vendored
Normal file
@@ -0,0 +1,343 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.TypeInfo = void 0;
|
||||
|
||||
var _find = _interopRequireDefault(require("../polyfills/find"));
|
||||
|
||||
var _kinds = require("../language/kinds");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
var _introspection = require("../type/introspection");
|
||||
|
||||
var _typeFromAST = require("./typeFromAST");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* TypeInfo is a utility class which, given a GraphQL schema, can keep track
|
||||
* of the current field and type definitions at any point in a GraphQL document
|
||||
* AST during a recursive descent by calling `enter(node)` and `leave(node)`.
|
||||
*/
|
||||
var TypeInfo =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function TypeInfo(schema, // NOTE: this experimental optional second parameter is only needed in order
|
||||
// to support non-spec-compliant codebases. You should never need to use it.
|
||||
// It may disappear in the future.
|
||||
getFieldDefFn, // Initial type may be provided in rare cases to facilitate traversals
|
||||
// beginning somewhere other than documents.
|
||||
initialType) {
|
||||
this._schema = schema;
|
||||
this._typeStack = [];
|
||||
this._parentTypeStack = [];
|
||||
this._inputTypeStack = [];
|
||||
this._fieldDefStack = [];
|
||||
this._defaultValueStack = [];
|
||||
this._directive = null;
|
||||
this._argument = null;
|
||||
this._enumValue = null;
|
||||
this._getFieldDef = getFieldDefFn || getFieldDef;
|
||||
|
||||
if (initialType) {
|
||||
if ((0, _definition.isInputType)(initialType)) {
|
||||
this._inputTypeStack.push(initialType);
|
||||
}
|
||||
|
||||
if ((0, _definition.isCompositeType)(initialType)) {
|
||||
this._parentTypeStack.push(initialType);
|
||||
}
|
||||
|
||||
if ((0, _definition.isOutputType)(initialType)) {
|
||||
this._typeStack.push(initialType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _proto = TypeInfo.prototype;
|
||||
|
||||
_proto.getType = function getType() {
|
||||
if (this._typeStack.length > 0) {
|
||||
return this._typeStack[this._typeStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getParentType = function getParentType() {
|
||||
if (this._parentTypeStack.length > 0) {
|
||||
return this._parentTypeStack[this._parentTypeStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getInputType = function getInputType() {
|
||||
if (this._inputTypeStack.length > 0) {
|
||||
return this._inputTypeStack[this._inputTypeStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getParentInputType = function getParentInputType() {
|
||||
if (this._inputTypeStack.length > 1) {
|
||||
return this._inputTypeStack[this._inputTypeStack.length - 2];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getFieldDef = function getFieldDef() {
|
||||
if (this._fieldDefStack.length > 0) {
|
||||
return this._fieldDefStack[this._fieldDefStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getDefaultValue = function getDefaultValue() {
|
||||
if (this._defaultValueStack.length > 0) {
|
||||
return this._defaultValueStack[this._defaultValueStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getDirective = function getDirective() {
|
||||
return this._directive;
|
||||
};
|
||||
|
||||
_proto.getArgument = function getArgument() {
|
||||
return this._argument;
|
||||
};
|
||||
|
||||
_proto.getEnumValue = function getEnumValue() {
|
||||
return this._enumValue;
|
||||
};
|
||||
|
||||
_proto.enter = function enter(node) {
|
||||
var schema = this._schema; // Note: many of the types below are explicitly typed as "mixed" to drop
|
||||
// any assumptions of a valid schema to ensure runtime types are properly
|
||||
// checked before continuing since TypeInfo is used as part of validation
|
||||
// which occurs before guarantees of schema and document validity.
|
||||
|
||||
switch (node.kind) {
|
||||
case _kinds.Kind.SELECTION_SET:
|
||||
{
|
||||
var namedType = (0, _definition.getNamedType)(this.getType());
|
||||
|
||||
this._parentTypeStack.push((0, _definition.isCompositeType)(namedType) ? namedType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case _kinds.Kind.FIELD:
|
||||
{
|
||||
var parentType = this.getParentType();
|
||||
var fieldDef;
|
||||
var fieldType;
|
||||
|
||||
if (parentType) {
|
||||
fieldDef = this._getFieldDef(schema, parentType, node);
|
||||
|
||||
if (fieldDef) {
|
||||
fieldType = fieldDef.type;
|
||||
}
|
||||
}
|
||||
|
||||
this._fieldDefStack.push(fieldDef);
|
||||
|
||||
this._typeStack.push((0, _definition.isOutputType)(fieldType) ? fieldType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case _kinds.Kind.DIRECTIVE:
|
||||
this._directive = schema.getDirective(node.name.value);
|
||||
break;
|
||||
|
||||
case _kinds.Kind.OPERATION_DEFINITION:
|
||||
{
|
||||
var type;
|
||||
|
||||
if (node.operation === 'query') {
|
||||
type = schema.getQueryType();
|
||||
} else if (node.operation === 'mutation') {
|
||||
type = schema.getMutationType();
|
||||
} else if (node.operation === 'subscription') {
|
||||
type = schema.getSubscriptionType();
|
||||
}
|
||||
|
||||
this._typeStack.push((0, _definition.isObjectType)(type) ? type : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case _kinds.Kind.INLINE_FRAGMENT:
|
||||
case _kinds.Kind.FRAGMENT_DEFINITION:
|
||||
{
|
||||
var typeConditionAST = node.typeCondition;
|
||||
var outputType = typeConditionAST ? (0, _typeFromAST.typeFromAST)(schema, typeConditionAST) : (0, _definition.getNamedType)(this.getType());
|
||||
|
||||
this._typeStack.push((0, _definition.isOutputType)(outputType) ? outputType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case _kinds.Kind.VARIABLE_DEFINITION:
|
||||
{
|
||||
var inputType = (0, _typeFromAST.typeFromAST)(schema, node.type);
|
||||
|
||||
this._inputTypeStack.push((0, _definition.isInputType)(inputType) ? inputType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case _kinds.Kind.ARGUMENT:
|
||||
{
|
||||
var argDef;
|
||||
var argType;
|
||||
var fieldOrDirective = this.getDirective() || this.getFieldDef();
|
||||
|
||||
if (fieldOrDirective) {
|
||||
argDef = (0, _find.default)(fieldOrDirective.args, function (arg) {
|
||||
return arg.name === node.name.value;
|
||||
});
|
||||
|
||||
if (argDef) {
|
||||
argType = argDef.type;
|
||||
}
|
||||
}
|
||||
|
||||
this._argument = argDef;
|
||||
|
||||
this._defaultValueStack.push(argDef ? argDef.defaultValue : undefined);
|
||||
|
||||
this._inputTypeStack.push((0, _definition.isInputType)(argType) ? argType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case _kinds.Kind.LIST:
|
||||
{
|
||||
var listType = (0, _definition.getNullableType)(this.getInputType());
|
||||
var itemType = (0, _definition.isListType)(listType) ? listType.ofType : listType; // List positions never have a default value.
|
||||
|
||||
this._defaultValueStack.push(undefined);
|
||||
|
||||
this._inputTypeStack.push((0, _definition.isInputType)(itemType) ? itemType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case _kinds.Kind.OBJECT_FIELD:
|
||||
{
|
||||
var objectType = (0, _definition.getNamedType)(this.getInputType());
|
||||
var inputFieldType;
|
||||
var inputField;
|
||||
|
||||
if ((0, _definition.isInputObjectType)(objectType)) {
|
||||
inputField = objectType.getFields()[node.name.value];
|
||||
|
||||
if (inputField) {
|
||||
inputFieldType = inputField.type;
|
||||
}
|
||||
}
|
||||
|
||||
this._defaultValueStack.push(inputField ? inputField.defaultValue : undefined);
|
||||
|
||||
this._inputTypeStack.push((0, _definition.isInputType)(inputFieldType) ? inputFieldType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case _kinds.Kind.ENUM:
|
||||
{
|
||||
var enumType = (0, _definition.getNamedType)(this.getInputType());
|
||||
var enumValue;
|
||||
|
||||
if ((0, _definition.isEnumType)(enumType)) {
|
||||
enumValue = enumType.getValue(node.value);
|
||||
}
|
||||
|
||||
this._enumValue = enumValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_proto.leave = function leave(node) {
|
||||
switch (node.kind) {
|
||||
case _kinds.Kind.SELECTION_SET:
|
||||
this._parentTypeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case _kinds.Kind.FIELD:
|
||||
this._fieldDefStack.pop();
|
||||
|
||||
this._typeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case _kinds.Kind.DIRECTIVE:
|
||||
this._directive = null;
|
||||
break;
|
||||
|
||||
case _kinds.Kind.OPERATION_DEFINITION:
|
||||
case _kinds.Kind.INLINE_FRAGMENT:
|
||||
case _kinds.Kind.FRAGMENT_DEFINITION:
|
||||
this._typeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case _kinds.Kind.VARIABLE_DEFINITION:
|
||||
this._inputTypeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case _kinds.Kind.ARGUMENT:
|
||||
this._argument = null;
|
||||
|
||||
this._defaultValueStack.pop();
|
||||
|
||||
this._inputTypeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case _kinds.Kind.LIST:
|
||||
case _kinds.Kind.OBJECT_FIELD:
|
||||
this._defaultValueStack.pop();
|
||||
|
||||
this._inputTypeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case _kinds.Kind.ENUM:
|
||||
this._enumValue = null;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
return TypeInfo;
|
||||
}();
|
||||
/**
|
||||
* Not exactly the same as the executor's definition of getFieldDef, in this
|
||||
* statically evaluated environment we do not always have an Object type,
|
||||
* and need to handle Interface and Union types.
|
||||
*/
|
||||
|
||||
|
||||
exports.TypeInfo = TypeInfo;
|
||||
|
||||
function getFieldDef(schema, parentType, fieldNode) {
|
||||
var name = fieldNode.name.value;
|
||||
|
||||
if (name === _introspection.SchemaMetaFieldDef.name && schema.getQueryType() === parentType) {
|
||||
return _introspection.SchemaMetaFieldDef;
|
||||
}
|
||||
|
||||
if (name === _introspection.TypeMetaFieldDef.name && schema.getQueryType() === parentType) {
|
||||
return _introspection.TypeMetaFieldDef;
|
||||
}
|
||||
|
||||
if (name === _introspection.TypeNameMetaFieldDef.name && (0, _definition.isCompositeType)(parentType)) {
|
||||
return _introspection.TypeNameMetaFieldDef;
|
||||
}
|
||||
|
||||
if ((0, _definition.isObjectType)(parentType) || (0, _definition.isInterfaceType)(parentType)) {
|
||||
return parentType.getFields()[name];
|
||||
}
|
||||
}
|
||||
316
node_modules/graphql/utilities/TypeInfo.js.flow
generated
vendored
Normal file
316
node_modules/graphql/utilities/TypeInfo.js.flow
generated
vendored
Normal file
@@ -0,0 +1,316 @@
|
||||
// @flow strict
|
||||
|
||||
import find from '../polyfills/find';
|
||||
|
||||
import { Kind } from '../language/kinds';
|
||||
import { type ASTNode, type FieldNode } from '../language/ast';
|
||||
|
||||
import { type GraphQLSchema } from '../type/schema';
|
||||
import { type GraphQLDirective } from '../type/directives';
|
||||
import {
|
||||
type GraphQLType,
|
||||
type GraphQLInputType,
|
||||
type GraphQLOutputType,
|
||||
type GraphQLCompositeType,
|
||||
type GraphQLField,
|
||||
type GraphQLArgument,
|
||||
type GraphQLInputField,
|
||||
type GraphQLEnumValue,
|
||||
isObjectType,
|
||||
isInterfaceType,
|
||||
isEnumType,
|
||||
isInputObjectType,
|
||||
isListType,
|
||||
isCompositeType,
|
||||
isInputType,
|
||||
isOutputType,
|
||||
getNullableType,
|
||||
getNamedType,
|
||||
} from '../type/definition';
|
||||
import {
|
||||
SchemaMetaFieldDef,
|
||||
TypeMetaFieldDef,
|
||||
TypeNameMetaFieldDef,
|
||||
} from '../type/introspection';
|
||||
|
||||
import { typeFromAST } from './typeFromAST';
|
||||
|
||||
/**
|
||||
* TypeInfo is a utility class which, given a GraphQL schema, can keep track
|
||||
* of the current field and type definitions at any point in a GraphQL document
|
||||
* AST during a recursive descent by calling `enter(node)` and `leave(node)`.
|
||||
*/
|
||||
export class TypeInfo {
|
||||
_schema: GraphQLSchema;
|
||||
_typeStack: Array<?GraphQLOutputType>;
|
||||
_parentTypeStack: Array<?GraphQLCompositeType>;
|
||||
_inputTypeStack: Array<?GraphQLInputType>;
|
||||
_fieldDefStack: Array<?GraphQLField<mixed, mixed>>;
|
||||
_defaultValueStack: Array<?mixed>;
|
||||
_directive: ?GraphQLDirective;
|
||||
_argument: ?GraphQLArgument;
|
||||
_enumValue: ?GraphQLEnumValue;
|
||||
_getFieldDef: typeof getFieldDef;
|
||||
|
||||
constructor(
|
||||
schema: GraphQLSchema,
|
||||
// NOTE: this experimental optional second parameter is only needed in order
|
||||
// to support non-spec-compliant codebases. You should never need to use it.
|
||||
// It may disappear in the future.
|
||||
getFieldDefFn?: typeof getFieldDef,
|
||||
// Initial type may be provided in rare cases to facilitate traversals
|
||||
// beginning somewhere other than documents.
|
||||
initialType?: GraphQLType,
|
||||
): void {
|
||||
this._schema = schema;
|
||||
this._typeStack = [];
|
||||
this._parentTypeStack = [];
|
||||
this._inputTypeStack = [];
|
||||
this._fieldDefStack = [];
|
||||
this._defaultValueStack = [];
|
||||
this._directive = null;
|
||||
this._argument = null;
|
||||
this._enumValue = null;
|
||||
this._getFieldDef = getFieldDefFn || getFieldDef;
|
||||
if (initialType) {
|
||||
if (isInputType(initialType)) {
|
||||
this._inputTypeStack.push(initialType);
|
||||
}
|
||||
if (isCompositeType(initialType)) {
|
||||
this._parentTypeStack.push(initialType);
|
||||
}
|
||||
if (isOutputType(initialType)) {
|
||||
this._typeStack.push(initialType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getType(): ?GraphQLOutputType {
|
||||
if (this._typeStack.length > 0) {
|
||||
return this._typeStack[this._typeStack.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
getParentType(): ?GraphQLCompositeType {
|
||||
if (this._parentTypeStack.length > 0) {
|
||||
return this._parentTypeStack[this._parentTypeStack.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
getInputType(): ?GraphQLInputType {
|
||||
if (this._inputTypeStack.length > 0) {
|
||||
return this._inputTypeStack[this._inputTypeStack.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
getParentInputType(): ?GraphQLInputType {
|
||||
if (this._inputTypeStack.length > 1) {
|
||||
return this._inputTypeStack[this._inputTypeStack.length - 2];
|
||||
}
|
||||
}
|
||||
|
||||
getFieldDef(): ?GraphQLField<mixed, mixed> {
|
||||
if (this._fieldDefStack.length > 0) {
|
||||
return this._fieldDefStack[this._fieldDefStack.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
getDefaultValue(): ?mixed {
|
||||
if (this._defaultValueStack.length > 0) {
|
||||
return this._defaultValueStack[this._defaultValueStack.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
getDirective(): ?GraphQLDirective {
|
||||
return this._directive;
|
||||
}
|
||||
|
||||
getArgument(): ?GraphQLArgument {
|
||||
return this._argument;
|
||||
}
|
||||
|
||||
getEnumValue(): ?GraphQLEnumValue {
|
||||
return this._enumValue;
|
||||
}
|
||||
|
||||
enter(node: ASTNode) {
|
||||
const schema = this._schema;
|
||||
// Note: many of the types below are explicitly typed as "mixed" to drop
|
||||
// any assumptions of a valid schema to ensure runtime types are properly
|
||||
// checked before continuing since TypeInfo is used as part of validation
|
||||
// which occurs before guarantees of schema and document validity.
|
||||
switch (node.kind) {
|
||||
case Kind.SELECTION_SET: {
|
||||
const namedType: mixed = getNamedType(this.getType());
|
||||
this._parentTypeStack.push(
|
||||
isCompositeType(namedType) ? namedType : undefined,
|
||||
);
|
||||
break;
|
||||
}
|
||||
case Kind.FIELD: {
|
||||
const parentType = this.getParentType();
|
||||
let fieldDef;
|
||||
let fieldType: mixed;
|
||||
if (parentType) {
|
||||
fieldDef = this._getFieldDef(schema, parentType, node);
|
||||
if (fieldDef) {
|
||||
fieldType = fieldDef.type;
|
||||
}
|
||||
}
|
||||
this._fieldDefStack.push(fieldDef);
|
||||
this._typeStack.push(isOutputType(fieldType) ? fieldType : undefined);
|
||||
break;
|
||||
}
|
||||
case Kind.DIRECTIVE:
|
||||
this._directive = schema.getDirective(node.name.value);
|
||||
break;
|
||||
case Kind.OPERATION_DEFINITION: {
|
||||
let type: mixed;
|
||||
if (node.operation === 'query') {
|
||||
type = schema.getQueryType();
|
||||
} else if (node.operation === 'mutation') {
|
||||
type = schema.getMutationType();
|
||||
} else if (node.operation === 'subscription') {
|
||||
type = schema.getSubscriptionType();
|
||||
}
|
||||
this._typeStack.push(isObjectType(type) ? type : undefined);
|
||||
break;
|
||||
}
|
||||
case Kind.INLINE_FRAGMENT:
|
||||
case Kind.FRAGMENT_DEFINITION: {
|
||||
const typeConditionAST = node.typeCondition;
|
||||
const outputType: mixed = typeConditionAST
|
||||
? typeFromAST(schema, typeConditionAST)
|
||||
: getNamedType(this.getType());
|
||||
this._typeStack.push(isOutputType(outputType) ? outputType : undefined);
|
||||
break;
|
||||
}
|
||||
case Kind.VARIABLE_DEFINITION: {
|
||||
const inputType: mixed = typeFromAST(schema, node.type);
|
||||
this._inputTypeStack.push(
|
||||
isInputType(inputType) ? inputType : undefined,
|
||||
);
|
||||
break;
|
||||
}
|
||||
case Kind.ARGUMENT: {
|
||||
let argDef;
|
||||
let argType: mixed;
|
||||
const fieldOrDirective = this.getDirective() || this.getFieldDef();
|
||||
if (fieldOrDirective) {
|
||||
argDef = find(
|
||||
fieldOrDirective.args,
|
||||
arg => arg.name === node.name.value,
|
||||
);
|
||||
if (argDef) {
|
||||
argType = argDef.type;
|
||||
}
|
||||
}
|
||||
this._argument = argDef;
|
||||
this._defaultValueStack.push(argDef ? argDef.defaultValue : undefined);
|
||||
this._inputTypeStack.push(isInputType(argType) ? argType : undefined);
|
||||
break;
|
||||
}
|
||||
case Kind.LIST: {
|
||||
const listType: mixed = getNullableType(this.getInputType());
|
||||
const itemType: mixed = isListType(listType)
|
||||
? listType.ofType
|
||||
: listType;
|
||||
// List positions never have a default value.
|
||||
this._defaultValueStack.push(undefined);
|
||||
this._inputTypeStack.push(isInputType(itemType) ? itemType : undefined);
|
||||
break;
|
||||
}
|
||||
case Kind.OBJECT_FIELD: {
|
||||
const objectType: mixed = getNamedType(this.getInputType());
|
||||
let inputFieldType: GraphQLInputType | void;
|
||||
let inputField: GraphQLInputField | void;
|
||||
if (isInputObjectType(objectType)) {
|
||||
inputField = objectType.getFields()[node.name.value];
|
||||
if (inputField) {
|
||||
inputFieldType = inputField.type;
|
||||
}
|
||||
}
|
||||
this._defaultValueStack.push(
|
||||
inputField ? inputField.defaultValue : undefined,
|
||||
);
|
||||
this._inputTypeStack.push(
|
||||
isInputType(inputFieldType) ? inputFieldType : undefined,
|
||||
);
|
||||
break;
|
||||
}
|
||||
case Kind.ENUM: {
|
||||
const enumType: mixed = getNamedType(this.getInputType());
|
||||
let enumValue;
|
||||
if (isEnumType(enumType)) {
|
||||
enumValue = enumType.getValue(node.value);
|
||||
}
|
||||
this._enumValue = enumValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
leave(node: ASTNode) {
|
||||
switch (node.kind) {
|
||||
case Kind.SELECTION_SET:
|
||||
this._parentTypeStack.pop();
|
||||
break;
|
||||
case Kind.FIELD:
|
||||
this._fieldDefStack.pop();
|
||||
this._typeStack.pop();
|
||||
break;
|
||||
case Kind.DIRECTIVE:
|
||||
this._directive = null;
|
||||
break;
|
||||
case Kind.OPERATION_DEFINITION:
|
||||
case Kind.INLINE_FRAGMENT:
|
||||
case Kind.FRAGMENT_DEFINITION:
|
||||
this._typeStack.pop();
|
||||
break;
|
||||
case Kind.VARIABLE_DEFINITION:
|
||||
this._inputTypeStack.pop();
|
||||
break;
|
||||
case Kind.ARGUMENT:
|
||||
this._argument = null;
|
||||
this._defaultValueStack.pop();
|
||||
this._inputTypeStack.pop();
|
||||
break;
|
||||
case Kind.LIST:
|
||||
case Kind.OBJECT_FIELD:
|
||||
this._defaultValueStack.pop();
|
||||
this._inputTypeStack.pop();
|
||||
break;
|
||||
case Kind.ENUM:
|
||||
this._enumValue = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not exactly the same as the executor's definition of getFieldDef, in this
|
||||
* statically evaluated environment we do not always have an Object type,
|
||||
* and need to handle Interface and Union types.
|
||||
*/
|
||||
function getFieldDef(
|
||||
schema: GraphQLSchema,
|
||||
parentType: GraphQLType,
|
||||
fieldNode: FieldNode,
|
||||
): ?GraphQLField<mixed, mixed> {
|
||||
const name = fieldNode.name.value;
|
||||
if (
|
||||
name === SchemaMetaFieldDef.name &&
|
||||
schema.getQueryType() === parentType
|
||||
) {
|
||||
return SchemaMetaFieldDef;
|
||||
}
|
||||
if (name === TypeMetaFieldDef.name && schema.getQueryType() === parentType) {
|
||||
return TypeMetaFieldDef;
|
||||
}
|
||||
if (name === TypeNameMetaFieldDef.name && isCompositeType(parentType)) {
|
||||
return TypeNameMetaFieldDef;
|
||||
}
|
||||
if (isObjectType(parentType) || isInterfaceType(parentType)) {
|
||||
return parentType.getFields()[name];
|
||||
}
|
||||
}
|
||||
327
node_modules/graphql/utilities/TypeInfo.mjs
generated
vendored
Normal file
327
node_modules/graphql/utilities/TypeInfo.mjs
generated
vendored
Normal file
@@ -0,0 +1,327 @@
|
||||
import find from '../polyfills/find';
|
||||
import { Kind } from '../language/kinds';
|
||||
import { isObjectType, isInterfaceType, isEnumType, isInputObjectType, isListType, isCompositeType, isInputType, isOutputType, getNullableType, getNamedType } from '../type/definition';
|
||||
import { SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef } from '../type/introspection';
|
||||
import { typeFromAST } from './typeFromAST';
|
||||
/**
|
||||
* TypeInfo is a utility class which, given a GraphQL schema, can keep track
|
||||
* of the current field and type definitions at any point in a GraphQL document
|
||||
* AST during a recursive descent by calling `enter(node)` and `leave(node)`.
|
||||
*/
|
||||
|
||||
export var TypeInfo =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function TypeInfo(schema, // NOTE: this experimental optional second parameter is only needed in order
|
||||
// to support non-spec-compliant codebases. You should never need to use it.
|
||||
// It may disappear in the future.
|
||||
getFieldDefFn, // Initial type may be provided in rare cases to facilitate traversals
|
||||
// beginning somewhere other than documents.
|
||||
initialType) {
|
||||
this._schema = schema;
|
||||
this._typeStack = [];
|
||||
this._parentTypeStack = [];
|
||||
this._inputTypeStack = [];
|
||||
this._fieldDefStack = [];
|
||||
this._defaultValueStack = [];
|
||||
this._directive = null;
|
||||
this._argument = null;
|
||||
this._enumValue = null;
|
||||
this._getFieldDef = getFieldDefFn || getFieldDef;
|
||||
|
||||
if (initialType) {
|
||||
if (isInputType(initialType)) {
|
||||
this._inputTypeStack.push(initialType);
|
||||
}
|
||||
|
||||
if (isCompositeType(initialType)) {
|
||||
this._parentTypeStack.push(initialType);
|
||||
}
|
||||
|
||||
if (isOutputType(initialType)) {
|
||||
this._typeStack.push(initialType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _proto = TypeInfo.prototype;
|
||||
|
||||
_proto.getType = function getType() {
|
||||
if (this._typeStack.length > 0) {
|
||||
return this._typeStack[this._typeStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getParentType = function getParentType() {
|
||||
if (this._parentTypeStack.length > 0) {
|
||||
return this._parentTypeStack[this._parentTypeStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getInputType = function getInputType() {
|
||||
if (this._inputTypeStack.length > 0) {
|
||||
return this._inputTypeStack[this._inputTypeStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getParentInputType = function getParentInputType() {
|
||||
if (this._inputTypeStack.length > 1) {
|
||||
return this._inputTypeStack[this._inputTypeStack.length - 2];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getFieldDef = function getFieldDef() {
|
||||
if (this._fieldDefStack.length > 0) {
|
||||
return this._fieldDefStack[this._fieldDefStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getDefaultValue = function getDefaultValue() {
|
||||
if (this._defaultValueStack.length > 0) {
|
||||
return this._defaultValueStack[this._defaultValueStack.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getDirective = function getDirective() {
|
||||
return this._directive;
|
||||
};
|
||||
|
||||
_proto.getArgument = function getArgument() {
|
||||
return this._argument;
|
||||
};
|
||||
|
||||
_proto.getEnumValue = function getEnumValue() {
|
||||
return this._enumValue;
|
||||
};
|
||||
|
||||
_proto.enter = function enter(node) {
|
||||
var schema = this._schema; // Note: many of the types below are explicitly typed as "mixed" to drop
|
||||
// any assumptions of a valid schema to ensure runtime types are properly
|
||||
// checked before continuing since TypeInfo is used as part of validation
|
||||
// which occurs before guarantees of schema and document validity.
|
||||
|
||||
switch (node.kind) {
|
||||
case Kind.SELECTION_SET:
|
||||
{
|
||||
var namedType = getNamedType(this.getType());
|
||||
|
||||
this._parentTypeStack.push(isCompositeType(namedType) ? namedType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind.FIELD:
|
||||
{
|
||||
var parentType = this.getParentType();
|
||||
var fieldDef;
|
||||
var fieldType;
|
||||
|
||||
if (parentType) {
|
||||
fieldDef = this._getFieldDef(schema, parentType, node);
|
||||
|
||||
if (fieldDef) {
|
||||
fieldType = fieldDef.type;
|
||||
}
|
||||
}
|
||||
|
||||
this._fieldDefStack.push(fieldDef);
|
||||
|
||||
this._typeStack.push(isOutputType(fieldType) ? fieldType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind.DIRECTIVE:
|
||||
this._directive = schema.getDirective(node.name.value);
|
||||
break;
|
||||
|
||||
case Kind.OPERATION_DEFINITION:
|
||||
{
|
||||
var type;
|
||||
|
||||
if (node.operation === 'query') {
|
||||
type = schema.getQueryType();
|
||||
} else if (node.operation === 'mutation') {
|
||||
type = schema.getMutationType();
|
||||
} else if (node.operation === 'subscription') {
|
||||
type = schema.getSubscriptionType();
|
||||
}
|
||||
|
||||
this._typeStack.push(isObjectType(type) ? type : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind.INLINE_FRAGMENT:
|
||||
case Kind.FRAGMENT_DEFINITION:
|
||||
{
|
||||
var typeConditionAST = node.typeCondition;
|
||||
var outputType = typeConditionAST ? typeFromAST(schema, typeConditionAST) : getNamedType(this.getType());
|
||||
|
||||
this._typeStack.push(isOutputType(outputType) ? outputType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind.VARIABLE_DEFINITION:
|
||||
{
|
||||
var inputType = typeFromAST(schema, node.type);
|
||||
|
||||
this._inputTypeStack.push(isInputType(inputType) ? inputType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind.ARGUMENT:
|
||||
{
|
||||
var argDef;
|
||||
var argType;
|
||||
var fieldOrDirective = this.getDirective() || this.getFieldDef();
|
||||
|
||||
if (fieldOrDirective) {
|
||||
argDef = find(fieldOrDirective.args, function (arg) {
|
||||
return arg.name === node.name.value;
|
||||
});
|
||||
|
||||
if (argDef) {
|
||||
argType = argDef.type;
|
||||
}
|
||||
}
|
||||
|
||||
this._argument = argDef;
|
||||
|
||||
this._defaultValueStack.push(argDef ? argDef.defaultValue : undefined);
|
||||
|
||||
this._inputTypeStack.push(isInputType(argType) ? argType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind.LIST:
|
||||
{
|
||||
var listType = getNullableType(this.getInputType());
|
||||
var itemType = isListType(listType) ? listType.ofType : listType; // List positions never have a default value.
|
||||
|
||||
this._defaultValueStack.push(undefined);
|
||||
|
||||
this._inputTypeStack.push(isInputType(itemType) ? itemType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind.OBJECT_FIELD:
|
||||
{
|
||||
var objectType = getNamedType(this.getInputType());
|
||||
var inputFieldType;
|
||||
var inputField;
|
||||
|
||||
if (isInputObjectType(objectType)) {
|
||||
inputField = objectType.getFields()[node.name.value];
|
||||
|
||||
if (inputField) {
|
||||
inputFieldType = inputField.type;
|
||||
}
|
||||
}
|
||||
|
||||
this._defaultValueStack.push(inputField ? inputField.defaultValue : undefined);
|
||||
|
||||
this._inputTypeStack.push(isInputType(inputFieldType) ? inputFieldType : undefined);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind.ENUM:
|
||||
{
|
||||
var enumType = getNamedType(this.getInputType());
|
||||
var enumValue;
|
||||
|
||||
if (isEnumType(enumType)) {
|
||||
enumValue = enumType.getValue(node.value);
|
||||
}
|
||||
|
||||
this._enumValue = enumValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_proto.leave = function leave(node) {
|
||||
switch (node.kind) {
|
||||
case Kind.SELECTION_SET:
|
||||
this._parentTypeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case Kind.FIELD:
|
||||
this._fieldDefStack.pop();
|
||||
|
||||
this._typeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case Kind.DIRECTIVE:
|
||||
this._directive = null;
|
||||
break;
|
||||
|
||||
case Kind.OPERATION_DEFINITION:
|
||||
case Kind.INLINE_FRAGMENT:
|
||||
case Kind.FRAGMENT_DEFINITION:
|
||||
this._typeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case Kind.VARIABLE_DEFINITION:
|
||||
this._inputTypeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case Kind.ARGUMENT:
|
||||
this._argument = null;
|
||||
|
||||
this._defaultValueStack.pop();
|
||||
|
||||
this._inputTypeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case Kind.LIST:
|
||||
case Kind.OBJECT_FIELD:
|
||||
this._defaultValueStack.pop();
|
||||
|
||||
this._inputTypeStack.pop();
|
||||
|
||||
break;
|
||||
|
||||
case Kind.ENUM:
|
||||
this._enumValue = null;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
return TypeInfo;
|
||||
}();
|
||||
/**
|
||||
* Not exactly the same as the executor's definition of getFieldDef, in this
|
||||
* statically evaluated environment we do not always have an Object type,
|
||||
* and need to handle Interface and Union types.
|
||||
*/
|
||||
|
||||
function getFieldDef(schema, parentType, fieldNode) {
|
||||
var name = fieldNode.name.value;
|
||||
|
||||
if (name === SchemaMetaFieldDef.name && schema.getQueryType() === parentType) {
|
||||
return SchemaMetaFieldDef;
|
||||
}
|
||||
|
||||
if (name === TypeMetaFieldDef.name && schema.getQueryType() === parentType) {
|
||||
return TypeMetaFieldDef;
|
||||
}
|
||||
|
||||
if (name === TypeNameMetaFieldDef.name && isCompositeType(parentType)) {
|
||||
return TypeNameMetaFieldDef;
|
||||
}
|
||||
|
||||
if (isObjectType(parentType) || isInterfaceType(parentType)) {
|
||||
return parentType.getFields()[name];
|
||||
}
|
||||
}
|
||||
15
node_modules/graphql/utilities/assertValidName.d.ts
generated
vendored
Normal file
15
node_modules/graphql/utilities/assertValidName.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { ASTNode } from '../language/ast';
|
||||
|
||||
/**
|
||||
* Upholds the spec rules about naming.
|
||||
*/
|
||||
export function assertValidName(name: string): string;
|
||||
|
||||
/**
|
||||
* Returns an Error if a name is invalid.
|
||||
*/
|
||||
export function isValidNameError(
|
||||
name: string,
|
||||
node?: ASTNode | undefined,
|
||||
): GraphQLError | undefined;
|
||||
44
node_modules/graphql/utilities/assertValidName.js
generated
vendored
Normal file
44
node_modules/graphql/utilities/assertValidName.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.assertValidName = assertValidName;
|
||||
exports.isValidNameError = isValidNameError;
|
||||
|
||||
var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
|
||||
|
||||
var _GraphQLError = require("../error/GraphQLError");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
|
||||
/**
|
||||
* Upholds the spec rules about naming.
|
||||
*/
|
||||
|
||||
function assertValidName(name) {
|
||||
var error = isValidNameError(name);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* Returns an Error if a name is invalid.
|
||||
*/
|
||||
|
||||
|
||||
function isValidNameError(name, node) {
|
||||
typeof name === 'string' || (0, _devAssert.default)(0, 'Expected string');
|
||||
|
||||
if (name.length > 1 && name[0] === '_' && name[1] === '_') {
|
||||
return new _GraphQLError.GraphQLError("Name \"".concat(name, "\" must not begin with \"__\", which is reserved by GraphQL introspection."), node);
|
||||
}
|
||||
|
||||
if (!NAME_RX.test(name)) {
|
||||
return new _GraphQLError.GraphQLError("Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but \"".concat(name, "\" does not."), node);
|
||||
}
|
||||
}
|
||||
41
node_modules/graphql/utilities/assertValidName.js.flow
generated
vendored
Normal file
41
node_modules/graphql/utilities/assertValidName.js.flow
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// @flow strict
|
||||
|
||||
import devAssert from '../jsutils/devAssert';
|
||||
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { type ASTNode } from '../language/ast';
|
||||
|
||||
const NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
|
||||
|
||||
/**
|
||||
* Upholds the spec rules about naming.
|
||||
*/
|
||||
export function assertValidName(name: string): string {
|
||||
const error = isValidNameError(name);
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Error if a name is invalid.
|
||||
*/
|
||||
export function isValidNameError(
|
||||
name: string,
|
||||
node?: ASTNode | void,
|
||||
): GraphQLError | void {
|
||||
devAssert(typeof name === 'string', 'Expected string');
|
||||
if (name.length > 1 && name[0] === '_' && name[1] === '_') {
|
||||
return new GraphQLError(
|
||||
`Name "${name}" must not begin with "__", which is reserved by GraphQL introspection.`,
|
||||
node,
|
||||
);
|
||||
}
|
||||
if (!NAME_RX.test(name)) {
|
||||
return new GraphQLError(
|
||||
`Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "${name}" does not.`,
|
||||
node,
|
||||
);
|
||||
}
|
||||
}
|
||||
31
node_modules/graphql/utilities/assertValidName.mjs
generated
vendored
Normal file
31
node_modules/graphql/utilities/assertValidName.mjs
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import devAssert from '../jsutils/devAssert';
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
var NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
|
||||
/**
|
||||
* Upholds the spec rules about naming.
|
||||
*/
|
||||
|
||||
export function assertValidName(name) {
|
||||
var error = isValidNameError(name);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* Returns an Error if a name is invalid.
|
||||
*/
|
||||
|
||||
export function isValidNameError(name, node) {
|
||||
typeof name === 'string' || devAssert(0, 'Expected string');
|
||||
|
||||
if (name.length > 1 && name[0] === '_' && name[1] === '_') {
|
||||
return new GraphQLError("Name \"".concat(name, "\" must not begin with \"__\", which is reserved by GraphQL introspection."), node);
|
||||
}
|
||||
|
||||
if (!NAME_RX.test(name)) {
|
||||
return new GraphQLError("Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but \"".concat(name, "\" does not."), node);
|
||||
}
|
||||
}
|
||||
25
node_modules/graphql/utilities/astFromValue.d.ts
generated
vendored
Normal file
25
node_modules/graphql/utilities/astFromValue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import Maybe from '../tsutils/Maybe';
|
||||
import { ValueNode } from '../language/ast';
|
||||
import { GraphQLInputType } from '../type/definition';
|
||||
|
||||
/**
|
||||
* Produces a GraphQL Value AST given a JavaScript value.
|
||||
*
|
||||
* A GraphQL type must be provided, which will be used to interpret different
|
||||
* JavaScript values.
|
||||
*
|
||||
* | JSON Value | GraphQL Value |
|
||||
* | ------------- | -------------------- |
|
||||
* | Object | Input Object |
|
||||
* | Array | List |
|
||||
* | Boolean | Boolean |
|
||||
* | String | String / Enum Value |
|
||||
* | Number | Int / Float |
|
||||
* | Mixed | Enum Value |
|
||||
* | null | NullValue |
|
||||
*
|
||||
*/
|
||||
export function astFromValue(
|
||||
value: any,
|
||||
type: GraphQLInputType,
|
||||
): Maybe<ValueNode>;
|
||||
191
node_modules/graphql/utilities/astFromValue.js
generated
vendored
Normal file
191
node_modules/graphql/utilities/astFromValue.js
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.astFromValue = astFromValue;
|
||||
|
||||
var _iterall = require("iterall");
|
||||
|
||||
var _objectValues3 = _interopRequireDefault(require("../polyfills/objectValues"));
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _isNullish = _interopRequireDefault(require("../jsutils/isNullish"));
|
||||
|
||||
var _isInvalid = _interopRequireDefault(require("../jsutils/isInvalid"));
|
||||
|
||||
var _isObjectLike = _interopRequireDefault(require("../jsutils/isObjectLike"));
|
||||
|
||||
var _kinds = require("../language/kinds");
|
||||
|
||||
var _scalars = require("../type/scalars");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Produces a GraphQL Value AST given a JavaScript value.
|
||||
*
|
||||
* A GraphQL type must be provided, which will be used to interpret different
|
||||
* JavaScript values.
|
||||
*
|
||||
* | JSON Value | GraphQL Value |
|
||||
* | ------------- | -------------------- |
|
||||
* | Object | Input Object |
|
||||
* | Array | List |
|
||||
* | Boolean | Boolean |
|
||||
* | String | String / Enum Value |
|
||||
* | Number | Int / Float |
|
||||
* | Mixed | Enum Value |
|
||||
* | null | NullValue |
|
||||
*
|
||||
*/
|
||||
function astFromValue(value, type) {
|
||||
if ((0, _definition.isNonNullType)(type)) {
|
||||
var astValue = astFromValue(value, type.ofType);
|
||||
|
||||
if (astValue && astValue.kind === _kinds.Kind.NULL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return astValue;
|
||||
} // only explicit null, not undefined, NaN
|
||||
|
||||
|
||||
if (value === null) {
|
||||
return {
|
||||
kind: _kinds.Kind.NULL
|
||||
};
|
||||
} // undefined, NaN
|
||||
|
||||
|
||||
if ((0, _isInvalid.default)(value)) {
|
||||
return null;
|
||||
} // Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
|
||||
// the value is not an array, convert the value using the list's item type.
|
||||
|
||||
|
||||
if ((0, _definition.isListType)(type)) {
|
||||
var itemType = type.ofType;
|
||||
|
||||
if ((0, _iterall.isCollection)(value)) {
|
||||
var valuesNodes = [];
|
||||
(0, _iterall.forEach)(value, function (item) {
|
||||
var itemNode = astFromValue(item, itemType);
|
||||
|
||||
if (itemNode) {
|
||||
valuesNodes.push(itemNode);
|
||||
}
|
||||
});
|
||||
return {
|
||||
kind: _kinds.Kind.LIST,
|
||||
values: valuesNodes
|
||||
};
|
||||
}
|
||||
|
||||
return astFromValue(value, itemType);
|
||||
} // Populate the fields of the input object by creating ASTs from each value
|
||||
// in the JavaScript object according to the fields in the input type.
|
||||
|
||||
|
||||
if ((0, _definition.isInputObjectType)(type)) {
|
||||
if (!(0, _isObjectLike.default)(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var fieldNodes = [];
|
||||
|
||||
for (var _i2 = 0, _objectValues2 = (0, _objectValues3.default)(type.getFields()); _i2 < _objectValues2.length; _i2++) {
|
||||
var field = _objectValues2[_i2];
|
||||
var fieldValue = astFromValue(value[field.name], field.type);
|
||||
|
||||
if (fieldValue) {
|
||||
fieldNodes.push({
|
||||
kind: _kinds.Kind.OBJECT_FIELD,
|
||||
name: {
|
||||
kind: _kinds.Kind.NAME,
|
||||
value: field.name
|
||||
},
|
||||
value: fieldValue
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
kind: _kinds.Kind.OBJECT,
|
||||
fields: fieldNodes
|
||||
};
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if ((0, _definition.isLeafType)(type)) {
|
||||
// Since value is an internally represented value, it must be serialized
|
||||
// to an externally represented value before converting into an AST.
|
||||
var serialized = type.serialize(value);
|
||||
|
||||
if ((0, _isNullish.default)(serialized)) {
|
||||
return null;
|
||||
} // Others serialize based on their corresponding JavaScript scalar types.
|
||||
|
||||
|
||||
if (typeof serialized === 'boolean') {
|
||||
return {
|
||||
kind: _kinds.Kind.BOOLEAN,
|
||||
value: serialized
|
||||
};
|
||||
} // JavaScript numbers can be Int or Float values.
|
||||
|
||||
|
||||
if (typeof serialized === 'number') {
|
||||
var stringNum = String(serialized);
|
||||
return integerStringRegExp.test(stringNum) ? {
|
||||
kind: _kinds.Kind.INT,
|
||||
value: stringNum
|
||||
} : {
|
||||
kind: _kinds.Kind.FLOAT,
|
||||
value: stringNum
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof serialized === 'string') {
|
||||
// Enum types use Enum literals.
|
||||
if ((0, _definition.isEnumType)(type)) {
|
||||
return {
|
||||
kind: _kinds.Kind.ENUM,
|
||||
value: serialized
|
||||
};
|
||||
} // ID types can use Int literals.
|
||||
|
||||
|
||||
if (type === _scalars.GraphQLID && integerStringRegExp.test(serialized)) {
|
||||
return {
|
||||
kind: _kinds.Kind.INT,
|
||||
value: serialized
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
kind: _kinds.Kind.STRING,
|
||||
value: serialized
|
||||
};
|
||||
}
|
||||
|
||||
throw new TypeError("Cannot convert value to AST: ".concat((0, _inspect.default)(serialized)));
|
||||
} // Not reachable. All possible input types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
(0, _invariant.default)(false, 'Unexpected input type: ' + (0, _inspect.default)(type));
|
||||
}
|
||||
/**
|
||||
* IntValue:
|
||||
* - NegativeSign? 0
|
||||
* - NegativeSign? NonZeroDigit ( Digit+ )?
|
||||
*/
|
||||
|
||||
|
||||
var integerStringRegExp = /^-?(?:0|[1-9][0-9]*)$/;
|
||||
149
node_modules/graphql/utilities/astFromValue.js.flow
generated
vendored
Normal file
149
node_modules/graphql/utilities/astFromValue.js.flow
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
// @flow strict
|
||||
|
||||
import { forEach, isCollection } from 'iterall';
|
||||
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import isNullish from '../jsutils/isNullish';
|
||||
import isInvalid from '../jsutils/isInvalid';
|
||||
import isObjectLike from '../jsutils/isObjectLike';
|
||||
|
||||
import { Kind } from '../language/kinds';
|
||||
import { type ValueNode } from '../language/ast';
|
||||
|
||||
import { GraphQLID } from '../type/scalars';
|
||||
import {
|
||||
type GraphQLInputType,
|
||||
isLeafType,
|
||||
isEnumType,
|
||||
isInputObjectType,
|
||||
isListType,
|
||||
isNonNullType,
|
||||
} from '../type/definition';
|
||||
|
||||
/**
|
||||
* Produces a GraphQL Value AST given a JavaScript value.
|
||||
*
|
||||
* A GraphQL type must be provided, which will be used to interpret different
|
||||
* JavaScript values.
|
||||
*
|
||||
* | JSON Value | GraphQL Value |
|
||||
* | ------------- | -------------------- |
|
||||
* | Object | Input Object |
|
||||
* | Array | List |
|
||||
* | Boolean | Boolean |
|
||||
* | String | String / Enum Value |
|
||||
* | Number | Int / Float |
|
||||
* | Mixed | Enum Value |
|
||||
* | null | NullValue |
|
||||
*
|
||||
*/
|
||||
export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode {
|
||||
if (isNonNullType(type)) {
|
||||
const astValue = astFromValue(value, type.ofType);
|
||||
if (astValue && astValue.kind === Kind.NULL) {
|
||||
return null;
|
||||
}
|
||||
return astValue;
|
||||
}
|
||||
|
||||
// only explicit null, not undefined, NaN
|
||||
if (value === null) {
|
||||
return { kind: Kind.NULL };
|
||||
}
|
||||
|
||||
// undefined, NaN
|
||||
if (isInvalid(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
|
||||
// the value is not an array, convert the value using the list's item type.
|
||||
if (isListType(type)) {
|
||||
const itemType = type.ofType;
|
||||
if (isCollection(value)) {
|
||||
const valuesNodes = [];
|
||||
forEach((value: any), item => {
|
||||
const itemNode = astFromValue(item, itemType);
|
||||
if (itemNode) {
|
||||
valuesNodes.push(itemNode);
|
||||
}
|
||||
});
|
||||
return { kind: Kind.LIST, values: valuesNodes };
|
||||
}
|
||||
return astFromValue(value, itemType);
|
||||
}
|
||||
|
||||
// Populate the fields of the input object by creating ASTs from each value
|
||||
// in the JavaScript object according to the fields in the input type.
|
||||
if (isInputObjectType(type)) {
|
||||
if (!isObjectLike(value)) {
|
||||
return null;
|
||||
}
|
||||
const fieldNodes = [];
|
||||
for (const field of objectValues(type.getFields())) {
|
||||
const fieldValue = astFromValue(value[field.name], field.type);
|
||||
if (fieldValue) {
|
||||
fieldNodes.push({
|
||||
kind: Kind.OBJECT_FIELD,
|
||||
name: { kind: Kind.NAME, value: field.name },
|
||||
value: fieldValue,
|
||||
});
|
||||
}
|
||||
}
|
||||
return { kind: Kind.OBJECT, fields: fieldNodes };
|
||||
}
|
||||
|
||||
if (isLeafType(type)) {
|
||||
// Since value is an internally represented value, it must be serialized
|
||||
// to an externally represented value before converting into an AST.
|
||||
const serialized = type.serialize(value);
|
||||
if (isNullish(serialized)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Others serialize based on their corresponding JavaScript scalar types.
|
||||
if (typeof serialized === 'boolean') {
|
||||
return { kind: Kind.BOOLEAN, value: serialized };
|
||||
}
|
||||
|
||||
// JavaScript numbers can be Int or Float values.
|
||||
if (typeof serialized === 'number') {
|
||||
const stringNum = String(serialized);
|
||||
return integerStringRegExp.test(stringNum)
|
||||
? { kind: Kind.INT, value: stringNum }
|
||||
: { kind: Kind.FLOAT, value: stringNum };
|
||||
}
|
||||
|
||||
if (typeof serialized === 'string') {
|
||||
// Enum types use Enum literals.
|
||||
if (isEnumType(type)) {
|
||||
return { kind: Kind.ENUM, value: serialized };
|
||||
}
|
||||
|
||||
// ID types can use Int literals.
|
||||
if (type === GraphQLID && integerStringRegExp.test(serialized)) {
|
||||
return { kind: Kind.INT, value: serialized };
|
||||
}
|
||||
|
||||
return {
|
||||
kind: Kind.STRING,
|
||||
value: serialized,
|
||||
};
|
||||
}
|
||||
|
||||
throw new TypeError(`Cannot convert value to AST: ${inspect(serialized)}`);
|
||||
}
|
||||
|
||||
// Not reachable. All possible input types have been considered.
|
||||
invariant(false, 'Unexpected input type: ' + inspect((type: empty)));
|
||||
}
|
||||
|
||||
/**
|
||||
* IntValue:
|
||||
* - NegativeSign? 0
|
||||
* - NegativeSign? NonZeroDigit ( Digit+ )?
|
||||
*/
|
||||
const integerStringRegExp = /^-?(?:0|[1-9][0-9]*)$/;
|
||||
172
node_modules/graphql/utilities/astFromValue.mjs
generated
vendored
Normal file
172
node_modules/graphql/utilities/astFromValue.mjs
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
import { forEach, isCollection } from 'iterall';
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import isNullish from '../jsutils/isNullish';
|
||||
import isInvalid from '../jsutils/isInvalid';
|
||||
import isObjectLike from '../jsutils/isObjectLike';
|
||||
import { Kind } from '../language/kinds';
|
||||
import { GraphQLID } from '../type/scalars';
|
||||
import { isLeafType, isEnumType, isInputObjectType, isListType, isNonNullType } from '../type/definition';
|
||||
/**
|
||||
* Produces a GraphQL Value AST given a JavaScript value.
|
||||
*
|
||||
* A GraphQL type must be provided, which will be used to interpret different
|
||||
* JavaScript values.
|
||||
*
|
||||
* | JSON Value | GraphQL Value |
|
||||
* | ------------- | -------------------- |
|
||||
* | Object | Input Object |
|
||||
* | Array | List |
|
||||
* | Boolean | Boolean |
|
||||
* | String | String / Enum Value |
|
||||
* | Number | Int / Float |
|
||||
* | Mixed | Enum Value |
|
||||
* | null | NullValue |
|
||||
*
|
||||
*/
|
||||
|
||||
export function astFromValue(value, type) {
|
||||
if (isNonNullType(type)) {
|
||||
var astValue = astFromValue(value, type.ofType);
|
||||
|
||||
if (astValue && astValue.kind === Kind.NULL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return astValue;
|
||||
} // only explicit null, not undefined, NaN
|
||||
|
||||
|
||||
if (value === null) {
|
||||
return {
|
||||
kind: Kind.NULL
|
||||
};
|
||||
} // undefined, NaN
|
||||
|
||||
|
||||
if (isInvalid(value)) {
|
||||
return null;
|
||||
} // Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
|
||||
// the value is not an array, convert the value using the list's item type.
|
||||
|
||||
|
||||
if (isListType(type)) {
|
||||
var itemType = type.ofType;
|
||||
|
||||
if (isCollection(value)) {
|
||||
var valuesNodes = [];
|
||||
forEach(value, function (item) {
|
||||
var itemNode = astFromValue(item, itemType);
|
||||
|
||||
if (itemNode) {
|
||||
valuesNodes.push(itemNode);
|
||||
}
|
||||
});
|
||||
return {
|
||||
kind: Kind.LIST,
|
||||
values: valuesNodes
|
||||
};
|
||||
}
|
||||
|
||||
return astFromValue(value, itemType);
|
||||
} // Populate the fields of the input object by creating ASTs from each value
|
||||
// in the JavaScript object according to the fields in the input type.
|
||||
|
||||
|
||||
if (isInputObjectType(type)) {
|
||||
if (!isObjectLike(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var fieldNodes = [];
|
||||
|
||||
for (var _i2 = 0, _objectValues2 = objectValues(type.getFields()); _i2 < _objectValues2.length; _i2++) {
|
||||
var field = _objectValues2[_i2];
|
||||
var fieldValue = astFromValue(value[field.name], field.type);
|
||||
|
||||
if (fieldValue) {
|
||||
fieldNodes.push({
|
||||
kind: Kind.OBJECT_FIELD,
|
||||
name: {
|
||||
kind: Kind.NAME,
|
||||
value: field.name
|
||||
},
|
||||
value: fieldValue
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
kind: Kind.OBJECT,
|
||||
fields: fieldNodes
|
||||
};
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (isLeafType(type)) {
|
||||
// Since value is an internally represented value, it must be serialized
|
||||
// to an externally represented value before converting into an AST.
|
||||
var serialized = type.serialize(value);
|
||||
|
||||
if (isNullish(serialized)) {
|
||||
return null;
|
||||
} // Others serialize based on their corresponding JavaScript scalar types.
|
||||
|
||||
|
||||
if (typeof serialized === 'boolean') {
|
||||
return {
|
||||
kind: Kind.BOOLEAN,
|
||||
value: serialized
|
||||
};
|
||||
} // JavaScript numbers can be Int or Float values.
|
||||
|
||||
|
||||
if (typeof serialized === 'number') {
|
||||
var stringNum = String(serialized);
|
||||
return integerStringRegExp.test(stringNum) ? {
|
||||
kind: Kind.INT,
|
||||
value: stringNum
|
||||
} : {
|
||||
kind: Kind.FLOAT,
|
||||
value: stringNum
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof serialized === 'string') {
|
||||
// Enum types use Enum literals.
|
||||
if (isEnumType(type)) {
|
||||
return {
|
||||
kind: Kind.ENUM,
|
||||
value: serialized
|
||||
};
|
||||
} // ID types can use Int literals.
|
||||
|
||||
|
||||
if (type === GraphQLID && integerStringRegExp.test(serialized)) {
|
||||
return {
|
||||
kind: Kind.INT,
|
||||
value: serialized
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
kind: Kind.STRING,
|
||||
value: serialized
|
||||
};
|
||||
}
|
||||
|
||||
throw new TypeError("Cannot convert value to AST: ".concat(inspect(serialized)));
|
||||
} // Not reachable. All possible input types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
invariant(false, 'Unexpected input type: ' + inspect(type));
|
||||
}
|
||||
/**
|
||||
* IntValue:
|
||||
* - NegativeSign? 0
|
||||
* - NegativeSign? NonZeroDigit ( Digit+ )?
|
||||
*/
|
||||
|
||||
var integerStringRegExp = /^-?(?:0|[1-9][0-9]*)$/;
|
||||
114
node_modules/graphql/utilities/buildASTSchema.d.ts
generated
vendored
Normal file
114
node_modules/graphql/utilities/buildASTSchema.d.ts
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
import Maybe from '../tsutils/Maybe';
|
||||
import {
|
||||
DocumentNode,
|
||||
Location,
|
||||
StringValueNode,
|
||||
TypeDefinitionNode,
|
||||
NamedTypeNode,
|
||||
DirectiveDefinitionNode,
|
||||
FieldDefinitionNode,
|
||||
InputValueDefinitionNode,
|
||||
EnumValueDefinitionNode,
|
||||
TypeNode,
|
||||
} from '../language/ast';
|
||||
import {
|
||||
GraphQLNamedType,
|
||||
GraphQLFieldConfig,
|
||||
GraphQLInputField,
|
||||
GraphQLEnumValueConfig,
|
||||
GraphQLType,
|
||||
GraphQLArgumentConfig,
|
||||
GraphQLInputFieldConfig,
|
||||
} from '../type/definition';
|
||||
import { GraphQLDirective } from '../type/directives';
|
||||
import { Source } from '../language/source';
|
||||
import { GraphQLSchema, GraphQLSchemaValidationOptions } from '../type/schema';
|
||||
import { ParseOptions } from '../language/parser';
|
||||
import { dedentBlockStringValue } from '../language/blockString';
|
||||
|
||||
interface BuildSchemaOptions extends GraphQLSchemaValidationOptions {
|
||||
/**
|
||||
* Descriptions are defined as preceding string literals, however an older
|
||||
* experimental version of the SDL supported preceding comments as
|
||||
* descriptions. Set to true to enable this deprecated behavior.
|
||||
* This option is provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
commentDescriptions?: boolean;
|
||||
|
||||
/**
|
||||
* Set to true to assume the SDL is valid.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
assumeValidSDL?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* This takes the ast of a schema document produced by the parse function in
|
||||
* src/language/parser.js.
|
||||
*
|
||||
* If no schema definition is provided, then it will look for types named Query
|
||||
* and Mutation.
|
||||
*
|
||||
* Given that AST it constructs a GraphQLSchema. The resulting schema
|
||||
* has no resolve methods, so execution will use default resolvers.
|
||||
*
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function buildASTSchema(
|
||||
documentAST: DocumentNode,
|
||||
options?: BuildSchemaOptions,
|
||||
): GraphQLSchema;
|
||||
|
||||
type TypeDefinitionsMap = { [key: string]: TypeDefinitionNode };
|
||||
type TypeResolver = (typeRef: NamedTypeNode) => GraphQLNamedType;
|
||||
|
||||
export class ASTDefinitionBuilder {
|
||||
constructor(options: Maybe<BuildSchemaOptions>, resolveType: TypeResolver);
|
||||
|
||||
getNamedType(node: NamedTypeNode): GraphQLNamedType;
|
||||
|
||||
getWrappedType(node: TypeNode): GraphQLType;
|
||||
|
||||
buildDirective(directive: DirectiveDefinitionNode): GraphQLDirective;
|
||||
|
||||
buildField(field: FieldDefinitionNode): GraphQLFieldConfig<any, any>;
|
||||
|
||||
buildArg(value: InputValueDefinitionNode): GraphQLArgumentConfig;
|
||||
|
||||
buildInputField(value: InputValueDefinitionNode): GraphQLInputFieldConfig;
|
||||
|
||||
buildEnumValue(value: EnumValueDefinitionNode): GraphQLEnumValueConfig;
|
||||
|
||||
buildType(node: NamedTypeNode | TypeDefinitionNode): GraphQLNamedType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an ast node, returns its string description.
|
||||
* @deprecated: provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function getDescription(
|
||||
node: { readonly description?: StringValueNode; readonly loc?: Location },
|
||||
options: Maybe<BuildSchemaOptions>,
|
||||
): string | undefined;
|
||||
|
||||
/**
|
||||
* A helper function to build a GraphQLSchema directly from a source
|
||||
* document.
|
||||
*/
|
||||
export function buildSchema(
|
||||
source: string | Source,
|
||||
options?: BuildSchemaOptions & ParseOptions,
|
||||
): GraphQLSchema;
|
||||
463
node_modules/graphql/utilities/buildASTSchema.js
generated
vendored
Normal file
463
node_modules/graphql/utilities/buildASTSchema.js
generated
vendored
Normal file
@@ -0,0 +1,463 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.buildASTSchema = buildASTSchema;
|
||||
exports.getDescription = getDescription;
|
||||
exports.buildSchema = buildSchema;
|
||||
exports.ASTDefinitionBuilder = void 0;
|
||||
|
||||
var _objectValues = _interopRequireDefault(require("../polyfills/objectValues"));
|
||||
|
||||
var _keyMap = _interopRequireDefault(require("../jsutils/keyMap"));
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
|
||||
|
||||
var _keyValMap = _interopRequireDefault(require("../jsutils/keyValMap"));
|
||||
|
||||
var _kinds = require("../language/kinds");
|
||||
|
||||
var _tokenKind = require("../language/tokenKind");
|
||||
|
||||
var _parser = require("../language/parser");
|
||||
|
||||
var _predicates = require("../language/predicates");
|
||||
|
||||
var _blockString = require("../language/blockString");
|
||||
|
||||
var _validate = require("../validation/validate");
|
||||
|
||||
var _values = require("../execution/values");
|
||||
|
||||
var _scalars = require("../type/scalars");
|
||||
|
||||
var _introspection = require("../type/introspection");
|
||||
|
||||
var _schema = require("../type/schema");
|
||||
|
||||
var _directives = require("../type/directives");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
var _valueFromAST = require("./valueFromAST");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* This takes the ast of a schema document produced by the parse function in
|
||||
* src/language/parser.js.
|
||||
*
|
||||
* If no schema definition is provided, then it will look for types named Query
|
||||
* and Mutation.
|
||||
*
|
||||
* Given that AST it constructs a GraphQLSchema. The resulting schema
|
||||
* has no resolve methods, so execution will use default resolvers.
|
||||
*
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
function buildASTSchema(documentAST, options) {
|
||||
documentAST && documentAST.kind === _kinds.Kind.DOCUMENT || (0, _devAssert.default)(0, 'Must provide valid Document AST');
|
||||
|
||||
if (!options || !(options.assumeValid || options.assumeValidSDL)) {
|
||||
(0, _validate.assertValidSDL)(documentAST);
|
||||
}
|
||||
|
||||
var schemaDef;
|
||||
var typeDefs = [];
|
||||
var directiveDefs = [];
|
||||
|
||||
for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
|
||||
var def = _documentAST$definiti2[_i2];
|
||||
|
||||
if (def.kind === _kinds.Kind.SCHEMA_DEFINITION) {
|
||||
schemaDef = def;
|
||||
} else if ((0, _predicates.isTypeDefinitionNode)(def)) {
|
||||
typeDefs.push(def);
|
||||
} else if (def.kind === _kinds.Kind.DIRECTIVE_DEFINITION) {
|
||||
directiveDefs.push(def);
|
||||
}
|
||||
}
|
||||
|
||||
var astBuilder = new ASTDefinitionBuilder(options, function (typeName) {
|
||||
var type = typeMap[typeName];
|
||||
|
||||
if (type === undefined) {
|
||||
throw new Error("Type \"".concat(typeName, "\" not found in document."));
|
||||
}
|
||||
|
||||
return type;
|
||||
});
|
||||
var typeMap = keyByNameNode(typeDefs, function (node) {
|
||||
return astBuilder.buildType(node);
|
||||
});
|
||||
var operationTypes = schemaDef ? getOperationTypes(schemaDef) : {
|
||||
query: 'Query',
|
||||
mutation: 'Mutation',
|
||||
subscription: 'Subscription'
|
||||
};
|
||||
var directives = directiveDefs.map(function (def) {
|
||||
return astBuilder.buildDirective(def);
|
||||
}); // If specified directives were not explicitly declared, add them.
|
||||
|
||||
if (!directives.some(function (directive) {
|
||||
return directive.name === 'skip';
|
||||
})) {
|
||||
directives.push(_directives.GraphQLSkipDirective);
|
||||
}
|
||||
|
||||
if (!directives.some(function (directive) {
|
||||
return directive.name === 'include';
|
||||
})) {
|
||||
directives.push(_directives.GraphQLIncludeDirective);
|
||||
}
|
||||
|
||||
if (!directives.some(function (directive) {
|
||||
return directive.name === 'deprecated';
|
||||
})) {
|
||||
directives.push(_directives.GraphQLDeprecatedDirective);
|
||||
}
|
||||
|
||||
return new _schema.GraphQLSchema({
|
||||
// Note: While this could make early assertions to get the correctly
|
||||
// typed values below, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
query: operationTypes.query ? typeMap[operationTypes.query] : null,
|
||||
mutation: operationTypes.mutation ? typeMap[operationTypes.mutation] : null,
|
||||
subscription: operationTypes.subscription ? typeMap[operationTypes.subscription] : null,
|
||||
types: (0, _objectValues.default)(typeMap),
|
||||
directives: directives,
|
||||
astNode: schemaDef,
|
||||
assumeValid: options && options.assumeValid,
|
||||
allowedLegacyNames: options && options.allowedLegacyNames
|
||||
});
|
||||
|
||||
function getOperationTypes(schema) {
|
||||
var opTypes = {};
|
||||
|
||||
for (var _i4 = 0, _schema$operationType2 = schema.operationTypes; _i4 < _schema$operationType2.length; _i4++) {
|
||||
var operationType = _schema$operationType2[_i4];
|
||||
opTypes[operationType.operation] = operationType.type.name.value;
|
||||
}
|
||||
|
||||
return opTypes;
|
||||
}
|
||||
}
|
||||
|
||||
var stdTypeMap = (0, _keyMap.default)(_scalars.specifiedScalarTypes.concat(_introspection.introspectionTypes), function (type) {
|
||||
return type.name;
|
||||
});
|
||||
|
||||
var ASTDefinitionBuilder =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function ASTDefinitionBuilder(options, resolveType) {
|
||||
this._options = options;
|
||||
this._resolveType = resolveType;
|
||||
}
|
||||
|
||||
var _proto = ASTDefinitionBuilder.prototype;
|
||||
|
||||
_proto.getNamedType = function getNamedType(node) {
|
||||
var name = node.name.value;
|
||||
return stdTypeMap[name] || this._resolveType(name);
|
||||
};
|
||||
|
||||
_proto.getWrappedType = function getWrappedType(node) {
|
||||
if (node.kind === _kinds.Kind.LIST_TYPE) {
|
||||
return new _definition.GraphQLList(this.getWrappedType(node.type));
|
||||
}
|
||||
|
||||
if (node.kind === _kinds.Kind.NON_NULL_TYPE) {
|
||||
return new _definition.GraphQLNonNull(this.getWrappedType(node.type));
|
||||
}
|
||||
|
||||
return this.getNamedType(node);
|
||||
};
|
||||
|
||||
_proto.buildDirective = function buildDirective(directive) {
|
||||
var _this = this;
|
||||
|
||||
var locations = directive.locations.map(function (_ref) {
|
||||
var value = _ref.value;
|
||||
return value;
|
||||
});
|
||||
return new _directives.GraphQLDirective({
|
||||
name: directive.name.value,
|
||||
description: getDescription(directive, this._options),
|
||||
locations: locations,
|
||||
isRepeatable: directive.repeatable,
|
||||
args: keyByNameNode(directive.arguments || [], function (arg) {
|
||||
return _this.buildArg(arg);
|
||||
}),
|
||||
astNode: directive
|
||||
});
|
||||
};
|
||||
|
||||
_proto.buildField = function buildField(field) {
|
||||
var _this2 = this;
|
||||
|
||||
return {
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// value, that would throw immediately while type system validation
|
||||
// with validateSchema() will produce more actionable results.
|
||||
type: this.getWrappedType(field.type),
|
||||
description: getDescription(field, this._options),
|
||||
args: keyByNameNode(field.arguments || [], function (arg) {
|
||||
return _this2.buildArg(arg);
|
||||
}),
|
||||
deprecationReason: getDeprecationReason(field),
|
||||
astNode: field
|
||||
};
|
||||
};
|
||||
|
||||
_proto.buildArg = function buildArg(value) {
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// value, that would throw immediately while type system validation
|
||||
// with validateSchema() will produce more actionable results.
|
||||
var type = this.getWrappedType(value.type);
|
||||
return {
|
||||
type: type,
|
||||
description: getDescription(value, this._options),
|
||||
defaultValue: (0, _valueFromAST.valueFromAST)(value.defaultValue, type),
|
||||
astNode: value
|
||||
};
|
||||
};
|
||||
|
||||
_proto.buildInputField = function buildInputField(value) {
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// value, that would throw immediately while type system validation
|
||||
// with validateSchema() will produce more actionable results.
|
||||
var type = this.getWrappedType(value.type);
|
||||
return {
|
||||
type: type,
|
||||
description: getDescription(value, this._options),
|
||||
defaultValue: (0, _valueFromAST.valueFromAST)(value.defaultValue, type),
|
||||
astNode: value
|
||||
};
|
||||
};
|
||||
|
||||
_proto.buildEnumValue = function buildEnumValue(value) {
|
||||
return {
|
||||
description: getDescription(value, this._options),
|
||||
deprecationReason: getDeprecationReason(value),
|
||||
astNode: value
|
||||
};
|
||||
};
|
||||
|
||||
_proto.buildType = function buildType(astNode) {
|
||||
var name = astNode.name.value;
|
||||
|
||||
if (stdTypeMap[name]) {
|
||||
return stdTypeMap[name];
|
||||
}
|
||||
|
||||
switch (astNode.kind) {
|
||||
case _kinds.Kind.OBJECT_TYPE_DEFINITION:
|
||||
return this._makeTypeDef(astNode);
|
||||
|
||||
case _kinds.Kind.INTERFACE_TYPE_DEFINITION:
|
||||
return this._makeInterfaceDef(astNode);
|
||||
|
||||
case _kinds.Kind.ENUM_TYPE_DEFINITION:
|
||||
return this._makeEnumDef(astNode);
|
||||
|
||||
case _kinds.Kind.UNION_TYPE_DEFINITION:
|
||||
return this._makeUnionDef(astNode);
|
||||
|
||||
case _kinds.Kind.SCALAR_TYPE_DEFINITION:
|
||||
return this._makeScalarDef(astNode);
|
||||
|
||||
case _kinds.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
||||
return this._makeInputObjectDef(astNode);
|
||||
} // Not reachable. All possible type definition nodes have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
(0, _invariant.default)(false, 'Unexpected type definition node: ' + (0, _inspect.default)(astNode));
|
||||
};
|
||||
|
||||
_proto._makeTypeDef = function _makeTypeDef(astNode) {
|
||||
var _this3 = this;
|
||||
|
||||
var interfaceNodes = astNode.interfaces;
|
||||
var fieldNodes = astNode.fields; // Note: While this could make assertions to get the correctly typed
|
||||
// values below, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
|
||||
var interfaces = interfaceNodes && interfaceNodes.length > 0 ? function () {
|
||||
return interfaceNodes.map(function (ref) {
|
||||
return _this3.getNamedType(ref);
|
||||
});
|
||||
} : [];
|
||||
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
||||
return keyByNameNode(fieldNodes, function (field) {
|
||||
return _this3.buildField(field);
|
||||
});
|
||||
} : Object.create(null);
|
||||
return new _definition.GraphQLObjectType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
interfaces: interfaces,
|
||||
fields: fields,
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeInterfaceDef = function _makeInterfaceDef(astNode) {
|
||||
var _this4 = this;
|
||||
|
||||
var fieldNodes = astNode.fields;
|
||||
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
||||
return keyByNameNode(fieldNodes, function (field) {
|
||||
return _this4.buildField(field);
|
||||
});
|
||||
} : Object.create(null);
|
||||
return new _definition.GraphQLInterfaceType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
fields: fields,
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeEnumDef = function _makeEnumDef(astNode) {
|
||||
var _this5 = this;
|
||||
|
||||
var valueNodes = astNode.values || [];
|
||||
return new _definition.GraphQLEnumType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
values: keyByNameNode(valueNodes, function (value) {
|
||||
return _this5.buildEnumValue(value);
|
||||
}),
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeUnionDef = function _makeUnionDef(astNode) {
|
||||
var _this6 = this;
|
||||
|
||||
var typeNodes = astNode.types; // Note: While this could make assertions to get the correctly typed
|
||||
// values below, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
|
||||
var types = typeNodes && typeNodes.length > 0 ? function () {
|
||||
return typeNodes.map(function (ref) {
|
||||
return _this6.getNamedType(ref);
|
||||
});
|
||||
} : [];
|
||||
return new _definition.GraphQLUnionType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
types: types,
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeScalarDef = function _makeScalarDef(astNode) {
|
||||
return new _definition.GraphQLScalarType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeInputObjectDef = function _makeInputObjectDef(def) {
|
||||
var _this7 = this;
|
||||
|
||||
var fields = def.fields;
|
||||
return new _definition.GraphQLInputObjectType({
|
||||
name: def.name.value,
|
||||
description: getDescription(def, this._options),
|
||||
fields: fields ? function () {
|
||||
return keyByNameNode(fields, function (field) {
|
||||
return _this7.buildInputField(field);
|
||||
});
|
||||
} : Object.create(null),
|
||||
astNode: def
|
||||
});
|
||||
};
|
||||
|
||||
return ASTDefinitionBuilder;
|
||||
}();
|
||||
|
||||
exports.ASTDefinitionBuilder = ASTDefinitionBuilder;
|
||||
|
||||
function keyByNameNode(list, valFn) {
|
||||
return (0, _keyValMap.default)(list, function (_ref2) {
|
||||
var name = _ref2.name;
|
||||
return name.value;
|
||||
}, valFn);
|
||||
}
|
||||
/**
|
||||
* Given a field or enum value node, returns the string value for the
|
||||
* deprecation reason.
|
||||
*/
|
||||
|
||||
|
||||
function getDeprecationReason(node) {
|
||||
var deprecated = (0, _values.getDirectiveValues)(_directives.GraphQLDeprecatedDirective, node);
|
||||
return deprecated && deprecated.reason;
|
||||
}
|
||||
/**
|
||||
* Given an ast node, returns its string description.
|
||||
* @deprecated: provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
function getDescription(node, options) {
|
||||
if (node.description) {
|
||||
return node.description.value;
|
||||
}
|
||||
|
||||
if (options && options.commentDescriptions) {
|
||||
var rawValue = getLeadingCommentBlock(node);
|
||||
|
||||
if (rawValue !== undefined) {
|
||||
return (0, _blockString.dedentBlockStringValue)('\n' + rawValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getLeadingCommentBlock(node) {
|
||||
var loc = node.loc;
|
||||
|
||||
if (!loc) {
|
||||
return;
|
||||
}
|
||||
|
||||
var comments = [];
|
||||
var token = loc.startToken.prev;
|
||||
|
||||
while (token && token.kind === _tokenKind.TokenKind.COMMENT && token.next && token.prev && token.line + 1 === token.next.line && token.line !== token.prev.line) {
|
||||
var value = String(token.value);
|
||||
comments.push(value);
|
||||
token = token.prev;
|
||||
}
|
||||
|
||||
return comments.reverse().join('\n');
|
||||
}
|
||||
/**
|
||||
* A helper function to build a GraphQLSchema directly from a source
|
||||
* document.
|
||||
*/
|
||||
|
||||
|
||||
function buildSchema(source, options) {
|
||||
return buildASTSchema((0, _parser.parse)(source, options), options);
|
||||
}
|
||||
491
node_modules/graphql/utilities/buildASTSchema.js.flow
generated
vendored
Normal file
491
node_modules/graphql/utilities/buildASTSchema.js.flow
generated
vendored
Normal file
@@ -0,0 +1,491 @@
|
||||
// @flow strict
|
||||
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
|
||||
import keyMap from '../jsutils/keyMap';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import devAssert from '../jsutils/devAssert';
|
||||
import keyValMap from '../jsutils/keyValMap';
|
||||
import { type ObjMap } from '../jsutils/ObjMap';
|
||||
|
||||
import { Kind } from '../language/kinds';
|
||||
import { type Source } from '../language/source';
|
||||
import { TokenKind } from '../language/tokenKind';
|
||||
import { type ParseOptions, parse } from '../language/parser';
|
||||
import { isTypeDefinitionNode } from '../language/predicates';
|
||||
import { dedentBlockStringValue } from '../language/blockString';
|
||||
import { type DirectiveLocationEnum } from '../language/directiveLocation';
|
||||
import {
|
||||
type DocumentNode,
|
||||
type NameNode,
|
||||
type TypeNode,
|
||||
type NamedTypeNode,
|
||||
type SchemaDefinitionNode,
|
||||
type TypeDefinitionNode,
|
||||
type ScalarTypeDefinitionNode,
|
||||
type ObjectTypeDefinitionNode,
|
||||
type FieldDefinitionNode,
|
||||
type InputValueDefinitionNode,
|
||||
type InterfaceTypeDefinitionNode,
|
||||
type UnionTypeDefinitionNode,
|
||||
type EnumTypeDefinitionNode,
|
||||
type EnumValueDefinitionNode,
|
||||
type InputObjectTypeDefinitionNode,
|
||||
type DirectiveDefinitionNode,
|
||||
type StringValueNode,
|
||||
type Location,
|
||||
} from '../language/ast';
|
||||
|
||||
import { assertValidSDL } from '../validation/validate';
|
||||
|
||||
import { getDirectiveValues } from '../execution/values';
|
||||
|
||||
import { specifiedScalarTypes } from '../type/scalars';
|
||||
import { introspectionTypes } from '../type/introspection';
|
||||
import {
|
||||
type GraphQLSchemaValidationOptions,
|
||||
GraphQLSchema,
|
||||
} from '../type/schema';
|
||||
import {
|
||||
GraphQLDirective,
|
||||
GraphQLSkipDirective,
|
||||
GraphQLIncludeDirective,
|
||||
GraphQLDeprecatedDirective,
|
||||
} from '../type/directives';
|
||||
import {
|
||||
type GraphQLType,
|
||||
type GraphQLNamedType,
|
||||
type GraphQLFieldConfig,
|
||||
type GraphQLArgumentConfig,
|
||||
type GraphQLEnumValueConfig,
|
||||
type GraphQLInputFieldConfig,
|
||||
GraphQLScalarType,
|
||||
GraphQLObjectType,
|
||||
GraphQLInterfaceType,
|
||||
GraphQLUnionType,
|
||||
GraphQLEnumType,
|
||||
GraphQLInputObjectType,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
} from '../type/definition';
|
||||
|
||||
import { valueFromAST } from './valueFromAST';
|
||||
|
||||
export type BuildSchemaOptions = {
|
||||
...GraphQLSchemaValidationOptions,
|
||||
|
||||
/**
|
||||
* Descriptions are defined as preceding string literals, however an older
|
||||
* experimental version of the SDL supported preceding comments as
|
||||
* descriptions. Set to true to enable this deprecated behavior.
|
||||
* This option is provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
commentDescriptions?: boolean,
|
||||
|
||||
/**
|
||||
* Set to true to assume the SDL is valid.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
assumeValidSDL?: boolean,
|
||||
|
||||
...
|
||||
};
|
||||
|
||||
/**
|
||||
* This takes the ast of a schema document produced by the parse function in
|
||||
* src/language/parser.js.
|
||||
*
|
||||
* If no schema definition is provided, then it will look for types named Query
|
||||
* and Mutation.
|
||||
*
|
||||
* Given that AST it constructs a GraphQLSchema. The resulting schema
|
||||
* has no resolve methods, so execution will use default resolvers.
|
||||
*
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function buildASTSchema(
|
||||
documentAST: DocumentNode,
|
||||
options?: BuildSchemaOptions,
|
||||
): GraphQLSchema {
|
||||
devAssert(
|
||||
documentAST && documentAST.kind === Kind.DOCUMENT,
|
||||
'Must provide valid Document AST',
|
||||
);
|
||||
|
||||
if (!options || !(options.assumeValid || options.assumeValidSDL)) {
|
||||
assertValidSDL(documentAST);
|
||||
}
|
||||
|
||||
let schemaDef: ?SchemaDefinitionNode;
|
||||
const typeDefs: Array<TypeDefinitionNode> = [];
|
||||
const directiveDefs: Array<DirectiveDefinitionNode> = [];
|
||||
|
||||
for (const def of documentAST.definitions) {
|
||||
if (def.kind === Kind.SCHEMA_DEFINITION) {
|
||||
schemaDef = def;
|
||||
} else if (isTypeDefinitionNode(def)) {
|
||||
typeDefs.push(def);
|
||||
} else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
|
||||
directiveDefs.push(def);
|
||||
}
|
||||
}
|
||||
|
||||
const astBuilder = new ASTDefinitionBuilder(options, typeName => {
|
||||
const type = typeMap[typeName];
|
||||
if (type === undefined) {
|
||||
throw new Error(`Type "${typeName}" not found in document.`);
|
||||
}
|
||||
return type;
|
||||
});
|
||||
|
||||
const typeMap = keyByNameNode(typeDefs, node => astBuilder.buildType(node));
|
||||
|
||||
const operationTypes = schemaDef
|
||||
? getOperationTypes(schemaDef)
|
||||
: {
|
||||
query: 'Query',
|
||||
mutation: 'Mutation',
|
||||
subscription: 'Subscription',
|
||||
};
|
||||
|
||||
const directives = directiveDefs.map(def => astBuilder.buildDirective(def));
|
||||
|
||||
// If specified directives were not explicitly declared, add them.
|
||||
if (!directives.some(directive => directive.name === 'skip')) {
|
||||
directives.push(GraphQLSkipDirective);
|
||||
}
|
||||
|
||||
if (!directives.some(directive => directive.name === 'include')) {
|
||||
directives.push(GraphQLIncludeDirective);
|
||||
}
|
||||
|
||||
if (!directives.some(directive => directive.name === 'deprecated')) {
|
||||
directives.push(GraphQLDeprecatedDirective);
|
||||
}
|
||||
|
||||
return new GraphQLSchema({
|
||||
// Note: While this could make early assertions to get the correctly
|
||||
// typed values below, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
query: operationTypes.query ? (typeMap[operationTypes.query]: any) : null,
|
||||
mutation: operationTypes.mutation
|
||||
? (typeMap[operationTypes.mutation]: any)
|
||||
: null,
|
||||
subscription: operationTypes.subscription
|
||||
? (typeMap[operationTypes.subscription]: any)
|
||||
: null,
|
||||
|
||||
types: objectValues(typeMap),
|
||||
directives,
|
||||
astNode: schemaDef,
|
||||
assumeValid: options && options.assumeValid,
|
||||
allowedLegacyNames: options && options.allowedLegacyNames,
|
||||
});
|
||||
|
||||
function getOperationTypes(schema: SchemaDefinitionNode) {
|
||||
const opTypes = {};
|
||||
for (const operationType of schema.operationTypes) {
|
||||
opTypes[operationType.operation] = operationType.type.name.value;
|
||||
}
|
||||
return opTypes;
|
||||
}
|
||||
}
|
||||
|
||||
type TypeResolver = (typeName: string) => GraphQLNamedType;
|
||||
|
||||
const stdTypeMap = keyMap(
|
||||
specifiedScalarTypes.concat(introspectionTypes),
|
||||
type => type.name,
|
||||
);
|
||||
|
||||
export class ASTDefinitionBuilder {
|
||||
_options: ?BuildSchemaOptions;
|
||||
_resolveType: TypeResolver;
|
||||
|
||||
constructor(options: ?BuildSchemaOptions, resolveType: TypeResolver) {
|
||||
this._options = options;
|
||||
this._resolveType = resolveType;
|
||||
}
|
||||
|
||||
getNamedType(node: NamedTypeNode): GraphQLNamedType {
|
||||
const name = node.name.value;
|
||||
return stdTypeMap[name] || this._resolveType(name);
|
||||
}
|
||||
|
||||
getWrappedType(node: TypeNode): GraphQLType {
|
||||
if (node.kind === Kind.LIST_TYPE) {
|
||||
return new GraphQLList(this.getWrappedType(node.type));
|
||||
}
|
||||
if (node.kind === Kind.NON_NULL_TYPE) {
|
||||
return new GraphQLNonNull(this.getWrappedType(node.type));
|
||||
}
|
||||
return this.getNamedType(node);
|
||||
}
|
||||
|
||||
buildDirective(directive: DirectiveDefinitionNode): GraphQLDirective {
|
||||
const locations = directive.locations.map(
|
||||
({ value }) => ((value: any): DirectiveLocationEnum),
|
||||
);
|
||||
|
||||
return new GraphQLDirective({
|
||||
name: directive.name.value,
|
||||
description: getDescription(directive, this._options),
|
||||
locations,
|
||||
isRepeatable: directive.repeatable,
|
||||
args: keyByNameNode(directive.arguments || [], arg => this.buildArg(arg)),
|
||||
astNode: directive,
|
||||
});
|
||||
}
|
||||
|
||||
buildField(field: FieldDefinitionNode): GraphQLFieldConfig<mixed, mixed> {
|
||||
return {
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// value, that would throw immediately while type system validation
|
||||
// with validateSchema() will produce more actionable results.
|
||||
type: (this.getWrappedType(field.type): any),
|
||||
description: getDescription(field, this._options),
|
||||
args: keyByNameNode(field.arguments || [], arg => this.buildArg(arg)),
|
||||
deprecationReason: getDeprecationReason(field),
|
||||
astNode: field,
|
||||
};
|
||||
}
|
||||
|
||||
buildArg(value: InputValueDefinitionNode): GraphQLArgumentConfig {
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// value, that would throw immediately while type system validation
|
||||
// with validateSchema() will produce more actionable results.
|
||||
const type: any = this.getWrappedType(value.type);
|
||||
return {
|
||||
type,
|
||||
description: getDescription(value, this._options),
|
||||
defaultValue: valueFromAST(value.defaultValue, type),
|
||||
astNode: value,
|
||||
};
|
||||
}
|
||||
|
||||
buildInputField(value: InputValueDefinitionNode): GraphQLInputFieldConfig {
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// value, that would throw immediately while type system validation
|
||||
// with validateSchema() will produce more actionable results.
|
||||
const type: any = this.getWrappedType(value.type);
|
||||
return {
|
||||
type,
|
||||
description: getDescription(value, this._options),
|
||||
defaultValue: valueFromAST(value.defaultValue, type),
|
||||
astNode: value,
|
||||
};
|
||||
}
|
||||
|
||||
buildEnumValue(value: EnumValueDefinitionNode): GraphQLEnumValueConfig {
|
||||
return {
|
||||
description: getDescription(value, this._options),
|
||||
deprecationReason: getDeprecationReason(value),
|
||||
astNode: value,
|
||||
};
|
||||
}
|
||||
|
||||
buildType(astNode: TypeDefinitionNode): GraphQLNamedType {
|
||||
const name = astNode.name.value;
|
||||
if (stdTypeMap[name]) {
|
||||
return stdTypeMap[name];
|
||||
}
|
||||
|
||||
switch (astNode.kind) {
|
||||
case Kind.OBJECT_TYPE_DEFINITION:
|
||||
return this._makeTypeDef(astNode);
|
||||
case Kind.INTERFACE_TYPE_DEFINITION:
|
||||
return this._makeInterfaceDef(astNode);
|
||||
case Kind.ENUM_TYPE_DEFINITION:
|
||||
return this._makeEnumDef(astNode);
|
||||
case Kind.UNION_TYPE_DEFINITION:
|
||||
return this._makeUnionDef(astNode);
|
||||
case Kind.SCALAR_TYPE_DEFINITION:
|
||||
return this._makeScalarDef(astNode);
|
||||
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
||||
return this._makeInputObjectDef(astNode);
|
||||
}
|
||||
|
||||
// Not reachable. All possible type definition nodes have been considered.
|
||||
invariant(
|
||||
false,
|
||||
'Unexpected type definition node: ' + inspect((astNode: empty)),
|
||||
);
|
||||
}
|
||||
|
||||
_makeTypeDef(astNode: ObjectTypeDefinitionNode) {
|
||||
const interfaceNodes = astNode.interfaces;
|
||||
const fieldNodes = astNode.fields;
|
||||
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// values below, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
const interfaces =
|
||||
interfaceNodes && interfaceNodes.length > 0
|
||||
? () => interfaceNodes.map(ref => (this.getNamedType(ref): any))
|
||||
: [];
|
||||
|
||||
const fields =
|
||||
fieldNodes && fieldNodes.length > 0
|
||||
? () => keyByNameNode(fieldNodes, field => this.buildField(field))
|
||||
: Object.create(null);
|
||||
|
||||
return new GraphQLObjectType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
interfaces,
|
||||
fields,
|
||||
astNode,
|
||||
});
|
||||
}
|
||||
|
||||
_makeInterfaceDef(astNode: InterfaceTypeDefinitionNode) {
|
||||
const fieldNodes = astNode.fields;
|
||||
|
||||
const fields =
|
||||
fieldNodes && fieldNodes.length > 0
|
||||
? () => keyByNameNode(fieldNodes, field => this.buildField(field))
|
||||
: Object.create(null);
|
||||
|
||||
return new GraphQLInterfaceType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
fields,
|
||||
astNode,
|
||||
});
|
||||
}
|
||||
|
||||
_makeEnumDef(astNode: EnumTypeDefinitionNode) {
|
||||
const valueNodes = astNode.values || [];
|
||||
|
||||
return new GraphQLEnumType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
values: keyByNameNode(valueNodes, value => this.buildEnumValue(value)),
|
||||
astNode,
|
||||
});
|
||||
}
|
||||
|
||||
_makeUnionDef(astNode: UnionTypeDefinitionNode) {
|
||||
const typeNodes = astNode.types;
|
||||
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// values below, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
const types =
|
||||
typeNodes && typeNodes.length > 0
|
||||
? () => typeNodes.map(ref => (this.getNamedType(ref): any))
|
||||
: [];
|
||||
|
||||
return new GraphQLUnionType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
types,
|
||||
astNode,
|
||||
});
|
||||
}
|
||||
|
||||
_makeScalarDef(astNode: ScalarTypeDefinitionNode) {
|
||||
return new GraphQLScalarType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
astNode,
|
||||
});
|
||||
}
|
||||
|
||||
_makeInputObjectDef(def: InputObjectTypeDefinitionNode) {
|
||||
const { fields } = def;
|
||||
|
||||
return new GraphQLInputObjectType({
|
||||
name: def.name.value,
|
||||
description: getDescription(def, this._options),
|
||||
fields: fields
|
||||
? () => keyByNameNode(fields, field => this.buildInputField(field))
|
||||
: Object.create(null),
|
||||
astNode: def,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function keyByNameNode<T: { +name: NameNode, ... }, V>(
|
||||
list: $ReadOnlyArray<T>,
|
||||
valFn: (item: T) => V,
|
||||
): ObjMap<V> {
|
||||
return keyValMap(list, ({ name }) => name.value, valFn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a field or enum value node, returns the string value for the
|
||||
* deprecation reason.
|
||||
*/
|
||||
function getDeprecationReason(
|
||||
node: EnumValueDefinitionNode | FieldDefinitionNode,
|
||||
): ?string {
|
||||
const deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
|
||||
return deprecated && (deprecated.reason: any);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an ast node, returns its string description.
|
||||
* @deprecated: provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function getDescription(
|
||||
node: { +description?: StringValueNode, +loc?: Location, ... },
|
||||
options: ?BuildSchemaOptions,
|
||||
): void | string {
|
||||
if (node.description) {
|
||||
return node.description.value;
|
||||
}
|
||||
if (options && options.commentDescriptions) {
|
||||
const rawValue = getLeadingCommentBlock(node);
|
||||
if (rawValue !== undefined) {
|
||||
return dedentBlockStringValue('\n' + rawValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getLeadingCommentBlock(node): void | string {
|
||||
const loc = node.loc;
|
||||
if (!loc) {
|
||||
return;
|
||||
}
|
||||
const comments = [];
|
||||
let token = loc.startToken.prev;
|
||||
while (
|
||||
token &&
|
||||
token.kind === TokenKind.COMMENT &&
|
||||
token.next &&
|
||||
token.prev &&
|
||||
token.line + 1 === token.next.line &&
|
||||
token.line !== token.prev.line
|
||||
) {
|
||||
const value = String(token.value);
|
||||
comments.push(value);
|
||||
token = token.prev;
|
||||
}
|
||||
return comments.reverse().join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper function to build a GraphQLSchema directly from a source
|
||||
* document.
|
||||
*/
|
||||
export function buildSchema(
|
||||
source: string | Source,
|
||||
options?: BuildSchemaOptions & ParseOptions,
|
||||
): GraphQLSchema {
|
||||
return buildASTSchema(parse(source, options), options);
|
||||
}
|
||||
429
node_modules/graphql/utilities/buildASTSchema.mjs
generated
vendored
Normal file
429
node_modules/graphql/utilities/buildASTSchema.mjs
generated
vendored
Normal file
@@ -0,0 +1,429 @@
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
import keyMap from '../jsutils/keyMap';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import devAssert from '../jsutils/devAssert';
|
||||
import keyValMap from '../jsutils/keyValMap';
|
||||
import { Kind } from '../language/kinds';
|
||||
import { TokenKind } from '../language/tokenKind';
|
||||
import { parse } from '../language/parser';
|
||||
import { isTypeDefinitionNode } from '../language/predicates';
|
||||
import { dedentBlockStringValue } from '../language/blockString';
|
||||
import { assertValidSDL } from '../validation/validate';
|
||||
import { getDirectiveValues } from '../execution/values';
|
||||
import { specifiedScalarTypes } from '../type/scalars';
|
||||
import { introspectionTypes } from '../type/introspection';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { GraphQLDirective, GraphQLSkipDirective, GraphQLIncludeDirective, GraphQLDeprecatedDirective } from '../type/directives';
|
||||
import { GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, GraphQLNonNull } from '../type/definition';
|
||||
import { valueFromAST } from './valueFromAST';
|
||||
|
||||
/**
|
||||
* This takes the ast of a schema document produced by the parse function in
|
||||
* src/language/parser.js.
|
||||
*
|
||||
* If no schema definition is provided, then it will look for types named Query
|
||||
* and Mutation.
|
||||
*
|
||||
* Given that AST it constructs a GraphQLSchema. The resulting schema
|
||||
* has no resolve methods, so execution will use default resolvers.
|
||||
*
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function buildASTSchema(documentAST, options) {
|
||||
documentAST && documentAST.kind === Kind.DOCUMENT || devAssert(0, 'Must provide valid Document AST');
|
||||
|
||||
if (!options || !(options.assumeValid || options.assumeValidSDL)) {
|
||||
assertValidSDL(documentAST);
|
||||
}
|
||||
|
||||
var schemaDef;
|
||||
var typeDefs = [];
|
||||
var directiveDefs = [];
|
||||
|
||||
for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
|
||||
var def = _documentAST$definiti2[_i2];
|
||||
|
||||
if (def.kind === Kind.SCHEMA_DEFINITION) {
|
||||
schemaDef = def;
|
||||
} else if (isTypeDefinitionNode(def)) {
|
||||
typeDefs.push(def);
|
||||
} else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
|
||||
directiveDefs.push(def);
|
||||
}
|
||||
}
|
||||
|
||||
var astBuilder = new ASTDefinitionBuilder(options, function (typeName) {
|
||||
var type = typeMap[typeName];
|
||||
|
||||
if (type === undefined) {
|
||||
throw new Error("Type \"".concat(typeName, "\" not found in document."));
|
||||
}
|
||||
|
||||
return type;
|
||||
});
|
||||
var typeMap = keyByNameNode(typeDefs, function (node) {
|
||||
return astBuilder.buildType(node);
|
||||
});
|
||||
var operationTypes = schemaDef ? getOperationTypes(schemaDef) : {
|
||||
query: 'Query',
|
||||
mutation: 'Mutation',
|
||||
subscription: 'Subscription'
|
||||
};
|
||||
var directives = directiveDefs.map(function (def) {
|
||||
return astBuilder.buildDirective(def);
|
||||
}); // If specified directives were not explicitly declared, add them.
|
||||
|
||||
if (!directives.some(function (directive) {
|
||||
return directive.name === 'skip';
|
||||
})) {
|
||||
directives.push(GraphQLSkipDirective);
|
||||
}
|
||||
|
||||
if (!directives.some(function (directive) {
|
||||
return directive.name === 'include';
|
||||
})) {
|
||||
directives.push(GraphQLIncludeDirective);
|
||||
}
|
||||
|
||||
if (!directives.some(function (directive) {
|
||||
return directive.name === 'deprecated';
|
||||
})) {
|
||||
directives.push(GraphQLDeprecatedDirective);
|
||||
}
|
||||
|
||||
return new GraphQLSchema({
|
||||
// Note: While this could make early assertions to get the correctly
|
||||
// typed values below, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
query: operationTypes.query ? typeMap[operationTypes.query] : null,
|
||||
mutation: operationTypes.mutation ? typeMap[operationTypes.mutation] : null,
|
||||
subscription: operationTypes.subscription ? typeMap[operationTypes.subscription] : null,
|
||||
types: objectValues(typeMap),
|
||||
directives: directives,
|
||||
astNode: schemaDef,
|
||||
assumeValid: options && options.assumeValid,
|
||||
allowedLegacyNames: options && options.allowedLegacyNames
|
||||
});
|
||||
|
||||
function getOperationTypes(schema) {
|
||||
var opTypes = {};
|
||||
|
||||
for (var _i4 = 0, _schema$operationType2 = schema.operationTypes; _i4 < _schema$operationType2.length; _i4++) {
|
||||
var operationType = _schema$operationType2[_i4];
|
||||
opTypes[operationType.operation] = operationType.type.name.value;
|
||||
}
|
||||
|
||||
return opTypes;
|
||||
}
|
||||
}
|
||||
var stdTypeMap = keyMap(specifiedScalarTypes.concat(introspectionTypes), function (type) {
|
||||
return type.name;
|
||||
});
|
||||
export var ASTDefinitionBuilder =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function ASTDefinitionBuilder(options, resolveType) {
|
||||
this._options = options;
|
||||
this._resolveType = resolveType;
|
||||
}
|
||||
|
||||
var _proto = ASTDefinitionBuilder.prototype;
|
||||
|
||||
_proto.getNamedType = function getNamedType(node) {
|
||||
var name = node.name.value;
|
||||
return stdTypeMap[name] || this._resolveType(name);
|
||||
};
|
||||
|
||||
_proto.getWrappedType = function getWrappedType(node) {
|
||||
if (node.kind === Kind.LIST_TYPE) {
|
||||
return new GraphQLList(this.getWrappedType(node.type));
|
||||
}
|
||||
|
||||
if (node.kind === Kind.NON_NULL_TYPE) {
|
||||
return new GraphQLNonNull(this.getWrappedType(node.type));
|
||||
}
|
||||
|
||||
return this.getNamedType(node);
|
||||
};
|
||||
|
||||
_proto.buildDirective = function buildDirective(directive) {
|
||||
var _this = this;
|
||||
|
||||
var locations = directive.locations.map(function (_ref) {
|
||||
var value = _ref.value;
|
||||
return value;
|
||||
});
|
||||
return new GraphQLDirective({
|
||||
name: directive.name.value,
|
||||
description: getDescription(directive, this._options),
|
||||
locations: locations,
|
||||
isRepeatable: directive.repeatable,
|
||||
args: keyByNameNode(directive.arguments || [], function (arg) {
|
||||
return _this.buildArg(arg);
|
||||
}),
|
||||
astNode: directive
|
||||
});
|
||||
};
|
||||
|
||||
_proto.buildField = function buildField(field) {
|
||||
var _this2 = this;
|
||||
|
||||
return {
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// value, that would throw immediately while type system validation
|
||||
// with validateSchema() will produce more actionable results.
|
||||
type: this.getWrappedType(field.type),
|
||||
description: getDescription(field, this._options),
|
||||
args: keyByNameNode(field.arguments || [], function (arg) {
|
||||
return _this2.buildArg(arg);
|
||||
}),
|
||||
deprecationReason: getDeprecationReason(field),
|
||||
astNode: field
|
||||
};
|
||||
};
|
||||
|
||||
_proto.buildArg = function buildArg(value) {
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// value, that would throw immediately while type system validation
|
||||
// with validateSchema() will produce more actionable results.
|
||||
var type = this.getWrappedType(value.type);
|
||||
return {
|
||||
type: type,
|
||||
description: getDescription(value, this._options),
|
||||
defaultValue: valueFromAST(value.defaultValue, type),
|
||||
astNode: value
|
||||
};
|
||||
};
|
||||
|
||||
_proto.buildInputField = function buildInputField(value) {
|
||||
// Note: While this could make assertions to get the correctly typed
|
||||
// value, that would throw immediately while type system validation
|
||||
// with validateSchema() will produce more actionable results.
|
||||
var type = this.getWrappedType(value.type);
|
||||
return {
|
||||
type: type,
|
||||
description: getDescription(value, this._options),
|
||||
defaultValue: valueFromAST(value.defaultValue, type),
|
||||
astNode: value
|
||||
};
|
||||
};
|
||||
|
||||
_proto.buildEnumValue = function buildEnumValue(value) {
|
||||
return {
|
||||
description: getDescription(value, this._options),
|
||||
deprecationReason: getDeprecationReason(value),
|
||||
astNode: value
|
||||
};
|
||||
};
|
||||
|
||||
_proto.buildType = function buildType(astNode) {
|
||||
var name = astNode.name.value;
|
||||
|
||||
if (stdTypeMap[name]) {
|
||||
return stdTypeMap[name];
|
||||
}
|
||||
|
||||
switch (astNode.kind) {
|
||||
case Kind.OBJECT_TYPE_DEFINITION:
|
||||
return this._makeTypeDef(astNode);
|
||||
|
||||
case Kind.INTERFACE_TYPE_DEFINITION:
|
||||
return this._makeInterfaceDef(astNode);
|
||||
|
||||
case Kind.ENUM_TYPE_DEFINITION:
|
||||
return this._makeEnumDef(astNode);
|
||||
|
||||
case Kind.UNION_TYPE_DEFINITION:
|
||||
return this._makeUnionDef(astNode);
|
||||
|
||||
case Kind.SCALAR_TYPE_DEFINITION:
|
||||
return this._makeScalarDef(astNode);
|
||||
|
||||
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
||||
return this._makeInputObjectDef(astNode);
|
||||
} // Not reachable. All possible type definition nodes have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
invariant(false, 'Unexpected type definition node: ' + inspect(astNode));
|
||||
};
|
||||
|
||||
_proto._makeTypeDef = function _makeTypeDef(astNode) {
|
||||
var _this3 = this;
|
||||
|
||||
var interfaceNodes = astNode.interfaces;
|
||||
var fieldNodes = astNode.fields; // Note: While this could make assertions to get the correctly typed
|
||||
// values below, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
|
||||
var interfaces = interfaceNodes && interfaceNodes.length > 0 ? function () {
|
||||
return interfaceNodes.map(function (ref) {
|
||||
return _this3.getNamedType(ref);
|
||||
});
|
||||
} : [];
|
||||
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
||||
return keyByNameNode(fieldNodes, function (field) {
|
||||
return _this3.buildField(field);
|
||||
});
|
||||
} : Object.create(null);
|
||||
return new GraphQLObjectType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
interfaces: interfaces,
|
||||
fields: fields,
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeInterfaceDef = function _makeInterfaceDef(astNode) {
|
||||
var _this4 = this;
|
||||
|
||||
var fieldNodes = astNode.fields;
|
||||
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
||||
return keyByNameNode(fieldNodes, function (field) {
|
||||
return _this4.buildField(field);
|
||||
});
|
||||
} : Object.create(null);
|
||||
return new GraphQLInterfaceType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
fields: fields,
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeEnumDef = function _makeEnumDef(astNode) {
|
||||
var _this5 = this;
|
||||
|
||||
var valueNodes = astNode.values || [];
|
||||
return new GraphQLEnumType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
values: keyByNameNode(valueNodes, function (value) {
|
||||
return _this5.buildEnumValue(value);
|
||||
}),
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeUnionDef = function _makeUnionDef(astNode) {
|
||||
var _this6 = this;
|
||||
|
||||
var typeNodes = astNode.types; // Note: While this could make assertions to get the correctly typed
|
||||
// values below, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
|
||||
var types = typeNodes && typeNodes.length > 0 ? function () {
|
||||
return typeNodes.map(function (ref) {
|
||||
return _this6.getNamedType(ref);
|
||||
});
|
||||
} : [];
|
||||
return new GraphQLUnionType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
types: types,
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeScalarDef = function _makeScalarDef(astNode) {
|
||||
return new GraphQLScalarType({
|
||||
name: astNode.name.value,
|
||||
description: getDescription(astNode, this._options),
|
||||
astNode: astNode
|
||||
});
|
||||
};
|
||||
|
||||
_proto._makeInputObjectDef = function _makeInputObjectDef(def) {
|
||||
var _this7 = this;
|
||||
|
||||
var fields = def.fields;
|
||||
return new GraphQLInputObjectType({
|
||||
name: def.name.value,
|
||||
description: getDescription(def, this._options),
|
||||
fields: fields ? function () {
|
||||
return keyByNameNode(fields, function (field) {
|
||||
return _this7.buildInputField(field);
|
||||
});
|
||||
} : Object.create(null),
|
||||
astNode: def
|
||||
});
|
||||
};
|
||||
|
||||
return ASTDefinitionBuilder;
|
||||
}();
|
||||
|
||||
function keyByNameNode(list, valFn) {
|
||||
return keyValMap(list, function (_ref2) {
|
||||
var name = _ref2.name;
|
||||
return name.value;
|
||||
}, valFn);
|
||||
}
|
||||
/**
|
||||
* Given a field or enum value node, returns the string value for the
|
||||
* deprecation reason.
|
||||
*/
|
||||
|
||||
|
||||
function getDeprecationReason(node) {
|
||||
var deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
|
||||
return deprecated && deprecated.reason;
|
||||
}
|
||||
/**
|
||||
* Given an ast node, returns its string description.
|
||||
* @deprecated: provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
export function getDescription(node, options) {
|
||||
if (node.description) {
|
||||
return node.description.value;
|
||||
}
|
||||
|
||||
if (options && options.commentDescriptions) {
|
||||
var rawValue = getLeadingCommentBlock(node);
|
||||
|
||||
if (rawValue !== undefined) {
|
||||
return dedentBlockStringValue('\n' + rawValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getLeadingCommentBlock(node) {
|
||||
var loc = node.loc;
|
||||
|
||||
if (!loc) {
|
||||
return;
|
||||
}
|
||||
|
||||
var comments = [];
|
||||
var token = loc.startToken.prev;
|
||||
|
||||
while (token && token.kind === TokenKind.COMMENT && token.next && token.prev && token.line + 1 === token.next.line && token.line !== token.prev.line) {
|
||||
var value = String(token.value);
|
||||
comments.push(value);
|
||||
token = token.prev;
|
||||
}
|
||||
|
||||
return comments.reverse().join('\n');
|
||||
}
|
||||
/**
|
||||
* A helper function to build a GraphQLSchema directly from a source
|
||||
* document.
|
||||
*/
|
||||
|
||||
|
||||
export function buildSchema(source, options) {
|
||||
return buildASTSchema(parse(source, options), options);
|
||||
}
|
||||
21
node_modules/graphql/utilities/buildClientSchema.d.ts
generated
vendored
Normal file
21
node_modules/graphql/utilities/buildClientSchema.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { IntrospectionQuery } from './introspectionQuery';
|
||||
import { GraphQLSchema, GraphQLSchemaValidationOptions } from '../type/schema';
|
||||
|
||||
interface Options extends GraphQLSchemaValidationOptions {}
|
||||
|
||||
/**
|
||||
* Build a GraphQLSchema for use by client tools.
|
||||
*
|
||||
* Given the result of a client running the introspection query, creates and
|
||||
* returns a GraphQLSchema instance which can be then used with all graphql-js
|
||||
* tools, but cannot be used to execute a query, as introspection does not
|
||||
* represent the "resolver", "parse" or "serialize" functions or any other
|
||||
* server-internal mechanisms.
|
||||
*
|
||||
* This function expects a complete introspection result. Don't forget to check
|
||||
* the "errors" field of a server response before calling this function.
|
||||
*/
|
||||
export function buildClientSchema(
|
||||
introspection: IntrospectionQuery,
|
||||
options?: Options,
|
||||
): GraphQLSchema;
|
||||
315
node_modules/graphql/utilities/buildClientSchema.js
generated
vendored
Normal file
315
node_modules/graphql/utilities/buildClientSchema.js
generated
vendored
Normal file
@@ -0,0 +1,315 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.buildClientSchema = buildClientSchema;
|
||||
|
||||
var _objectValues = _interopRequireDefault(require("../polyfills/objectValues"));
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
|
||||
|
||||
var _keyValMap = _interopRequireDefault(require("../jsutils/keyValMap"));
|
||||
|
||||
var _isObjectLike = _interopRequireDefault(require("../jsutils/isObjectLike"));
|
||||
|
||||
var _parser = require("../language/parser");
|
||||
|
||||
var _directives = require("../type/directives");
|
||||
|
||||
var _scalars = require("../type/scalars");
|
||||
|
||||
var _introspection = require("../type/introspection");
|
||||
|
||||
var _schema = require("../type/schema");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
var _valueFromAST = require("./valueFromAST");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Build a GraphQLSchema for use by client tools.
|
||||
*
|
||||
* Given the result of a client running the introspection query, creates and
|
||||
* returns a GraphQLSchema instance which can be then used with all graphql-js
|
||||
* tools, but cannot be used to execute a query, as introspection does not
|
||||
* represent the "resolver", "parse" or "serialize" functions or any other
|
||||
* server-internal mechanisms.
|
||||
*
|
||||
* This function expects a complete introspection result. Don't forget to check
|
||||
* the "errors" field of a server response before calling this function.
|
||||
*/
|
||||
function buildClientSchema(introspection, options) {
|
||||
(0, _isObjectLike.default)(introspection) && (0, _isObjectLike.default)(introspection.__schema) || (0, _devAssert.default)(0, 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ' + (0, _inspect.default)(introspection)); // Get the schema from the introspection result.
|
||||
|
||||
var schemaIntrospection = introspection.__schema; // Iterate through all types, getting the type definition for each.
|
||||
|
||||
var typeMap = (0, _keyValMap.default)(schemaIntrospection.types, function (typeIntrospection) {
|
||||
return typeIntrospection.name;
|
||||
}, function (typeIntrospection) {
|
||||
return buildType(typeIntrospection);
|
||||
});
|
||||
|
||||
for (var _i2 = 0, _ref2 = [].concat(_scalars.specifiedScalarTypes, _introspection.introspectionTypes); _i2 < _ref2.length; _i2++) {
|
||||
var stdType = _ref2[_i2];
|
||||
|
||||
if (typeMap[stdType.name]) {
|
||||
typeMap[stdType.name] = stdType;
|
||||
}
|
||||
} // Get the root Query, Mutation, and Subscription types.
|
||||
|
||||
|
||||
var queryType = schemaIntrospection.queryType ? getObjectType(schemaIntrospection.queryType) : null;
|
||||
var mutationType = schemaIntrospection.mutationType ? getObjectType(schemaIntrospection.mutationType) : null;
|
||||
var subscriptionType = schemaIntrospection.subscriptionType ? getObjectType(schemaIntrospection.subscriptionType) : null; // Get the directives supported by Introspection, assuming empty-set if
|
||||
// directives were not queried for.
|
||||
|
||||
var directives = schemaIntrospection.directives ? schemaIntrospection.directives.map(buildDirective) : []; // Then produce and return a Schema with these types.
|
||||
|
||||
return new _schema.GraphQLSchema({
|
||||
query: queryType,
|
||||
mutation: mutationType,
|
||||
subscription: subscriptionType,
|
||||
types: (0, _objectValues.default)(typeMap),
|
||||
directives: directives,
|
||||
assumeValid: options && options.assumeValid,
|
||||
allowedLegacyNames: options && options.allowedLegacyNames
|
||||
}); // Given a type reference in introspection, return the GraphQLType instance.
|
||||
// preferring cached instances before building new instances.
|
||||
|
||||
function getType(typeRef) {
|
||||
if (typeRef.kind === _introspection.TypeKind.LIST) {
|
||||
var itemRef = typeRef.ofType;
|
||||
|
||||
if (!itemRef) {
|
||||
throw new Error('Decorated type deeper than introspection query.');
|
||||
}
|
||||
|
||||
return (0, _definition.GraphQLList)(getType(itemRef));
|
||||
}
|
||||
|
||||
if (typeRef.kind === _introspection.TypeKind.NON_NULL) {
|
||||
var nullableRef = typeRef.ofType;
|
||||
|
||||
if (!nullableRef) {
|
||||
throw new Error('Decorated type deeper than introspection query.');
|
||||
}
|
||||
|
||||
var nullableType = getType(nullableRef);
|
||||
return (0, _definition.GraphQLNonNull)((0, _definition.assertNullableType)(nullableType));
|
||||
}
|
||||
|
||||
if (!typeRef.name) {
|
||||
throw new Error('Unknown type reference: ' + (0, _inspect.default)(typeRef));
|
||||
}
|
||||
|
||||
return getNamedType(typeRef.name);
|
||||
}
|
||||
|
||||
function getNamedType(typeName) {
|
||||
var type = typeMap[typeName];
|
||||
|
||||
if (!type) {
|
||||
throw new Error("Invalid or incomplete schema, unknown type: ".concat(typeName, ". Ensure that a full introspection query is used in order to build a client schema."));
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function getInputType(typeRef) {
|
||||
var type = getType(typeRef);
|
||||
|
||||
if ((0, _definition.isInputType)(type)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
throw new Error('Introspection must provide input type for arguments, but received: ' + (0, _inspect.default)(type) + '.');
|
||||
}
|
||||
|
||||
function getOutputType(typeRef) {
|
||||
var type = getType(typeRef);
|
||||
|
||||
if ((0, _definition.isOutputType)(type)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
throw new Error('Introspection must provide output type for fields, but received: ' + (0, _inspect.default)(type) + '.');
|
||||
}
|
||||
|
||||
function getObjectType(typeRef) {
|
||||
var type = getType(typeRef);
|
||||
return (0, _definition.assertObjectType)(type);
|
||||
}
|
||||
|
||||
function getInterfaceType(typeRef) {
|
||||
var type = getType(typeRef);
|
||||
return (0, _definition.assertInterfaceType)(type);
|
||||
} // Given a type's introspection result, construct the correct
|
||||
// GraphQLType instance.
|
||||
|
||||
|
||||
function buildType(type) {
|
||||
if (type && type.name && type.kind) {
|
||||
switch (type.kind) {
|
||||
case _introspection.TypeKind.SCALAR:
|
||||
return buildScalarDef(type);
|
||||
|
||||
case _introspection.TypeKind.OBJECT:
|
||||
return buildObjectDef(type);
|
||||
|
||||
case _introspection.TypeKind.INTERFACE:
|
||||
return buildInterfaceDef(type);
|
||||
|
||||
case _introspection.TypeKind.UNION:
|
||||
return buildUnionDef(type);
|
||||
|
||||
case _introspection.TypeKind.ENUM:
|
||||
return buildEnumDef(type);
|
||||
|
||||
case _introspection.TypeKind.INPUT_OBJECT:
|
||||
return buildInputObjectDef(type);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema:' + (0, _inspect.default)(type));
|
||||
}
|
||||
|
||||
function buildScalarDef(scalarIntrospection) {
|
||||
return new _definition.GraphQLScalarType({
|
||||
name: scalarIntrospection.name,
|
||||
description: scalarIntrospection.description
|
||||
});
|
||||
}
|
||||
|
||||
function buildObjectDef(objectIntrospection) {
|
||||
if (!objectIntrospection.interfaces) {
|
||||
throw new Error('Introspection result missing interfaces: ' + (0, _inspect.default)(objectIntrospection));
|
||||
}
|
||||
|
||||
return new _definition.GraphQLObjectType({
|
||||
name: objectIntrospection.name,
|
||||
description: objectIntrospection.description,
|
||||
interfaces: function interfaces() {
|
||||
return objectIntrospection.interfaces.map(getInterfaceType);
|
||||
},
|
||||
fields: function fields() {
|
||||
return buildFieldDefMap(objectIntrospection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildInterfaceDef(interfaceIntrospection) {
|
||||
return new _definition.GraphQLInterfaceType({
|
||||
name: interfaceIntrospection.name,
|
||||
description: interfaceIntrospection.description,
|
||||
fields: function fields() {
|
||||
return buildFieldDefMap(interfaceIntrospection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildUnionDef(unionIntrospection) {
|
||||
if (!unionIntrospection.possibleTypes) {
|
||||
throw new Error('Introspection result missing possibleTypes: ' + (0, _inspect.default)(unionIntrospection));
|
||||
}
|
||||
|
||||
return new _definition.GraphQLUnionType({
|
||||
name: unionIntrospection.name,
|
||||
description: unionIntrospection.description,
|
||||
types: function types() {
|
||||
return unionIntrospection.possibleTypes.map(getObjectType);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildEnumDef(enumIntrospection) {
|
||||
if (!enumIntrospection.enumValues) {
|
||||
throw new Error('Introspection result missing enumValues: ' + (0, _inspect.default)(enumIntrospection));
|
||||
}
|
||||
|
||||
return new _definition.GraphQLEnumType({
|
||||
name: enumIntrospection.name,
|
||||
description: enumIntrospection.description,
|
||||
values: (0, _keyValMap.default)(enumIntrospection.enumValues, function (valueIntrospection) {
|
||||
return valueIntrospection.name;
|
||||
}, function (valueIntrospection) {
|
||||
return {
|
||||
description: valueIntrospection.description,
|
||||
deprecationReason: valueIntrospection.deprecationReason
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function buildInputObjectDef(inputObjectIntrospection) {
|
||||
if (!inputObjectIntrospection.inputFields) {
|
||||
throw new Error('Introspection result missing inputFields: ' + (0, _inspect.default)(inputObjectIntrospection));
|
||||
}
|
||||
|
||||
return new _definition.GraphQLInputObjectType({
|
||||
name: inputObjectIntrospection.name,
|
||||
description: inputObjectIntrospection.description,
|
||||
fields: function fields() {
|
||||
return buildInputValueDefMap(inputObjectIntrospection.inputFields);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildFieldDefMap(typeIntrospection) {
|
||||
if (!typeIntrospection.fields) {
|
||||
throw new Error('Introspection result missing fields: ' + (0, _inspect.default)(typeIntrospection));
|
||||
}
|
||||
|
||||
return (0, _keyValMap.default)(typeIntrospection.fields, function (fieldIntrospection) {
|
||||
return fieldIntrospection.name;
|
||||
}, function (fieldIntrospection) {
|
||||
if (!fieldIntrospection.args) {
|
||||
throw new Error('Introspection result missing field args: ' + (0, _inspect.default)(fieldIntrospection));
|
||||
}
|
||||
|
||||
return {
|
||||
description: fieldIntrospection.description,
|
||||
deprecationReason: fieldIntrospection.deprecationReason,
|
||||
type: getOutputType(fieldIntrospection.type),
|
||||
args: buildInputValueDefMap(fieldIntrospection.args)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function buildInputValueDefMap(inputValueIntrospections) {
|
||||
return (0, _keyValMap.default)(inputValueIntrospections, function (inputValue) {
|
||||
return inputValue.name;
|
||||
}, buildInputValue);
|
||||
}
|
||||
|
||||
function buildInputValue(inputValueIntrospection) {
|
||||
var type = getInputType(inputValueIntrospection.type);
|
||||
var defaultValue = inputValueIntrospection.defaultValue ? (0, _valueFromAST.valueFromAST)((0, _parser.parseValue)(inputValueIntrospection.defaultValue), type) : undefined;
|
||||
return {
|
||||
description: inputValueIntrospection.description,
|
||||
type: type,
|
||||
defaultValue: defaultValue
|
||||
};
|
||||
}
|
||||
|
||||
function buildDirective(directiveIntrospection) {
|
||||
if (!directiveIntrospection.args) {
|
||||
throw new Error('Introspection result missing directive args: ' + (0, _inspect.default)(directiveIntrospection));
|
||||
}
|
||||
|
||||
if (!directiveIntrospection.locations) {
|
||||
throw new Error('Introspection result missing directive locations: ' + (0, _inspect.default)(directiveIntrospection));
|
||||
}
|
||||
|
||||
return new _directives.GraphQLDirective({
|
||||
name: directiveIntrospection.name,
|
||||
description: directiveIntrospection.description,
|
||||
locations: directiveIntrospection.locations.slice(),
|
||||
args: buildInputValueDefMap(directiveIntrospection.args)
|
||||
});
|
||||
}
|
||||
}
|
||||
384
node_modules/graphql/utilities/buildClientSchema.js.flow
generated
vendored
Normal file
384
node_modules/graphql/utilities/buildClientSchema.js.flow
generated
vendored
Normal file
@@ -0,0 +1,384 @@
|
||||
// @flow strict
|
||||
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
|
||||
import inspect from '../jsutils/inspect';
|
||||
import devAssert from '../jsutils/devAssert';
|
||||
import keyValMap from '../jsutils/keyValMap';
|
||||
import isObjectLike from '../jsutils/isObjectLike';
|
||||
|
||||
import { parseValue } from '../language/parser';
|
||||
|
||||
import { GraphQLDirective } from '../type/directives';
|
||||
import { specifiedScalarTypes } from '../type/scalars';
|
||||
import { introspectionTypes, TypeKind } from '../type/introspection';
|
||||
import {
|
||||
type GraphQLSchemaValidationOptions,
|
||||
GraphQLSchema,
|
||||
} from '../type/schema';
|
||||
import {
|
||||
type GraphQLType,
|
||||
type GraphQLInputType,
|
||||
type GraphQLOutputType,
|
||||
type GraphQLNamedType,
|
||||
isInputType,
|
||||
isOutputType,
|
||||
GraphQLScalarType,
|
||||
GraphQLObjectType,
|
||||
GraphQLInterfaceType,
|
||||
GraphQLUnionType,
|
||||
GraphQLEnumType,
|
||||
GraphQLInputObjectType,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
assertNullableType,
|
||||
assertObjectType,
|
||||
assertInterfaceType,
|
||||
} from '../type/definition';
|
||||
|
||||
import { valueFromAST } from './valueFromAST';
|
||||
import {
|
||||
type IntrospectionQuery,
|
||||
type IntrospectionType,
|
||||
type IntrospectionScalarType,
|
||||
type IntrospectionObjectType,
|
||||
type IntrospectionInterfaceType,
|
||||
type IntrospectionUnionType,
|
||||
type IntrospectionEnumType,
|
||||
type IntrospectionInputObjectType,
|
||||
type IntrospectionTypeRef,
|
||||
type IntrospectionInputTypeRef,
|
||||
type IntrospectionOutputTypeRef,
|
||||
type IntrospectionNamedTypeRef,
|
||||
} from './introspectionQuery';
|
||||
|
||||
type Options = {|
|
||||
...GraphQLSchemaValidationOptions,
|
||||
|};
|
||||
|
||||
/**
|
||||
* Build a GraphQLSchema for use by client tools.
|
||||
*
|
||||
* Given the result of a client running the introspection query, creates and
|
||||
* returns a GraphQLSchema instance which can be then used with all graphql-js
|
||||
* tools, but cannot be used to execute a query, as introspection does not
|
||||
* represent the "resolver", "parse" or "serialize" functions or any other
|
||||
* server-internal mechanisms.
|
||||
*
|
||||
* This function expects a complete introspection result. Don't forget to check
|
||||
* the "errors" field of a server response before calling this function.
|
||||
*/
|
||||
export function buildClientSchema(
|
||||
introspection: IntrospectionQuery,
|
||||
options?: Options,
|
||||
): GraphQLSchema {
|
||||
devAssert(
|
||||
isObjectLike(introspection) && isObjectLike(introspection.__schema),
|
||||
'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ' +
|
||||
inspect(introspection),
|
||||
);
|
||||
|
||||
// Get the schema from the introspection result.
|
||||
const schemaIntrospection = introspection.__schema;
|
||||
|
||||
// Iterate through all types, getting the type definition for each.
|
||||
const typeMap = keyValMap(
|
||||
schemaIntrospection.types,
|
||||
typeIntrospection => typeIntrospection.name,
|
||||
typeIntrospection => buildType(typeIntrospection),
|
||||
);
|
||||
|
||||
for (const stdType of [...specifiedScalarTypes, ...introspectionTypes]) {
|
||||
if (typeMap[stdType.name]) {
|
||||
typeMap[stdType.name] = stdType;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the root Query, Mutation, and Subscription types.
|
||||
const queryType = schemaIntrospection.queryType
|
||||
? getObjectType(schemaIntrospection.queryType)
|
||||
: null;
|
||||
|
||||
const mutationType = schemaIntrospection.mutationType
|
||||
? getObjectType(schemaIntrospection.mutationType)
|
||||
: null;
|
||||
|
||||
const subscriptionType = schemaIntrospection.subscriptionType
|
||||
? getObjectType(schemaIntrospection.subscriptionType)
|
||||
: null;
|
||||
|
||||
// Get the directives supported by Introspection, assuming empty-set if
|
||||
// directives were not queried for.
|
||||
const directives = schemaIntrospection.directives
|
||||
? schemaIntrospection.directives.map(buildDirective)
|
||||
: [];
|
||||
|
||||
// Then produce and return a Schema with these types.
|
||||
return new GraphQLSchema({
|
||||
query: queryType,
|
||||
mutation: mutationType,
|
||||
subscription: subscriptionType,
|
||||
types: objectValues(typeMap),
|
||||
directives,
|
||||
assumeValid: options && options.assumeValid,
|
||||
allowedLegacyNames: options && options.allowedLegacyNames,
|
||||
});
|
||||
|
||||
// Given a type reference in introspection, return the GraphQLType instance.
|
||||
// preferring cached instances before building new instances.
|
||||
function getType(typeRef: IntrospectionTypeRef): GraphQLType {
|
||||
if (typeRef.kind === TypeKind.LIST) {
|
||||
const itemRef = typeRef.ofType;
|
||||
if (!itemRef) {
|
||||
throw new Error('Decorated type deeper than introspection query.');
|
||||
}
|
||||
return GraphQLList(getType(itemRef));
|
||||
}
|
||||
if (typeRef.kind === TypeKind.NON_NULL) {
|
||||
const nullableRef = typeRef.ofType;
|
||||
if (!nullableRef) {
|
||||
throw new Error('Decorated type deeper than introspection query.');
|
||||
}
|
||||
const nullableType = getType(nullableRef);
|
||||
return GraphQLNonNull(assertNullableType(nullableType));
|
||||
}
|
||||
if (!typeRef.name) {
|
||||
throw new Error('Unknown type reference: ' + inspect(typeRef));
|
||||
}
|
||||
return getNamedType(typeRef.name);
|
||||
}
|
||||
|
||||
function getNamedType(typeName: string): GraphQLNamedType {
|
||||
const type = typeMap[typeName];
|
||||
if (!type) {
|
||||
throw new Error(
|
||||
`Invalid or incomplete schema, unknown type: ${typeName}. Ensure that a full introspection query is used in order to build a client schema.`,
|
||||
);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function getInputType(typeRef: IntrospectionInputTypeRef): GraphQLInputType {
|
||||
const type = getType(typeRef);
|
||||
if (isInputType(type)) {
|
||||
return type;
|
||||
}
|
||||
throw new Error(
|
||||
'Introspection must provide input type for arguments, but received: ' +
|
||||
inspect(type) +
|
||||
'.',
|
||||
);
|
||||
}
|
||||
|
||||
function getOutputType(
|
||||
typeRef: IntrospectionOutputTypeRef,
|
||||
): GraphQLOutputType {
|
||||
const type = getType(typeRef);
|
||||
if (isOutputType(type)) {
|
||||
return type;
|
||||
}
|
||||
throw new Error(
|
||||
'Introspection must provide output type for fields, but received: ' +
|
||||
inspect(type) +
|
||||
'.',
|
||||
);
|
||||
}
|
||||
|
||||
function getObjectType(
|
||||
typeRef: IntrospectionNamedTypeRef<IntrospectionObjectType>,
|
||||
): GraphQLObjectType {
|
||||
const type = getType(typeRef);
|
||||
return assertObjectType(type);
|
||||
}
|
||||
|
||||
function getInterfaceType(
|
||||
typeRef: IntrospectionTypeRef,
|
||||
): GraphQLInterfaceType {
|
||||
const type = getType(typeRef);
|
||||
return assertInterfaceType(type);
|
||||
}
|
||||
|
||||
// Given a type's introspection result, construct the correct
|
||||
// GraphQLType instance.
|
||||
function buildType(type: IntrospectionType): GraphQLNamedType {
|
||||
if (type && type.name && type.kind) {
|
||||
switch (type.kind) {
|
||||
case TypeKind.SCALAR:
|
||||
return buildScalarDef(type);
|
||||
case TypeKind.OBJECT:
|
||||
return buildObjectDef(type);
|
||||
case TypeKind.INTERFACE:
|
||||
return buildInterfaceDef(type);
|
||||
case TypeKind.UNION:
|
||||
return buildUnionDef(type);
|
||||
case TypeKind.ENUM:
|
||||
return buildEnumDef(type);
|
||||
case TypeKind.INPUT_OBJECT:
|
||||
return buildInputObjectDef(type);
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
'Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema:' +
|
||||
inspect(type),
|
||||
);
|
||||
}
|
||||
|
||||
function buildScalarDef(
|
||||
scalarIntrospection: IntrospectionScalarType,
|
||||
): GraphQLScalarType {
|
||||
return new GraphQLScalarType({
|
||||
name: scalarIntrospection.name,
|
||||
description: scalarIntrospection.description,
|
||||
});
|
||||
}
|
||||
|
||||
function buildObjectDef(
|
||||
objectIntrospection: IntrospectionObjectType,
|
||||
): GraphQLObjectType {
|
||||
if (!objectIntrospection.interfaces) {
|
||||
throw new Error(
|
||||
'Introspection result missing interfaces: ' +
|
||||
inspect(objectIntrospection),
|
||||
);
|
||||
}
|
||||
return new GraphQLObjectType({
|
||||
name: objectIntrospection.name,
|
||||
description: objectIntrospection.description,
|
||||
interfaces: () => objectIntrospection.interfaces.map(getInterfaceType),
|
||||
fields: () => buildFieldDefMap(objectIntrospection),
|
||||
});
|
||||
}
|
||||
|
||||
function buildInterfaceDef(
|
||||
interfaceIntrospection: IntrospectionInterfaceType,
|
||||
): GraphQLInterfaceType {
|
||||
return new GraphQLInterfaceType({
|
||||
name: interfaceIntrospection.name,
|
||||
description: interfaceIntrospection.description,
|
||||
fields: () => buildFieldDefMap(interfaceIntrospection),
|
||||
});
|
||||
}
|
||||
|
||||
function buildUnionDef(
|
||||
unionIntrospection: IntrospectionUnionType,
|
||||
): GraphQLUnionType {
|
||||
if (!unionIntrospection.possibleTypes) {
|
||||
throw new Error(
|
||||
'Introspection result missing possibleTypes: ' +
|
||||
inspect(unionIntrospection),
|
||||
);
|
||||
}
|
||||
return new GraphQLUnionType({
|
||||
name: unionIntrospection.name,
|
||||
description: unionIntrospection.description,
|
||||
types: () => unionIntrospection.possibleTypes.map(getObjectType),
|
||||
});
|
||||
}
|
||||
|
||||
function buildEnumDef(
|
||||
enumIntrospection: IntrospectionEnumType,
|
||||
): GraphQLEnumType {
|
||||
if (!enumIntrospection.enumValues) {
|
||||
throw new Error(
|
||||
'Introspection result missing enumValues: ' +
|
||||
inspect(enumIntrospection),
|
||||
);
|
||||
}
|
||||
return new GraphQLEnumType({
|
||||
name: enumIntrospection.name,
|
||||
description: enumIntrospection.description,
|
||||
values: keyValMap(
|
||||
enumIntrospection.enumValues,
|
||||
valueIntrospection => valueIntrospection.name,
|
||||
valueIntrospection => ({
|
||||
description: valueIntrospection.description,
|
||||
deprecationReason: valueIntrospection.deprecationReason,
|
||||
}),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
function buildInputObjectDef(
|
||||
inputObjectIntrospection: IntrospectionInputObjectType,
|
||||
): GraphQLInputObjectType {
|
||||
if (!inputObjectIntrospection.inputFields) {
|
||||
throw new Error(
|
||||
'Introspection result missing inputFields: ' +
|
||||
inspect(inputObjectIntrospection),
|
||||
);
|
||||
}
|
||||
return new GraphQLInputObjectType({
|
||||
name: inputObjectIntrospection.name,
|
||||
description: inputObjectIntrospection.description,
|
||||
fields: () => buildInputValueDefMap(inputObjectIntrospection.inputFields),
|
||||
});
|
||||
}
|
||||
|
||||
function buildFieldDefMap(typeIntrospection) {
|
||||
if (!typeIntrospection.fields) {
|
||||
throw new Error(
|
||||
'Introspection result missing fields: ' + inspect(typeIntrospection),
|
||||
);
|
||||
}
|
||||
return keyValMap(
|
||||
typeIntrospection.fields,
|
||||
fieldIntrospection => fieldIntrospection.name,
|
||||
fieldIntrospection => {
|
||||
if (!fieldIntrospection.args) {
|
||||
throw new Error(
|
||||
'Introspection result missing field args: ' +
|
||||
inspect(fieldIntrospection),
|
||||
);
|
||||
}
|
||||
return {
|
||||
description: fieldIntrospection.description,
|
||||
deprecationReason: fieldIntrospection.deprecationReason,
|
||||
type: getOutputType(fieldIntrospection.type),
|
||||
args: buildInputValueDefMap(fieldIntrospection.args),
|
||||
};
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function buildInputValueDefMap(inputValueIntrospections) {
|
||||
return keyValMap(
|
||||
inputValueIntrospections,
|
||||
inputValue => inputValue.name,
|
||||
buildInputValue,
|
||||
);
|
||||
}
|
||||
|
||||
function buildInputValue(inputValueIntrospection) {
|
||||
const type = getInputType(inputValueIntrospection.type);
|
||||
const defaultValue = inputValueIntrospection.defaultValue
|
||||
? valueFromAST(parseValue(inputValueIntrospection.defaultValue), type)
|
||||
: undefined;
|
||||
return {
|
||||
description: inputValueIntrospection.description,
|
||||
type,
|
||||
defaultValue,
|
||||
};
|
||||
}
|
||||
|
||||
function buildDirective(directiveIntrospection) {
|
||||
if (!directiveIntrospection.args) {
|
||||
throw new Error(
|
||||
'Introspection result missing directive args: ' +
|
||||
inspect(directiveIntrospection),
|
||||
);
|
||||
}
|
||||
if (!directiveIntrospection.locations) {
|
||||
throw new Error(
|
||||
'Introspection result missing directive locations: ' +
|
||||
inspect(directiveIntrospection),
|
||||
);
|
||||
}
|
||||
return new GraphQLDirective({
|
||||
name: directiveIntrospection.name,
|
||||
description: directiveIntrospection.description,
|
||||
locations: directiveIntrospection.locations.slice(),
|
||||
args: buildInputValueDefMap(directiveIntrospection.args),
|
||||
});
|
||||
}
|
||||
}
|
||||
295
node_modules/graphql/utilities/buildClientSchema.mjs
generated
vendored
Normal file
295
node_modules/graphql/utilities/buildClientSchema.mjs
generated
vendored
Normal file
@@ -0,0 +1,295 @@
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import devAssert from '../jsutils/devAssert';
|
||||
import keyValMap from '../jsutils/keyValMap';
|
||||
import isObjectLike from '../jsutils/isObjectLike';
|
||||
import { parseValue } from '../language/parser';
|
||||
import { GraphQLDirective } from '../type/directives';
|
||||
import { specifiedScalarTypes } from '../type/scalars';
|
||||
import { introspectionTypes, TypeKind } from '../type/introspection';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { isInputType, isOutputType, GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, GraphQLNonNull, assertNullableType, assertObjectType, assertInterfaceType } from '../type/definition';
|
||||
import { valueFromAST } from './valueFromAST';
|
||||
|
||||
/**
|
||||
* Build a GraphQLSchema for use by client tools.
|
||||
*
|
||||
* Given the result of a client running the introspection query, creates and
|
||||
* returns a GraphQLSchema instance which can be then used with all graphql-js
|
||||
* tools, but cannot be used to execute a query, as introspection does not
|
||||
* represent the "resolver", "parse" or "serialize" functions or any other
|
||||
* server-internal mechanisms.
|
||||
*
|
||||
* This function expects a complete introspection result. Don't forget to check
|
||||
* the "errors" field of a server response before calling this function.
|
||||
*/
|
||||
export function buildClientSchema(introspection, options) {
|
||||
isObjectLike(introspection) && isObjectLike(introspection.__schema) || devAssert(0, 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ' + inspect(introspection)); // Get the schema from the introspection result.
|
||||
|
||||
var schemaIntrospection = introspection.__schema; // Iterate through all types, getting the type definition for each.
|
||||
|
||||
var typeMap = keyValMap(schemaIntrospection.types, function (typeIntrospection) {
|
||||
return typeIntrospection.name;
|
||||
}, function (typeIntrospection) {
|
||||
return buildType(typeIntrospection);
|
||||
});
|
||||
|
||||
for (var _i2 = 0, _ref2 = [].concat(specifiedScalarTypes, introspectionTypes); _i2 < _ref2.length; _i2++) {
|
||||
var stdType = _ref2[_i2];
|
||||
|
||||
if (typeMap[stdType.name]) {
|
||||
typeMap[stdType.name] = stdType;
|
||||
}
|
||||
} // Get the root Query, Mutation, and Subscription types.
|
||||
|
||||
|
||||
var queryType = schemaIntrospection.queryType ? getObjectType(schemaIntrospection.queryType) : null;
|
||||
var mutationType = schemaIntrospection.mutationType ? getObjectType(schemaIntrospection.mutationType) : null;
|
||||
var subscriptionType = schemaIntrospection.subscriptionType ? getObjectType(schemaIntrospection.subscriptionType) : null; // Get the directives supported by Introspection, assuming empty-set if
|
||||
// directives were not queried for.
|
||||
|
||||
var directives = schemaIntrospection.directives ? schemaIntrospection.directives.map(buildDirective) : []; // Then produce and return a Schema with these types.
|
||||
|
||||
return new GraphQLSchema({
|
||||
query: queryType,
|
||||
mutation: mutationType,
|
||||
subscription: subscriptionType,
|
||||
types: objectValues(typeMap),
|
||||
directives: directives,
|
||||
assumeValid: options && options.assumeValid,
|
||||
allowedLegacyNames: options && options.allowedLegacyNames
|
||||
}); // Given a type reference in introspection, return the GraphQLType instance.
|
||||
// preferring cached instances before building new instances.
|
||||
|
||||
function getType(typeRef) {
|
||||
if (typeRef.kind === TypeKind.LIST) {
|
||||
var itemRef = typeRef.ofType;
|
||||
|
||||
if (!itemRef) {
|
||||
throw new Error('Decorated type deeper than introspection query.');
|
||||
}
|
||||
|
||||
return GraphQLList(getType(itemRef));
|
||||
}
|
||||
|
||||
if (typeRef.kind === TypeKind.NON_NULL) {
|
||||
var nullableRef = typeRef.ofType;
|
||||
|
||||
if (!nullableRef) {
|
||||
throw new Error('Decorated type deeper than introspection query.');
|
||||
}
|
||||
|
||||
var nullableType = getType(nullableRef);
|
||||
return GraphQLNonNull(assertNullableType(nullableType));
|
||||
}
|
||||
|
||||
if (!typeRef.name) {
|
||||
throw new Error('Unknown type reference: ' + inspect(typeRef));
|
||||
}
|
||||
|
||||
return getNamedType(typeRef.name);
|
||||
}
|
||||
|
||||
function getNamedType(typeName) {
|
||||
var type = typeMap[typeName];
|
||||
|
||||
if (!type) {
|
||||
throw new Error("Invalid or incomplete schema, unknown type: ".concat(typeName, ". Ensure that a full introspection query is used in order to build a client schema."));
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function getInputType(typeRef) {
|
||||
var type = getType(typeRef);
|
||||
|
||||
if (isInputType(type)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
throw new Error('Introspection must provide input type for arguments, but received: ' + inspect(type) + '.');
|
||||
}
|
||||
|
||||
function getOutputType(typeRef) {
|
||||
var type = getType(typeRef);
|
||||
|
||||
if (isOutputType(type)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
throw new Error('Introspection must provide output type for fields, but received: ' + inspect(type) + '.');
|
||||
}
|
||||
|
||||
function getObjectType(typeRef) {
|
||||
var type = getType(typeRef);
|
||||
return assertObjectType(type);
|
||||
}
|
||||
|
||||
function getInterfaceType(typeRef) {
|
||||
var type = getType(typeRef);
|
||||
return assertInterfaceType(type);
|
||||
} // Given a type's introspection result, construct the correct
|
||||
// GraphQLType instance.
|
||||
|
||||
|
||||
function buildType(type) {
|
||||
if (type && type.name && type.kind) {
|
||||
switch (type.kind) {
|
||||
case TypeKind.SCALAR:
|
||||
return buildScalarDef(type);
|
||||
|
||||
case TypeKind.OBJECT:
|
||||
return buildObjectDef(type);
|
||||
|
||||
case TypeKind.INTERFACE:
|
||||
return buildInterfaceDef(type);
|
||||
|
||||
case TypeKind.UNION:
|
||||
return buildUnionDef(type);
|
||||
|
||||
case TypeKind.ENUM:
|
||||
return buildEnumDef(type);
|
||||
|
||||
case TypeKind.INPUT_OBJECT:
|
||||
return buildInputObjectDef(type);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema:' + inspect(type));
|
||||
}
|
||||
|
||||
function buildScalarDef(scalarIntrospection) {
|
||||
return new GraphQLScalarType({
|
||||
name: scalarIntrospection.name,
|
||||
description: scalarIntrospection.description
|
||||
});
|
||||
}
|
||||
|
||||
function buildObjectDef(objectIntrospection) {
|
||||
if (!objectIntrospection.interfaces) {
|
||||
throw new Error('Introspection result missing interfaces: ' + inspect(objectIntrospection));
|
||||
}
|
||||
|
||||
return new GraphQLObjectType({
|
||||
name: objectIntrospection.name,
|
||||
description: objectIntrospection.description,
|
||||
interfaces: function interfaces() {
|
||||
return objectIntrospection.interfaces.map(getInterfaceType);
|
||||
},
|
||||
fields: function fields() {
|
||||
return buildFieldDefMap(objectIntrospection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildInterfaceDef(interfaceIntrospection) {
|
||||
return new GraphQLInterfaceType({
|
||||
name: interfaceIntrospection.name,
|
||||
description: interfaceIntrospection.description,
|
||||
fields: function fields() {
|
||||
return buildFieldDefMap(interfaceIntrospection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildUnionDef(unionIntrospection) {
|
||||
if (!unionIntrospection.possibleTypes) {
|
||||
throw new Error('Introspection result missing possibleTypes: ' + inspect(unionIntrospection));
|
||||
}
|
||||
|
||||
return new GraphQLUnionType({
|
||||
name: unionIntrospection.name,
|
||||
description: unionIntrospection.description,
|
||||
types: function types() {
|
||||
return unionIntrospection.possibleTypes.map(getObjectType);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildEnumDef(enumIntrospection) {
|
||||
if (!enumIntrospection.enumValues) {
|
||||
throw new Error('Introspection result missing enumValues: ' + inspect(enumIntrospection));
|
||||
}
|
||||
|
||||
return new GraphQLEnumType({
|
||||
name: enumIntrospection.name,
|
||||
description: enumIntrospection.description,
|
||||
values: keyValMap(enumIntrospection.enumValues, function (valueIntrospection) {
|
||||
return valueIntrospection.name;
|
||||
}, function (valueIntrospection) {
|
||||
return {
|
||||
description: valueIntrospection.description,
|
||||
deprecationReason: valueIntrospection.deprecationReason
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function buildInputObjectDef(inputObjectIntrospection) {
|
||||
if (!inputObjectIntrospection.inputFields) {
|
||||
throw new Error('Introspection result missing inputFields: ' + inspect(inputObjectIntrospection));
|
||||
}
|
||||
|
||||
return new GraphQLInputObjectType({
|
||||
name: inputObjectIntrospection.name,
|
||||
description: inputObjectIntrospection.description,
|
||||
fields: function fields() {
|
||||
return buildInputValueDefMap(inputObjectIntrospection.inputFields);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildFieldDefMap(typeIntrospection) {
|
||||
if (!typeIntrospection.fields) {
|
||||
throw new Error('Introspection result missing fields: ' + inspect(typeIntrospection));
|
||||
}
|
||||
|
||||
return keyValMap(typeIntrospection.fields, function (fieldIntrospection) {
|
||||
return fieldIntrospection.name;
|
||||
}, function (fieldIntrospection) {
|
||||
if (!fieldIntrospection.args) {
|
||||
throw new Error('Introspection result missing field args: ' + inspect(fieldIntrospection));
|
||||
}
|
||||
|
||||
return {
|
||||
description: fieldIntrospection.description,
|
||||
deprecationReason: fieldIntrospection.deprecationReason,
|
||||
type: getOutputType(fieldIntrospection.type),
|
||||
args: buildInputValueDefMap(fieldIntrospection.args)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function buildInputValueDefMap(inputValueIntrospections) {
|
||||
return keyValMap(inputValueIntrospections, function (inputValue) {
|
||||
return inputValue.name;
|
||||
}, buildInputValue);
|
||||
}
|
||||
|
||||
function buildInputValue(inputValueIntrospection) {
|
||||
var type = getInputType(inputValueIntrospection.type);
|
||||
var defaultValue = inputValueIntrospection.defaultValue ? valueFromAST(parseValue(inputValueIntrospection.defaultValue), type) : undefined;
|
||||
return {
|
||||
description: inputValueIntrospection.description,
|
||||
type: type,
|
||||
defaultValue: defaultValue
|
||||
};
|
||||
}
|
||||
|
||||
function buildDirective(directiveIntrospection) {
|
||||
if (!directiveIntrospection.args) {
|
||||
throw new Error('Introspection result missing directive args: ' + inspect(directiveIntrospection));
|
||||
}
|
||||
|
||||
if (!directiveIntrospection.locations) {
|
||||
throw new Error('Introspection result missing directive locations: ' + inspect(directiveIntrospection));
|
||||
}
|
||||
|
||||
return new GraphQLDirective({
|
||||
name: directiveIntrospection.name,
|
||||
description: directiveIntrospection.description,
|
||||
locations: directiveIntrospection.locations.slice(),
|
||||
args: buildInputValueDefMap(directiveIntrospection.args)
|
||||
});
|
||||
}
|
||||
}
|
||||
17
node_modules/graphql/utilities/coerceInputValue.d.ts
generated
vendored
Normal file
17
node_modules/graphql/utilities/coerceInputValue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { GraphQLInputType } from '../type/definition';
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
|
||||
type OnErrorCB = (
|
||||
path: ReadonlyArray<string | number>,
|
||||
invalidValue: any,
|
||||
error: GraphQLError,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* Coerces a JavaScript value given a GraphQL Input Type.
|
||||
*/
|
||||
export function coerceInputValue(
|
||||
inputValue: any,
|
||||
type: GraphQLInputType,
|
||||
onError?: OnErrorCB,
|
||||
): any;
|
||||
161
node_modules/graphql/utilities/coerceInputValue.js
generated
vendored
Normal file
161
node_modules/graphql/utilities/coerceInputValue.js
generated
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.coerceInputValue = coerceInputValue;
|
||||
|
||||
var _iterall = require("iterall");
|
||||
|
||||
var _objectValues3 = _interopRequireDefault(require("../polyfills/objectValues"));
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _didYouMean = _interopRequireDefault(require("../jsutils/didYouMean"));
|
||||
|
||||
var _isObjectLike = _interopRequireDefault(require("../jsutils/isObjectLike"));
|
||||
|
||||
var _suggestionList = _interopRequireDefault(require("../jsutils/suggestionList"));
|
||||
|
||||
var _printPathArray = _interopRequireDefault(require("../jsutils/printPathArray"));
|
||||
|
||||
var _Path = require("../jsutils/Path");
|
||||
|
||||
var _GraphQLError = require("../error/GraphQLError");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Coerces a JavaScript value given a GraphQL Input Type.
|
||||
*/
|
||||
function coerceInputValue(inputValue, type) {
|
||||
var onError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultOnError;
|
||||
return coerceInputValueImpl(inputValue, type, onError);
|
||||
}
|
||||
|
||||
function defaultOnError(path, invalidValue, error) {
|
||||
var errorPrefix = 'Invalid value ' + (0, _inspect.default)(invalidValue);
|
||||
|
||||
if (path.length > 0) {
|
||||
errorPrefix += " at \"value".concat((0, _printPathArray.default)(path), "\": ");
|
||||
}
|
||||
|
||||
error.message = errorPrefix + ': ' + error.message;
|
||||
throw error;
|
||||
}
|
||||
|
||||
function coerceInputValueImpl(inputValue, type, onError, path) {
|
||||
if ((0, _definition.isNonNullType)(type)) {
|
||||
if (inputValue != null) {
|
||||
return coerceInputValueImpl(inputValue, type.ofType, onError, path);
|
||||
}
|
||||
|
||||
onError((0, _Path.pathToArray)(path), inputValue, new _GraphQLError.GraphQLError("Expected non-nullable type ".concat((0, _inspect.default)(type), " not to be null.")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputValue == null) {
|
||||
// Explicitly return the value null.
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((0, _definition.isListType)(type)) {
|
||||
var itemType = type.ofType;
|
||||
|
||||
if ((0, _iterall.isCollection)(inputValue)) {
|
||||
var coercedValue = [];
|
||||
(0, _iterall.forEach)(inputValue, function (itemValue, index) {
|
||||
coercedValue.push(coerceInputValueImpl(itemValue, itemType, onError, (0, _Path.addPath)(path, index)));
|
||||
});
|
||||
return coercedValue;
|
||||
} // Lists accept a non-list value as a list of one.
|
||||
|
||||
|
||||
return [coerceInputValueImpl(inputValue, itemType, onError, path)];
|
||||
}
|
||||
|
||||
if ((0, _definition.isInputObjectType)(type)) {
|
||||
if (!(0, _isObjectLike.default)(inputValue)) {
|
||||
onError((0, _Path.pathToArray)(path), inputValue, new _GraphQLError.GraphQLError("Expected type ".concat(type.name, " to be an object.")));
|
||||
return;
|
||||
}
|
||||
|
||||
var _coercedValue = {};
|
||||
var fieldDefs = type.getFields();
|
||||
|
||||
for (var _i2 = 0, _objectValues2 = (0, _objectValues3.default)(fieldDefs); _i2 < _objectValues2.length; _i2++) {
|
||||
var field = _objectValues2[_i2];
|
||||
var fieldValue = inputValue[field.name];
|
||||
|
||||
if (fieldValue === undefined) {
|
||||
if (field.defaultValue !== undefined) {
|
||||
_coercedValue[field.name] = field.defaultValue;
|
||||
} else if ((0, _definition.isNonNullType)(field.type)) {
|
||||
var typeStr = (0, _inspect.default)(field.type);
|
||||
onError((0, _Path.pathToArray)(path), inputValue, new _GraphQLError.GraphQLError("Field ".concat(field.name, " of required type ").concat(typeStr, " was not provided.")));
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
_coercedValue[field.name] = coerceInputValueImpl(fieldValue, field.type, onError, (0, _Path.addPath)(path, field.name));
|
||||
} // Ensure every provided field is defined.
|
||||
|
||||
|
||||
for (var _i4 = 0, _Object$keys2 = Object.keys(inputValue); _i4 < _Object$keys2.length; _i4++) {
|
||||
var fieldName = _Object$keys2[_i4];
|
||||
|
||||
if (!fieldDefs[fieldName]) {
|
||||
var suggestions = (0, _suggestionList.default)(fieldName, Object.keys(type.getFields()));
|
||||
onError((0, _Path.pathToArray)(path), inputValue, new _GraphQLError.GraphQLError("Field \"".concat(fieldName, "\" is not defined by type ").concat(type.name, ".") + (0, _didYouMean.default)(suggestions)));
|
||||
}
|
||||
}
|
||||
|
||||
return _coercedValue;
|
||||
}
|
||||
|
||||
if ((0, _definition.isScalarType)(type)) {
|
||||
var parseResult; // Scalars determine if a input value is valid via parseValue(), which can
|
||||
// throw to indicate failure. If it throws, maintain a reference to
|
||||
// the original error.
|
||||
|
||||
try {
|
||||
parseResult = type.parseValue(inputValue);
|
||||
} catch (error) {
|
||||
onError((0, _Path.pathToArray)(path), inputValue, new _GraphQLError.GraphQLError("Expected type ".concat(type.name, ". ") + error.message, undefined, undefined, undefined, undefined, error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (parseResult === undefined) {
|
||||
onError((0, _Path.pathToArray)(path), inputValue, new _GraphQLError.GraphQLError("Expected type ".concat(type.name, ".")));
|
||||
}
|
||||
|
||||
return parseResult;
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if ((0, _definition.isEnumType)(type)) {
|
||||
if (typeof inputValue === 'string') {
|
||||
var enumValue = type.getValue(inputValue);
|
||||
|
||||
if (enumValue) {
|
||||
return enumValue.value;
|
||||
}
|
||||
}
|
||||
|
||||
var _suggestions = (0, _suggestionList.default)(String(inputValue), type.getValues().map(function (enumValue) {
|
||||
return enumValue.name;
|
||||
}));
|
||||
|
||||
onError((0, _Path.pathToArray)(path), inputValue, new _GraphQLError.GraphQLError("Expected type ".concat(type.name, ".") + (0, _didYouMean.default)(_suggestions)));
|
||||
return;
|
||||
} // Not reachable. All possible input types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
(0, _invariant.default)(false, 'Unexpected input type: ' + (0, _inspect.default)(type));
|
||||
}
|
||||
214
node_modules/graphql/utilities/coerceInputValue.js.flow
generated
vendored
Normal file
214
node_modules/graphql/utilities/coerceInputValue.js.flow
generated
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
// @flow strict
|
||||
|
||||
import { forEach, isCollection } from 'iterall';
|
||||
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import didYouMean from '../jsutils/didYouMean';
|
||||
import isObjectLike from '../jsutils/isObjectLike';
|
||||
import suggestionList from '../jsutils/suggestionList';
|
||||
import printPathArray from '../jsutils/printPathArray';
|
||||
import { type Path, addPath, pathToArray } from '../jsutils/Path';
|
||||
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import {
|
||||
type GraphQLInputType,
|
||||
isScalarType,
|
||||
isEnumType,
|
||||
isInputObjectType,
|
||||
isListType,
|
||||
isNonNullType,
|
||||
} from '../type/definition';
|
||||
|
||||
type OnErrorCB = (
|
||||
path: $ReadOnlyArray<string | number>,
|
||||
invalidValue: mixed,
|
||||
error: GraphQLError,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* Coerces a JavaScript value given a GraphQL Input Type.
|
||||
*/
|
||||
export function coerceInputValue(
|
||||
inputValue: mixed,
|
||||
type: GraphQLInputType,
|
||||
onError?: OnErrorCB = defaultOnError,
|
||||
): mixed {
|
||||
return coerceInputValueImpl(inputValue, type, onError);
|
||||
}
|
||||
|
||||
function defaultOnError(
|
||||
path: $ReadOnlyArray<string | number>,
|
||||
invalidValue: mixed,
|
||||
error: GraphQLError,
|
||||
) {
|
||||
let errorPrefix = 'Invalid value ' + inspect(invalidValue);
|
||||
if (path.length > 0) {
|
||||
errorPrefix += ` at "value${printPathArray(path)}": `;
|
||||
}
|
||||
error.message = errorPrefix + ': ' + error.message;
|
||||
throw error;
|
||||
}
|
||||
|
||||
function coerceInputValueImpl(
|
||||
inputValue: mixed,
|
||||
type: GraphQLInputType,
|
||||
onError: OnErrorCB,
|
||||
path: Path | void,
|
||||
): mixed {
|
||||
if (isNonNullType(type)) {
|
||||
if (inputValue != null) {
|
||||
return coerceInputValueImpl(inputValue, type.ofType, onError, path);
|
||||
}
|
||||
onError(
|
||||
pathToArray(path),
|
||||
inputValue,
|
||||
new GraphQLError(
|
||||
`Expected non-nullable type ${inspect(type)} not to be null.`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputValue == null) {
|
||||
// Explicitly return the value null.
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isListType(type)) {
|
||||
const itemType = type.ofType;
|
||||
if (isCollection(inputValue)) {
|
||||
const coercedValue = [];
|
||||
forEach((inputValue: any), (itemValue, index) => {
|
||||
coercedValue.push(
|
||||
coerceInputValueImpl(
|
||||
itemValue,
|
||||
itemType,
|
||||
onError,
|
||||
addPath(path, index),
|
||||
),
|
||||
);
|
||||
});
|
||||
return coercedValue;
|
||||
}
|
||||
// Lists accept a non-list value as a list of one.
|
||||
return [coerceInputValueImpl(inputValue, itemType, onError, path)];
|
||||
}
|
||||
|
||||
if (isInputObjectType(type)) {
|
||||
if (!isObjectLike(inputValue)) {
|
||||
onError(
|
||||
pathToArray(path),
|
||||
inputValue,
|
||||
new GraphQLError(`Expected type ${type.name} to be an object.`),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const coercedValue = {};
|
||||
const fieldDefs = type.getFields();
|
||||
|
||||
for (const field of objectValues(fieldDefs)) {
|
||||
const fieldValue = inputValue[field.name];
|
||||
|
||||
if (fieldValue === undefined) {
|
||||
if (field.defaultValue !== undefined) {
|
||||
coercedValue[field.name] = field.defaultValue;
|
||||
} else if (isNonNullType(field.type)) {
|
||||
const typeStr = inspect(field.type);
|
||||
onError(
|
||||
pathToArray(path),
|
||||
inputValue,
|
||||
new GraphQLError(
|
||||
`Field ${field.name} of required type ${typeStr} was not provided.`,
|
||||
),
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
coercedValue[field.name] = coerceInputValueImpl(
|
||||
fieldValue,
|
||||
field.type,
|
||||
onError,
|
||||
addPath(path, field.name),
|
||||
);
|
||||
}
|
||||
|
||||
// Ensure every provided field is defined.
|
||||
for (const fieldName of Object.keys(inputValue)) {
|
||||
if (!fieldDefs[fieldName]) {
|
||||
const suggestions = suggestionList(
|
||||
fieldName,
|
||||
Object.keys(type.getFields()),
|
||||
);
|
||||
onError(
|
||||
pathToArray(path),
|
||||
inputValue,
|
||||
new GraphQLError(
|
||||
`Field "${fieldName}" is not defined by type ${type.name}.` +
|
||||
didYouMean(suggestions),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return coercedValue;
|
||||
}
|
||||
|
||||
if (isScalarType(type)) {
|
||||
let parseResult;
|
||||
|
||||
// Scalars determine if a input value is valid via parseValue(), which can
|
||||
// throw to indicate failure. If it throws, maintain a reference to
|
||||
// the original error.
|
||||
try {
|
||||
parseResult = type.parseValue(inputValue);
|
||||
} catch (error) {
|
||||
onError(
|
||||
pathToArray(path),
|
||||
inputValue,
|
||||
new GraphQLError(
|
||||
`Expected type ${type.name}. ` + error.message,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
error,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (parseResult === undefined) {
|
||||
onError(
|
||||
pathToArray(path),
|
||||
inputValue,
|
||||
new GraphQLError(`Expected type ${type.name}.`),
|
||||
);
|
||||
}
|
||||
return parseResult;
|
||||
}
|
||||
|
||||
if (isEnumType(type)) {
|
||||
if (typeof inputValue === 'string') {
|
||||
const enumValue = type.getValue(inputValue);
|
||||
if (enumValue) {
|
||||
return enumValue.value;
|
||||
}
|
||||
}
|
||||
const suggestions = suggestionList(
|
||||
String(inputValue),
|
||||
type.getValues().map(enumValue => enumValue.name),
|
||||
);
|
||||
onError(
|
||||
pathToArray(path),
|
||||
inputValue,
|
||||
new GraphQLError(`Expected type ${type.name}.` + didYouMean(suggestions)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Not reachable. All possible input types have been considered.
|
||||
invariant(false, 'Unexpected input type: ' + inspect((type: empty)));
|
||||
}
|
||||
142
node_modules/graphql/utilities/coerceInputValue.mjs
generated
vendored
Normal file
142
node_modules/graphql/utilities/coerceInputValue.mjs
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
import { forEach, isCollection } from 'iterall';
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import didYouMean from '../jsutils/didYouMean';
|
||||
import isObjectLike from '../jsutils/isObjectLike';
|
||||
import suggestionList from '../jsutils/suggestionList';
|
||||
import printPathArray from '../jsutils/printPathArray';
|
||||
import { addPath, pathToArray } from '../jsutils/Path';
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { isScalarType, isEnumType, isInputObjectType, isListType, isNonNullType } from '../type/definition';
|
||||
|
||||
/**
|
||||
* Coerces a JavaScript value given a GraphQL Input Type.
|
||||
*/
|
||||
export function coerceInputValue(inputValue, type) {
|
||||
var onError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultOnError;
|
||||
return coerceInputValueImpl(inputValue, type, onError);
|
||||
}
|
||||
|
||||
function defaultOnError(path, invalidValue, error) {
|
||||
var errorPrefix = 'Invalid value ' + inspect(invalidValue);
|
||||
|
||||
if (path.length > 0) {
|
||||
errorPrefix += " at \"value".concat(printPathArray(path), "\": ");
|
||||
}
|
||||
|
||||
error.message = errorPrefix + ': ' + error.message;
|
||||
throw error;
|
||||
}
|
||||
|
||||
function coerceInputValueImpl(inputValue, type, onError, path) {
|
||||
if (isNonNullType(type)) {
|
||||
if (inputValue != null) {
|
||||
return coerceInputValueImpl(inputValue, type.ofType, onError, path);
|
||||
}
|
||||
|
||||
onError(pathToArray(path), inputValue, new GraphQLError("Expected non-nullable type ".concat(inspect(type), " not to be null.")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputValue == null) {
|
||||
// Explicitly return the value null.
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isListType(type)) {
|
||||
var itemType = type.ofType;
|
||||
|
||||
if (isCollection(inputValue)) {
|
||||
var coercedValue = [];
|
||||
forEach(inputValue, function (itemValue, index) {
|
||||
coercedValue.push(coerceInputValueImpl(itemValue, itemType, onError, addPath(path, index)));
|
||||
});
|
||||
return coercedValue;
|
||||
} // Lists accept a non-list value as a list of one.
|
||||
|
||||
|
||||
return [coerceInputValueImpl(inputValue, itemType, onError, path)];
|
||||
}
|
||||
|
||||
if (isInputObjectType(type)) {
|
||||
if (!isObjectLike(inputValue)) {
|
||||
onError(pathToArray(path), inputValue, new GraphQLError("Expected type ".concat(type.name, " to be an object.")));
|
||||
return;
|
||||
}
|
||||
|
||||
var _coercedValue = {};
|
||||
var fieldDefs = type.getFields();
|
||||
|
||||
for (var _i2 = 0, _objectValues2 = objectValues(fieldDefs); _i2 < _objectValues2.length; _i2++) {
|
||||
var field = _objectValues2[_i2];
|
||||
var fieldValue = inputValue[field.name];
|
||||
|
||||
if (fieldValue === undefined) {
|
||||
if (field.defaultValue !== undefined) {
|
||||
_coercedValue[field.name] = field.defaultValue;
|
||||
} else if (isNonNullType(field.type)) {
|
||||
var typeStr = inspect(field.type);
|
||||
onError(pathToArray(path), inputValue, new GraphQLError("Field ".concat(field.name, " of required type ").concat(typeStr, " was not provided.")));
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
_coercedValue[field.name] = coerceInputValueImpl(fieldValue, field.type, onError, addPath(path, field.name));
|
||||
} // Ensure every provided field is defined.
|
||||
|
||||
|
||||
for (var _i4 = 0, _Object$keys2 = Object.keys(inputValue); _i4 < _Object$keys2.length; _i4++) {
|
||||
var fieldName = _Object$keys2[_i4];
|
||||
|
||||
if (!fieldDefs[fieldName]) {
|
||||
var suggestions = suggestionList(fieldName, Object.keys(type.getFields()));
|
||||
onError(pathToArray(path), inputValue, new GraphQLError("Field \"".concat(fieldName, "\" is not defined by type ").concat(type.name, ".") + didYouMean(suggestions)));
|
||||
}
|
||||
}
|
||||
|
||||
return _coercedValue;
|
||||
}
|
||||
|
||||
if (isScalarType(type)) {
|
||||
var parseResult; // Scalars determine if a input value is valid via parseValue(), which can
|
||||
// throw to indicate failure. If it throws, maintain a reference to
|
||||
// the original error.
|
||||
|
||||
try {
|
||||
parseResult = type.parseValue(inputValue);
|
||||
} catch (error) {
|
||||
onError(pathToArray(path), inputValue, new GraphQLError("Expected type ".concat(type.name, ". ") + error.message, undefined, undefined, undefined, undefined, error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (parseResult === undefined) {
|
||||
onError(pathToArray(path), inputValue, new GraphQLError("Expected type ".concat(type.name, ".")));
|
||||
}
|
||||
|
||||
return parseResult;
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (isEnumType(type)) {
|
||||
if (typeof inputValue === 'string') {
|
||||
var enumValue = type.getValue(inputValue);
|
||||
|
||||
if (enumValue) {
|
||||
return enumValue.value;
|
||||
}
|
||||
}
|
||||
|
||||
var _suggestions = suggestionList(String(inputValue), type.getValues().map(function (enumValue) {
|
||||
return enumValue.name;
|
||||
}));
|
||||
|
||||
onError(pathToArray(path), inputValue, new GraphQLError("Expected type ".concat(type.name, ".") + didYouMean(_suggestions)));
|
||||
return;
|
||||
} // Not reachable. All possible input types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
invariant(false, 'Unexpected input type: ' + inspect(type));
|
||||
}
|
||||
23
node_modules/graphql/utilities/coerceValue.d.ts
generated
vendored
Normal file
23
node_modules/graphql/utilities/coerceValue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Path } from '../jsutils/Path';
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { ASTNode } from '../language/ast';
|
||||
import { GraphQLInputType } from '../type/definition';
|
||||
|
||||
interface CoercedValue {
|
||||
readonly errors: ReadonlyArray<GraphQLError> | undefined;
|
||||
readonly value: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerces a JavaScript value given a GraphQL Type.
|
||||
*
|
||||
* Returns either a value which is valid for the provided type or a list of
|
||||
* encountered coercion errors.
|
||||
*
|
||||
*/
|
||||
export function coerceValue(
|
||||
inputValue: any,
|
||||
type: GraphQLInputType,
|
||||
blameNode?: ASTNode,
|
||||
path?: Path,
|
||||
): CoercedValue;
|
||||
46
node_modules/graphql/utilities/coerceValue.js
generated
vendored
Normal file
46
node_modules/graphql/utilities/coerceValue.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.coerceValue = coerceValue;
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _printPathArray = _interopRequireDefault(require("../jsutils/printPathArray"));
|
||||
|
||||
var _Path = require("../jsutils/Path");
|
||||
|
||||
var _GraphQLError = require("../error/GraphQLError");
|
||||
|
||||
var _coerceInputValue = require("./coerceInputValue");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/* istanbul ignore file */
|
||||
|
||||
/**
|
||||
* Deprecated. Use coerceInputValue() directly for richer information.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
function coerceValue(inputValue, type, blameNode, path) {
|
||||
var errors = [];
|
||||
var value = (0, _coerceInputValue.coerceInputValue)(inputValue, type, function (errorPath, invalidValue, error) {
|
||||
var errorPrefix = 'Invalid value ' + (0, _inspect.default)(invalidValue);
|
||||
var pathArray = [].concat((0, _Path.pathToArray)(path), errorPath);
|
||||
|
||||
if (pathArray.length > 0) {
|
||||
errorPrefix += " at \"value".concat((0, _printPathArray.default)(pathArray), "\"");
|
||||
}
|
||||
|
||||
errors.push(new _GraphQLError.GraphQLError(errorPrefix + ': ' + error.message, blameNode, undefined, undefined, undefined, error.originalError));
|
||||
});
|
||||
return errors.length > 0 ? {
|
||||
errors: errors,
|
||||
value: undefined
|
||||
} : {
|
||||
errors: undefined,
|
||||
value: value
|
||||
};
|
||||
}
|
||||
56
node_modules/graphql/utilities/coerceValue.js.flow
generated
vendored
Normal file
56
node_modules/graphql/utilities/coerceValue.js.flow
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// @flow strict
|
||||
|
||||
/* istanbul ignore file */
|
||||
import inspect from '../jsutils/inspect';
|
||||
import printPathArray from '../jsutils/printPathArray';
|
||||
import { type Path, pathToArray } from '../jsutils/Path';
|
||||
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { type ASTNode } from '../language/ast';
|
||||
import { type GraphQLInputType } from '../type/definition';
|
||||
|
||||
import { coerceInputValue } from './coerceInputValue';
|
||||
|
||||
type CoercedValue = {|
|
||||
+errors: $ReadOnlyArray<GraphQLError> | void,
|
||||
+value: mixed,
|
||||
|};
|
||||
|
||||
/**
|
||||
* Deprecated. Use coerceInputValue() directly for richer information.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
export function coerceValue(
|
||||
inputValue: mixed,
|
||||
type: GraphQLInputType,
|
||||
blameNode?: ASTNode,
|
||||
path?: Path,
|
||||
): CoercedValue {
|
||||
const errors = [];
|
||||
const value = coerceInputValue(
|
||||
inputValue,
|
||||
type,
|
||||
(errorPath, invalidValue, error) => {
|
||||
let errorPrefix = 'Invalid value ' + inspect(invalidValue);
|
||||
const pathArray = [...pathToArray(path), ...errorPath];
|
||||
if (pathArray.length > 0) {
|
||||
errorPrefix += ` at "value${printPathArray(pathArray)}"`;
|
||||
}
|
||||
errors.push(
|
||||
new GraphQLError(
|
||||
errorPrefix + ': ' + error.message,
|
||||
blameNode,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
error.originalError,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return errors.length > 0
|
||||
? { errors, value: undefined }
|
||||
: { errors: undefined, value };
|
||||
}
|
||||
32
node_modules/graphql/utilities/coerceValue.mjs
generated
vendored
Normal file
32
node_modules/graphql/utilities/coerceValue.mjs
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/* istanbul ignore file */
|
||||
import inspect from '../jsutils/inspect';
|
||||
import printPathArray from '../jsutils/printPathArray';
|
||||
import { pathToArray } from '../jsutils/Path';
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { coerceInputValue } from './coerceInputValue';
|
||||
|
||||
/**
|
||||
* Deprecated. Use coerceInputValue() directly for richer information.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
export function coerceValue(inputValue, type, blameNode, path) {
|
||||
var errors = [];
|
||||
var value = coerceInputValue(inputValue, type, function (errorPath, invalidValue, error) {
|
||||
var errorPrefix = 'Invalid value ' + inspect(invalidValue);
|
||||
var pathArray = [].concat(pathToArray(path), errorPath);
|
||||
|
||||
if (pathArray.length > 0) {
|
||||
errorPrefix += " at \"value".concat(printPathArray(pathArray), "\"");
|
||||
}
|
||||
|
||||
errors.push(new GraphQLError(errorPrefix + ': ' + error.message, blameNode, undefined, undefined, undefined, error.originalError));
|
||||
});
|
||||
return errors.length > 0 ? {
|
||||
errors: errors,
|
||||
value: undefined
|
||||
} : {
|
||||
errors: undefined,
|
||||
value: value
|
||||
};
|
||||
}
|
||||
8
node_modules/graphql/utilities/concatAST.d.ts
generated
vendored
Normal file
8
node_modules/graphql/utilities/concatAST.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { DocumentNode } from '../language/ast';
|
||||
|
||||
/**
|
||||
* Provided a collection of ASTs, presumably each from different files,
|
||||
* concatenate the ASTs together into batched AST, useful for validating many
|
||||
* GraphQL source files which together represent one conceptual application.
|
||||
*/
|
||||
export function concatAST(asts: ReadonlyArray<DocumentNode>): DocumentNode;
|
||||
24
node_modules/graphql/utilities/concatAST.js
generated
vendored
Normal file
24
node_modules/graphql/utilities/concatAST.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.concatAST = concatAST;
|
||||
|
||||
var _flatMap = _interopRequireDefault(require("../polyfills/flatMap"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Provided a collection of ASTs, presumably each from different files,
|
||||
* concatenate the ASTs together into batched AST, useful for validating many
|
||||
* GraphQL source files which together represent one conceptual application.
|
||||
*/
|
||||
function concatAST(asts) {
|
||||
return {
|
||||
kind: 'Document',
|
||||
definitions: (0, _flatMap.default)(asts, function (ast) {
|
||||
return ast.definitions;
|
||||
})
|
||||
};
|
||||
}
|
||||
17
node_modules/graphql/utilities/concatAST.js.flow
generated
vendored
Normal file
17
node_modules/graphql/utilities/concatAST.js.flow
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// @flow strict
|
||||
|
||||
import flatMap from '../polyfills/flatMap';
|
||||
|
||||
import { type DocumentNode } from '../language/ast';
|
||||
|
||||
/**
|
||||
* Provided a collection of ASTs, presumably each from different files,
|
||||
* concatenate the ASTs together into batched AST, useful for validating many
|
||||
* GraphQL source files which together represent one conceptual application.
|
||||
*/
|
||||
export function concatAST(asts: $ReadOnlyArray<DocumentNode>): DocumentNode {
|
||||
return {
|
||||
kind: 'Document',
|
||||
definitions: flatMap(asts, ast => ast.definitions),
|
||||
};
|
||||
}
|
||||
15
node_modules/graphql/utilities/concatAST.mjs
generated
vendored
Normal file
15
node_modules/graphql/utilities/concatAST.mjs
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import flatMap from '../polyfills/flatMap';
|
||||
|
||||
/**
|
||||
* Provided a collection of ASTs, presumably each from different files,
|
||||
* concatenate the ASTs together into batched AST, useful for validating many
|
||||
* GraphQL source files which together represent one conceptual application.
|
||||
*/
|
||||
export function concatAST(asts) {
|
||||
return {
|
||||
kind: 'Document',
|
||||
definitions: flatMap(asts, function (ast) {
|
||||
return ast.definitions;
|
||||
})
|
||||
};
|
||||
}
|
||||
45
node_modules/graphql/utilities/extendSchema.d.ts
generated
vendored
Normal file
45
node_modules/graphql/utilities/extendSchema.d.ts
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import { DocumentNode } from '../language/ast';
|
||||
import { GraphQLSchemaValidationOptions, GraphQLSchema } from '../type/schema';
|
||||
|
||||
interface Options extends GraphQLSchemaValidationOptions {
|
||||
/**
|
||||
* Descriptions are defined as preceding string literals, however an older
|
||||
* experimental version of the SDL supported preceding comments as
|
||||
* descriptions. Set to true to enable this deprecated behavior.
|
||||
* This option is provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
commentDescriptions?: boolean;
|
||||
|
||||
/**
|
||||
* Set to true to assume the SDL is valid.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
assumeValidSDL?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a new schema given an existing schema and a document which may
|
||||
* contain GraphQL type extensions and definitions. The original schema will
|
||||
* remain unaltered.
|
||||
*
|
||||
* Because a schema represents a graph of references, a schema cannot be
|
||||
* extended without effectively making an entire copy. We do not know until it's
|
||||
* too late if subgraphs remain unchanged.
|
||||
*
|
||||
* This algorithm copies the provided schema, applying extensions while
|
||||
* producing the copy. The original schema remains unaltered.
|
||||
*
|
||||
* Accepts options as a third argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function extendSchema(
|
||||
schema: GraphQLSchema,
|
||||
documentAST: DocumentNode,
|
||||
options?: Options,
|
||||
): GraphQLSchema;
|
||||
351
node_modules/graphql/utilities/extendSchema.js
generated
vendored
Normal file
351
node_modules/graphql/utilities/extendSchema.js
generated
vendored
Normal file
@@ -0,0 +1,351 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.extendSchema = extendSchema;
|
||||
|
||||
var _flatMap = _interopRequireDefault(require("../polyfills/flatMap"));
|
||||
|
||||
var _objectValues = _interopRequireDefault(require("../polyfills/objectValues"));
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _mapValue = _interopRequireDefault(require("../jsutils/mapValue"));
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
|
||||
|
||||
var _keyValMap = _interopRequireDefault(require("../jsutils/keyValMap"));
|
||||
|
||||
var _kinds = require("../language/kinds");
|
||||
|
||||
var _predicates = require("../language/predicates");
|
||||
|
||||
var _validate = require("../validation/validate");
|
||||
|
||||
var _directives = require("../type/directives");
|
||||
|
||||
var _scalars = require("../type/scalars");
|
||||
|
||||
var _introspection = require("../type/introspection");
|
||||
|
||||
var _schema = require("../type/schema");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
var _buildASTSchema = require("./buildASTSchema");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
/**
|
||||
* Produces a new schema given an existing schema and a document which may
|
||||
* contain GraphQL type extensions and definitions. The original schema will
|
||||
* remain unaltered.
|
||||
*
|
||||
* Because a schema represents a graph of references, a schema cannot be
|
||||
* extended without effectively making an entire copy. We do not know until it's
|
||||
* too late if subgraphs remain unchanged.
|
||||
*
|
||||
* This algorithm copies the provided schema, applying extensions while
|
||||
* producing the copy. The original schema remains unaltered.
|
||||
*
|
||||
* Accepts options as a third argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
function extendSchema(schema, documentAST, options) {
|
||||
(0, _schema.assertSchema)(schema);
|
||||
documentAST && documentAST.kind === _kinds.Kind.DOCUMENT || (0, _devAssert.default)(0, 'Must provide valid Document AST');
|
||||
|
||||
if (!options || !(options.assumeValid || options.assumeValidSDL)) {
|
||||
(0, _validate.assertValidSDLExtension)(documentAST, schema);
|
||||
} // Collect the type definitions and extensions found in the document.
|
||||
|
||||
|
||||
var typeDefs = [];
|
||||
var typeExtsMap = Object.create(null); // New directives and types are separate because a directives and types can
|
||||
// have the same name. For example, a type named "skip".
|
||||
|
||||
var directiveDefs = [];
|
||||
var schemaDef; // Schema extensions are collected which may add additional operation types.
|
||||
|
||||
var schemaExts = [];
|
||||
|
||||
for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
|
||||
var def = _documentAST$definiti2[_i2];
|
||||
|
||||
if (def.kind === _kinds.Kind.SCHEMA_DEFINITION) {
|
||||
schemaDef = def;
|
||||
} else if (def.kind === _kinds.Kind.SCHEMA_EXTENSION) {
|
||||
schemaExts.push(def);
|
||||
} else if ((0, _predicates.isTypeDefinitionNode)(def)) {
|
||||
typeDefs.push(def);
|
||||
} else if ((0, _predicates.isTypeExtensionNode)(def)) {
|
||||
var extendedTypeName = def.name.value;
|
||||
var existingTypeExts = typeExtsMap[extendedTypeName];
|
||||
typeExtsMap[extendedTypeName] = existingTypeExts ? existingTypeExts.concat([def]) : [def];
|
||||
} else if (def.kind === _kinds.Kind.DIRECTIVE_DEFINITION) {
|
||||
directiveDefs.push(def);
|
||||
}
|
||||
} // If this document contains no new types, extensions, or directives then
|
||||
// return the same unmodified GraphQLSchema instance.
|
||||
|
||||
|
||||
if (Object.keys(typeExtsMap).length === 0 && typeDefs.length === 0 && directiveDefs.length === 0 && schemaExts.length === 0 && !schemaDef) {
|
||||
return schema;
|
||||
}
|
||||
|
||||
var schemaConfig = schema.toConfig();
|
||||
var astBuilder = new _buildASTSchema.ASTDefinitionBuilder(options, function (typeName) {
|
||||
var type = typeMap[typeName];
|
||||
|
||||
if (type === undefined) {
|
||||
throw new Error("Unknown type: \"".concat(typeName, "\"."));
|
||||
}
|
||||
|
||||
return type;
|
||||
});
|
||||
var typeMap = (0, _keyValMap.default)(typeDefs, function (node) {
|
||||
return node.name.value;
|
||||
}, function (node) {
|
||||
return astBuilder.buildType(node);
|
||||
});
|
||||
|
||||
for (var _i4 = 0, _schemaConfig$types2 = schemaConfig.types; _i4 < _schemaConfig$types2.length; _i4++) {
|
||||
var existingType = _schemaConfig$types2[_i4];
|
||||
typeMap[existingType.name] = extendNamedType(existingType);
|
||||
} // Get the extended root operation types.
|
||||
|
||||
|
||||
var operationTypes = {
|
||||
query: schemaConfig.query && schemaConfig.query.name,
|
||||
mutation: schemaConfig.mutation && schemaConfig.mutation.name,
|
||||
subscription: schemaConfig.subscription && schemaConfig.subscription.name
|
||||
};
|
||||
|
||||
if (schemaDef) {
|
||||
for (var _i6 = 0, _schemaDef$operationT2 = schemaDef.operationTypes; _i6 < _schemaDef$operationT2.length; _i6++) {
|
||||
var _ref2 = _schemaDef$operationT2[_i6];
|
||||
var operation = _ref2.operation;
|
||||
var type = _ref2.type;
|
||||
operationTypes[operation] = type.name.value;
|
||||
}
|
||||
} // Then, incorporate schema definition and all schema extensions.
|
||||
|
||||
|
||||
for (var _i8 = 0; _i8 < schemaExts.length; _i8++) {
|
||||
var schemaExt = schemaExts[_i8];
|
||||
|
||||
if (schemaExt.operationTypes) {
|
||||
for (var _i10 = 0, _schemaExt$operationT2 = schemaExt.operationTypes; _i10 < _schemaExt$operationT2.length; _i10++) {
|
||||
var _ref4 = _schemaExt$operationT2[_i10];
|
||||
var _operation = _ref4.operation;
|
||||
var _type = _ref4.type;
|
||||
operationTypes[_operation] = _type.name.value;
|
||||
}
|
||||
}
|
||||
} // Support both original legacy names and extended legacy names.
|
||||
|
||||
|
||||
var allowedLegacyNames = schemaConfig.allowedLegacyNames.concat(options && options.allowedLegacyNames || []); // Then produce and return a Schema with these types.
|
||||
|
||||
return new _schema.GraphQLSchema({
|
||||
// Note: While this could make early assertions to get the correctly
|
||||
// typed values, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
query: getMaybeTypeByName(operationTypes.query),
|
||||
mutation: getMaybeTypeByName(operationTypes.mutation),
|
||||
subscription: getMaybeTypeByName(operationTypes.subscription),
|
||||
types: (0, _objectValues.default)(typeMap),
|
||||
directives: getMergedDirectives(),
|
||||
astNode: schemaDef || schemaConfig.astNode,
|
||||
extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExts),
|
||||
allowedLegacyNames: allowedLegacyNames
|
||||
}); // Below are functions used for producing this schema that have closed over
|
||||
// this scope and have access to the schema, cache, and newly defined types.
|
||||
|
||||
function replaceType(type) {
|
||||
if ((0, _definition.isListType)(type)) {
|
||||
return new _definition.GraphQLList(replaceType(type.ofType));
|
||||
} else if ((0, _definition.isNonNullType)(type)) {
|
||||
return new _definition.GraphQLNonNull(replaceType(type.ofType));
|
||||
}
|
||||
|
||||
return replaceNamedType(type);
|
||||
}
|
||||
|
||||
function replaceNamedType(type) {
|
||||
return typeMap[type.name];
|
||||
}
|
||||
|
||||
function getMaybeTypeByName(typeName) {
|
||||
return typeName ? typeMap[typeName] : null;
|
||||
}
|
||||
|
||||
function getMergedDirectives() {
|
||||
var existingDirectives = schema.getDirectives().map(extendDirective);
|
||||
existingDirectives || (0, _devAssert.default)(0, 'schema must have default directives');
|
||||
return existingDirectives.concat(directiveDefs.map(function (node) {
|
||||
return astBuilder.buildDirective(node);
|
||||
}));
|
||||
}
|
||||
|
||||
function extendNamedType(type) {
|
||||
if ((0, _introspection.isIntrospectionType)(type) || (0, _scalars.isSpecifiedScalarType)(type)) {
|
||||
// Builtin types are not extended.
|
||||
return type;
|
||||
} else if ((0, _definition.isScalarType)(type)) {
|
||||
return extendScalarType(type);
|
||||
} else if ((0, _definition.isObjectType)(type)) {
|
||||
return extendObjectType(type);
|
||||
} else if ((0, _definition.isInterfaceType)(type)) {
|
||||
return extendInterfaceType(type);
|
||||
} else if ((0, _definition.isUnionType)(type)) {
|
||||
return extendUnionType(type);
|
||||
} else if ((0, _definition.isEnumType)(type)) {
|
||||
return extendEnumType(type);
|
||||
} else if ((0, _definition.isInputObjectType)(type)) {
|
||||
return extendInputObjectType(type);
|
||||
} // Not reachable. All possible types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
(0, _invariant.default)(false, 'Unexpected type: ' + (0, _inspect.default)(type));
|
||||
}
|
||||
|
||||
function extendDirective(directive) {
|
||||
var config = directive.toConfig();
|
||||
return new _directives.GraphQLDirective(_objectSpread({}, config, {
|
||||
args: (0, _mapValue.default)(config.args, extendArg)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendInputObjectType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
var fieldNodes = (0, _flatMap.default)(extensions, function (node) {
|
||||
return node.fields || [];
|
||||
});
|
||||
return new _definition.GraphQLInputObjectType(_objectSpread({}, config, {
|
||||
fields: function fields() {
|
||||
return _objectSpread({}, (0, _mapValue.default)(config.fields, function (field) {
|
||||
return _objectSpread({}, field, {
|
||||
type: replaceType(field.type)
|
||||
});
|
||||
}), {}, (0, _keyValMap.default)(fieldNodes, function (field) {
|
||||
return field.name.value;
|
||||
}, function (field) {
|
||||
return astBuilder.buildInputField(field);
|
||||
}));
|
||||
},
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendEnumType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[type.name] || [];
|
||||
var valueNodes = (0, _flatMap.default)(extensions, function (node) {
|
||||
return node.values || [];
|
||||
});
|
||||
return new _definition.GraphQLEnumType(_objectSpread({}, config, {
|
||||
values: _objectSpread({}, config.values, {}, (0, _keyValMap.default)(valueNodes, function (value) {
|
||||
return value.name.value;
|
||||
}, function (value) {
|
||||
return astBuilder.buildEnumValue(value);
|
||||
})),
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendScalarType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
return new _definition.GraphQLScalarType(_objectSpread({}, config, {
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendObjectType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
var interfaceNodes = (0, _flatMap.default)(extensions, function (node) {
|
||||
return node.interfaces || [];
|
||||
});
|
||||
var fieldNodes = (0, _flatMap.default)(extensions, function (node) {
|
||||
return node.fields || [];
|
||||
});
|
||||
return new _definition.GraphQLObjectType(_objectSpread({}, config, {
|
||||
interfaces: function interfaces() {
|
||||
return [].concat(type.getInterfaces().map(replaceNamedType), interfaceNodes.map(function (node) {
|
||||
return astBuilder.getNamedType(node);
|
||||
}));
|
||||
},
|
||||
fields: function fields() {
|
||||
return _objectSpread({}, (0, _mapValue.default)(config.fields, extendField), {}, (0, _keyValMap.default)(fieldNodes, function (node) {
|
||||
return node.name.value;
|
||||
}, function (node) {
|
||||
return astBuilder.buildField(node);
|
||||
}));
|
||||
},
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendInterfaceType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
var fieldNodes = (0, _flatMap.default)(extensions, function (node) {
|
||||
return node.fields || [];
|
||||
});
|
||||
return new _definition.GraphQLInterfaceType(_objectSpread({}, config, {
|
||||
fields: function fields() {
|
||||
return _objectSpread({}, (0, _mapValue.default)(config.fields, extendField), {}, (0, _keyValMap.default)(fieldNodes, function (node) {
|
||||
return node.name.value;
|
||||
}, function (node) {
|
||||
return astBuilder.buildField(node);
|
||||
}));
|
||||
},
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendUnionType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
var typeNodes = (0, _flatMap.default)(extensions, function (node) {
|
||||
return node.types || [];
|
||||
});
|
||||
return new _definition.GraphQLUnionType(_objectSpread({}, config, {
|
||||
types: function types() {
|
||||
return [].concat(type.getTypes().map(replaceNamedType), typeNodes.map(function (node) {
|
||||
return astBuilder.getNamedType(node);
|
||||
}));
|
||||
},
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendField(field) {
|
||||
return _objectSpread({}, field, {
|
||||
type: replaceType(field.type),
|
||||
args: (0, _mapValue.default)(field.args, extendArg)
|
||||
});
|
||||
}
|
||||
|
||||
function extendArg(arg) {
|
||||
return _objectSpread({}, arg, {
|
||||
type: replaceType(arg.type)
|
||||
});
|
||||
}
|
||||
}
|
||||
407
node_modules/graphql/utilities/extendSchema.js.flow
generated
vendored
Normal file
407
node_modules/graphql/utilities/extendSchema.js.flow
generated
vendored
Normal file
@@ -0,0 +1,407 @@
|
||||
// @flow strict
|
||||
|
||||
import flatMap from '../polyfills/flatMap';
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
|
||||
import inspect from '../jsutils/inspect';
|
||||
import mapValue from '../jsutils/mapValue';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import devAssert from '../jsutils/devAssert';
|
||||
import keyValMap from '../jsutils/keyValMap';
|
||||
|
||||
import { Kind } from '../language/kinds';
|
||||
import {
|
||||
isTypeDefinitionNode,
|
||||
isTypeExtensionNode,
|
||||
} from '../language/predicates';
|
||||
import {
|
||||
type DocumentNode,
|
||||
type DirectiveDefinitionNode,
|
||||
type SchemaExtensionNode,
|
||||
type SchemaDefinitionNode,
|
||||
} from '../language/ast';
|
||||
|
||||
import { assertValidSDLExtension } from '../validation/validate';
|
||||
|
||||
import { GraphQLDirective } from '../type/directives';
|
||||
import { isSpecifiedScalarType } from '../type/scalars';
|
||||
import { isIntrospectionType } from '../type/introspection';
|
||||
import {
|
||||
type GraphQLSchemaValidationOptions,
|
||||
assertSchema,
|
||||
GraphQLSchema,
|
||||
} from '../type/schema';
|
||||
import {
|
||||
type GraphQLNamedType,
|
||||
isScalarType,
|
||||
isObjectType,
|
||||
isInterfaceType,
|
||||
isUnionType,
|
||||
isListType,
|
||||
isNonNullType,
|
||||
isEnumType,
|
||||
isInputObjectType,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
GraphQLScalarType,
|
||||
GraphQLObjectType,
|
||||
GraphQLInterfaceType,
|
||||
GraphQLUnionType,
|
||||
GraphQLEnumType,
|
||||
GraphQLInputObjectType,
|
||||
} from '../type/definition';
|
||||
|
||||
import { ASTDefinitionBuilder } from './buildASTSchema';
|
||||
|
||||
type Options = {|
|
||||
...GraphQLSchemaValidationOptions,
|
||||
|
||||
/**
|
||||
* Descriptions are defined as preceding string literals, however an older
|
||||
* experimental version of the SDL supported preceding comments as
|
||||
* descriptions. Set to true to enable this deprecated behavior.
|
||||
* This option is provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
commentDescriptions?: boolean,
|
||||
|
||||
/**
|
||||
* Set to true to assume the SDL is valid.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
assumeValidSDL?: boolean,
|
||||
|};
|
||||
|
||||
/**
|
||||
* Produces a new schema given an existing schema and a document which may
|
||||
* contain GraphQL type extensions and definitions. The original schema will
|
||||
* remain unaltered.
|
||||
*
|
||||
* Because a schema represents a graph of references, a schema cannot be
|
||||
* extended without effectively making an entire copy. We do not know until it's
|
||||
* too late if subgraphs remain unchanged.
|
||||
*
|
||||
* This algorithm copies the provided schema, applying extensions while
|
||||
* producing the copy. The original schema remains unaltered.
|
||||
*
|
||||
* Accepts options as a third argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function extendSchema(
|
||||
schema: GraphQLSchema,
|
||||
documentAST: DocumentNode,
|
||||
options?: Options,
|
||||
): GraphQLSchema {
|
||||
assertSchema(schema);
|
||||
|
||||
devAssert(
|
||||
documentAST && documentAST.kind === Kind.DOCUMENT,
|
||||
'Must provide valid Document AST',
|
||||
);
|
||||
|
||||
if (!options || !(options.assumeValid || options.assumeValidSDL)) {
|
||||
assertValidSDLExtension(documentAST, schema);
|
||||
}
|
||||
|
||||
// Collect the type definitions and extensions found in the document.
|
||||
const typeDefs = [];
|
||||
const typeExtsMap = Object.create(null);
|
||||
|
||||
// New directives and types are separate because a directives and types can
|
||||
// have the same name. For example, a type named "skip".
|
||||
const directiveDefs: Array<DirectiveDefinitionNode> = [];
|
||||
|
||||
let schemaDef: ?SchemaDefinitionNode;
|
||||
// Schema extensions are collected which may add additional operation types.
|
||||
const schemaExts: Array<SchemaExtensionNode> = [];
|
||||
|
||||
for (const def of documentAST.definitions) {
|
||||
if (def.kind === Kind.SCHEMA_DEFINITION) {
|
||||
schemaDef = def;
|
||||
} else if (def.kind === Kind.SCHEMA_EXTENSION) {
|
||||
schemaExts.push(def);
|
||||
} else if (isTypeDefinitionNode(def)) {
|
||||
typeDefs.push(def);
|
||||
} else if (isTypeExtensionNode(def)) {
|
||||
const extendedTypeName = def.name.value;
|
||||
const existingTypeExts = typeExtsMap[extendedTypeName];
|
||||
typeExtsMap[extendedTypeName] = existingTypeExts
|
||||
? existingTypeExts.concat([def])
|
||||
: [def];
|
||||
} else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
|
||||
directiveDefs.push(def);
|
||||
}
|
||||
}
|
||||
|
||||
// If this document contains no new types, extensions, or directives then
|
||||
// return the same unmodified GraphQLSchema instance.
|
||||
if (
|
||||
Object.keys(typeExtsMap).length === 0 &&
|
||||
typeDefs.length === 0 &&
|
||||
directiveDefs.length === 0 &&
|
||||
schemaExts.length === 0 &&
|
||||
!schemaDef
|
||||
) {
|
||||
return schema;
|
||||
}
|
||||
|
||||
const schemaConfig = schema.toConfig();
|
||||
const astBuilder = new ASTDefinitionBuilder(options, typeName => {
|
||||
const type = typeMap[typeName];
|
||||
if (type === undefined) {
|
||||
throw new Error(`Unknown type: "${typeName}".`);
|
||||
}
|
||||
return type;
|
||||
});
|
||||
|
||||
const typeMap = keyValMap(
|
||||
typeDefs,
|
||||
node => node.name.value,
|
||||
node => astBuilder.buildType(node),
|
||||
);
|
||||
for (const existingType of schemaConfig.types) {
|
||||
typeMap[existingType.name] = extendNamedType(existingType);
|
||||
}
|
||||
|
||||
// Get the extended root operation types.
|
||||
const operationTypes = {
|
||||
query: schemaConfig.query && schemaConfig.query.name,
|
||||
mutation: schemaConfig.mutation && schemaConfig.mutation.name,
|
||||
subscription: schemaConfig.subscription && schemaConfig.subscription.name,
|
||||
};
|
||||
|
||||
if (schemaDef) {
|
||||
for (const { operation, type } of schemaDef.operationTypes) {
|
||||
operationTypes[operation] = type.name.value;
|
||||
}
|
||||
}
|
||||
|
||||
// Then, incorporate schema definition and all schema extensions.
|
||||
for (const schemaExt of schemaExts) {
|
||||
if (schemaExt.operationTypes) {
|
||||
for (const { operation, type } of schemaExt.operationTypes) {
|
||||
operationTypes[operation] = type.name.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Support both original legacy names and extended legacy names.
|
||||
const allowedLegacyNames = schemaConfig.allowedLegacyNames.concat(
|
||||
(options && options.allowedLegacyNames) || [],
|
||||
);
|
||||
|
||||
// Then produce and return a Schema with these types.
|
||||
return new GraphQLSchema({
|
||||
// Note: While this could make early assertions to get the correctly
|
||||
// typed values, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
query: (getMaybeTypeByName(operationTypes.query): any),
|
||||
mutation: (getMaybeTypeByName(operationTypes.mutation): any),
|
||||
subscription: (getMaybeTypeByName(operationTypes.subscription): any),
|
||||
|
||||
types: objectValues(typeMap),
|
||||
directives: getMergedDirectives(),
|
||||
astNode: schemaDef || schemaConfig.astNode,
|
||||
extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExts),
|
||||
allowedLegacyNames,
|
||||
});
|
||||
|
||||
// Below are functions used for producing this schema that have closed over
|
||||
// this scope and have access to the schema, cache, and newly defined types.
|
||||
|
||||
function replaceType(type) {
|
||||
if (isListType(type)) {
|
||||
return new GraphQLList(replaceType(type.ofType));
|
||||
} else if (isNonNullType(type)) {
|
||||
return new GraphQLNonNull(replaceType(type.ofType));
|
||||
}
|
||||
return replaceNamedType(type);
|
||||
}
|
||||
|
||||
function replaceNamedType<T: GraphQLNamedType>(type: T): T {
|
||||
return ((typeMap[type.name]: any): T);
|
||||
}
|
||||
|
||||
function getMaybeTypeByName(typeName: ?string): ?GraphQLNamedType {
|
||||
return typeName ? typeMap[typeName] : null;
|
||||
}
|
||||
|
||||
function getMergedDirectives(): Array<GraphQLDirective> {
|
||||
const existingDirectives = schema.getDirectives().map(extendDirective);
|
||||
devAssert(existingDirectives, 'schema must have default directives');
|
||||
|
||||
return existingDirectives.concat(
|
||||
directiveDefs.map(node => astBuilder.buildDirective(node)),
|
||||
);
|
||||
}
|
||||
|
||||
function extendNamedType(type: GraphQLNamedType): GraphQLNamedType {
|
||||
if (isIntrospectionType(type) || isSpecifiedScalarType(type)) {
|
||||
// Builtin types are not extended.
|
||||
return type;
|
||||
} else if (isScalarType(type)) {
|
||||
return extendScalarType(type);
|
||||
} else if (isObjectType(type)) {
|
||||
return extendObjectType(type);
|
||||
} else if (isInterfaceType(type)) {
|
||||
return extendInterfaceType(type);
|
||||
} else if (isUnionType(type)) {
|
||||
return extendUnionType(type);
|
||||
} else if (isEnumType(type)) {
|
||||
return extendEnumType(type);
|
||||
} else if (isInputObjectType(type)) {
|
||||
return extendInputObjectType(type);
|
||||
}
|
||||
|
||||
// Not reachable. All possible types have been considered.
|
||||
invariant(false, 'Unexpected type: ' + inspect((type: empty)));
|
||||
}
|
||||
|
||||
function extendDirective(directive: GraphQLDirective): GraphQLDirective {
|
||||
const config = directive.toConfig();
|
||||
|
||||
return new GraphQLDirective({
|
||||
...config,
|
||||
args: mapValue(config.args, extendArg),
|
||||
});
|
||||
}
|
||||
|
||||
function extendInputObjectType(
|
||||
type: GraphQLInputObjectType,
|
||||
): GraphQLInputObjectType {
|
||||
const config = type.toConfig();
|
||||
const extensions = typeExtsMap[config.name] || [];
|
||||
const fieldNodes = flatMap(extensions, node => node.fields || []);
|
||||
|
||||
return new GraphQLInputObjectType({
|
||||
...config,
|
||||
fields: () => ({
|
||||
...mapValue(config.fields, field => ({
|
||||
...field,
|
||||
type: replaceType(field.type),
|
||||
})),
|
||||
...keyValMap(
|
||||
fieldNodes,
|
||||
field => field.name.value,
|
||||
field => astBuilder.buildInputField(field),
|
||||
),
|
||||
}),
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions),
|
||||
});
|
||||
}
|
||||
|
||||
function extendEnumType(type: GraphQLEnumType): GraphQLEnumType {
|
||||
const config = type.toConfig();
|
||||
const extensions = typeExtsMap[type.name] || [];
|
||||
const valueNodes = flatMap(extensions, node => node.values || []);
|
||||
|
||||
return new GraphQLEnumType({
|
||||
...config,
|
||||
values: {
|
||||
...config.values,
|
||||
...keyValMap(
|
||||
valueNodes,
|
||||
value => value.name.value,
|
||||
value => astBuilder.buildEnumValue(value),
|
||||
),
|
||||
},
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions),
|
||||
});
|
||||
}
|
||||
|
||||
function extendScalarType(type: GraphQLScalarType): GraphQLScalarType {
|
||||
const config = type.toConfig();
|
||||
const extensions = typeExtsMap[config.name] || [];
|
||||
|
||||
return new GraphQLScalarType({
|
||||
...config,
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions),
|
||||
});
|
||||
}
|
||||
|
||||
function extendObjectType(type: GraphQLObjectType): GraphQLObjectType {
|
||||
const config = type.toConfig();
|
||||
const extensions = typeExtsMap[config.name] || [];
|
||||
const interfaceNodes = flatMap(extensions, node => node.interfaces || []);
|
||||
const fieldNodes = flatMap(extensions, node => node.fields || []);
|
||||
|
||||
return new GraphQLObjectType({
|
||||
...config,
|
||||
interfaces: () => [
|
||||
...type.getInterfaces().map(replaceNamedType),
|
||||
// Note: While this could make early assertions to get the correctly
|
||||
// typed values, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
...interfaceNodes.map(node => (astBuilder.getNamedType(node): any)),
|
||||
],
|
||||
fields: () => ({
|
||||
...mapValue(config.fields, extendField),
|
||||
...keyValMap(
|
||||
fieldNodes,
|
||||
node => node.name.value,
|
||||
node => astBuilder.buildField(node),
|
||||
),
|
||||
}),
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions),
|
||||
});
|
||||
}
|
||||
|
||||
function extendInterfaceType(
|
||||
type: GraphQLInterfaceType,
|
||||
): GraphQLInterfaceType {
|
||||
const config = type.toConfig();
|
||||
const extensions = typeExtsMap[config.name] || [];
|
||||
const fieldNodes = flatMap(extensions, node => node.fields || []);
|
||||
|
||||
return new GraphQLInterfaceType({
|
||||
...config,
|
||||
fields: () => ({
|
||||
...mapValue(config.fields, extendField),
|
||||
...keyValMap(
|
||||
fieldNodes,
|
||||
node => node.name.value,
|
||||
node => astBuilder.buildField(node),
|
||||
),
|
||||
}),
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions),
|
||||
});
|
||||
}
|
||||
|
||||
function extendUnionType(type: GraphQLUnionType): GraphQLUnionType {
|
||||
const config = type.toConfig();
|
||||
const extensions = typeExtsMap[config.name] || [];
|
||||
const typeNodes = flatMap(extensions, node => node.types || []);
|
||||
|
||||
return new GraphQLUnionType({
|
||||
...config,
|
||||
types: () => [
|
||||
...type.getTypes().map(replaceNamedType),
|
||||
// Note: While this could make early assertions to get the correctly
|
||||
// typed values, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
...typeNodes.map(node => (astBuilder.getNamedType(node): any)),
|
||||
],
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions),
|
||||
});
|
||||
}
|
||||
|
||||
function extendField(field) {
|
||||
return {
|
||||
...field,
|
||||
type: replaceType(field.type),
|
||||
args: mapValue(field.args, extendArg),
|
||||
};
|
||||
}
|
||||
|
||||
function extendArg(arg) {
|
||||
return {
|
||||
...arg,
|
||||
type: replaceType(arg.type),
|
||||
};
|
||||
}
|
||||
}
|
||||
327
node_modules/graphql/utilities/extendSchema.mjs
generated
vendored
Normal file
327
node_modules/graphql/utilities/extendSchema.mjs
generated
vendored
Normal file
@@ -0,0 +1,327 @@
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
import flatMap from '../polyfills/flatMap';
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import mapValue from '../jsutils/mapValue';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import devAssert from '../jsutils/devAssert';
|
||||
import keyValMap from '../jsutils/keyValMap';
|
||||
import { Kind } from '../language/kinds';
|
||||
import { isTypeDefinitionNode, isTypeExtensionNode } from '../language/predicates';
|
||||
import { assertValidSDLExtension } from '../validation/validate';
|
||||
import { GraphQLDirective } from '../type/directives';
|
||||
import { isSpecifiedScalarType } from '../type/scalars';
|
||||
import { isIntrospectionType } from '../type/introspection';
|
||||
import { assertSchema, GraphQLSchema } from '../type/schema';
|
||||
import { isScalarType, isObjectType, isInterfaceType, isUnionType, isListType, isNonNullType, isEnumType, isInputObjectType, GraphQLList, GraphQLNonNull, GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType } from '../type/definition';
|
||||
import { ASTDefinitionBuilder } from './buildASTSchema';
|
||||
|
||||
/**
|
||||
* Produces a new schema given an existing schema and a document which may
|
||||
* contain GraphQL type extensions and definitions. The original schema will
|
||||
* remain unaltered.
|
||||
*
|
||||
* Because a schema represents a graph of references, a schema cannot be
|
||||
* extended without effectively making an entire copy. We do not know until it's
|
||||
* too late if subgraphs remain unchanged.
|
||||
*
|
||||
* This algorithm copies the provided schema, applying extensions while
|
||||
* producing the copy. The original schema remains unaltered.
|
||||
*
|
||||
* Accepts options as a third argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function extendSchema(schema, documentAST, options) {
|
||||
assertSchema(schema);
|
||||
documentAST && documentAST.kind === Kind.DOCUMENT || devAssert(0, 'Must provide valid Document AST');
|
||||
|
||||
if (!options || !(options.assumeValid || options.assumeValidSDL)) {
|
||||
assertValidSDLExtension(documentAST, schema);
|
||||
} // Collect the type definitions and extensions found in the document.
|
||||
|
||||
|
||||
var typeDefs = [];
|
||||
var typeExtsMap = Object.create(null); // New directives and types are separate because a directives and types can
|
||||
// have the same name. For example, a type named "skip".
|
||||
|
||||
var directiveDefs = [];
|
||||
var schemaDef; // Schema extensions are collected which may add additional operation types.
|
||||
|
||||
var schemaExts = [];
|
||||
|
||||
for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
|
||||
var def = _documentAST$definiti2[_i2];
|
||||
|
||||
if (def.kind === Kind.SCHEMA_DEFINITION) {
|
||||
schemaDef = def;
|
||||
} else if (def.kind === Kind.SCHEMA_EXTENSION) {
|
||||
schemaExts.push(def);
|
||||
} else if (isTypeDefinitionNode(def)) {
|
||||
typeDefs.push(def);
|
||||
} else if (isTypeExtensionNode(def)) {
|
||||
var extendedTypeName = def.name.value;
|
||||
var existingTypeExts = typeExtsMap[extendedTypeName];
|
||||
typeExtsMap[extendedTypeName] = existingTypeExts ? existingTypeExts.concat([def]) : [def];
|
||||
} else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
|
||||
directiveDefs.push(def);
|
||||
}
|
||||
} // If this document contains no new types, extensions, or directives then
|
||||
// return the same unmodified GraphQLSchema instance.
|
||||
|
||||
|
||||
if (Object.keys(typeExtsMap).length === 0 && typeDefs.length === 0 && directiveDefs.length === 0 && schemaExts.length === 0 && !schemaDef) {
|
||||
return schema;
|
||||
}
|
||||
|
||||
var schemaConfig = schema.toConfig();
|
||||
var astBuilder = new ASTDefinitionBuilder(options, function (typeName) {
|
||||
var type = typeMap[typeName];
|
||||
|
||||
if (type === undefined) {
|
||||
throw new Error("Unknown type: \"".concat(typeName, "\"."));
|
||||
}
|
||||
|
||||
return type;
|
||||
});
|
||||
var typeMap = keyValMap(typeDefs, function (node) {
|
||||
return node.name.value;
|
||||
}, function (node) {
|
||||
return astBuilder.buildType(node);
|
||||
});
|
||||
|
||||
for (var _i4 = 0, _schemaConfig$types2 = schemaConfig.types; _i4 < _schemaConfig$types2.length; _i4++) {
|
||||
var existingType = _schemaConfig$types2[_i4];
|
||||
typeMap[existingType.name] = extendNamedType(existingType);
|
||||
} // Get the extended root operation types.
|
||||
|
||||
|
||||
var operationTypes = {
|
||||
query: schemaConfig.query && schemaConfig.query.name,
|
||||
mutation: schemaConfig.mutation && schemaConfig.mutation.name,
|
||||
subscription: schemaConfig.subscription && schemaConfig.subscription.name
|
||||
};
|
||||
|
||||
if (schemaDef) {
|
||||
for (var _i6 = 0, _schemaDef$operationT2 = schemaDef.operationTypes; _i6 < _schemaDef$operationT2.length; _i6++) {
|
||||
var _ref2 = _schemaDef$operationT2[_i6];
|
||||
var operation = _ref2.operation;
|
||||
var type = _ref2.type;
|
||||
operationTypes[operation] = type.name.value;
|
||||
}
|
||||
} // Then, incorporate schema definition and all schema extensions.
|
||||
|
||||
|
||||
for (var _i8 = 0; _i8 < schemaExts.length; _i8++) {
|
||||
var schemaExt = schemaExts[_i8];
|
||||
|
||||
if (schemaExt.operationTypes) {
|
||||
for (var _i10 = 0, _schemaExt$operationT2 = schemaExt.operationTypes; _i10 < _schemaExt$operationT2.length; _i10++) {
|
||||
var _ref4 = _schemaExt$operationT2[_i10];
|
||||
var _operation = _ref4.operation;
|
||||
var _type = _ref4.type;
|
||||
operationTypes[_operation] = _type.name.value;
|
||||
}
|
||||
}
|
||||
} // Support both original legacy names and extended legacy names.
|
||||
|
||||
|
||||
var allowedLegacyNames = schemaConfig.allowedLegacyNames.concat(options && options.allowedLegacyNames || []); // Then produce and return a Schema with these types.
|
||||
|
||||
return new GraphQLSchema({
|
||||
// Note: While this could make early assertions to get the correctly
|
||||
// typed values, that would throw immediately while type system
|
||||
// validation with validateSchema() will produce more actionable results.
|
||||
query: getMaybeTypeByName(operationTypes.query),
|
||||
mutation: getMaybeTypeByName(operationTypes.mutation),
|
||||
subscription: getMaybeTypeByName(operationTypes.subscription),
|
||||
types: objectValues(typeMap),
|
||||
directives: getMergedDirectives(),
|
||||
astNode: schemaDef || schemaConfig.astNode,
|
||||
extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExts),
|
||||
allowedLegacyNames: allowedLegacyNames
|
||||
}); // Below are functions used for producing this schema that have closed over
|
||||
// this scope and have access to the schema, cache, and newly defined types.
|
||||
|
||||
function replaceType(type) {
|
||||
if (isListType(type)) {
|
||||
return new GraphQLList(replaceType(type.ofType));
|
||||
} else if (isNonNullType(type)) {
|
||||
return new GraphQLNonNull(replaceType(type.ofType));
|
||||
}
|
||||
|
||||
return replaceNamedType(type);
|
||||
}
|
||||
|
||||
function replaceNamedType(type) {
|
||||
return typeMap[type.name];
|
||||
}
|
||||
|
||||
function getMaybeTypeByName(typeName) {
|
||||
return typeName ? typeMap[typeName] : null;
|
||||
}
|
||||
|
||||
function getMergedDirectives() {
|
||||
var existingDirectives = schema.getDirectives().map(extendDirective);
|
||||
existingDirectives || devAssert(0, 'schema must have default directives');
|
||||
return existingDirectives.concat(directiveDefs.map(function (node) {
|
||||
return astBuilder.buildDirective(node);
|
||||
}));
|
||||
}
|
||||
|
||||
function extendNamedType(type) {
|
||||
if (isIntrospectionType(type) || isSpecifiedScalarType(type)) {
|
||||
// Builtin types are not extended.
|
||||
return type;
|
||||
} else if (isScalarType(type)) {
|
||||
return extendScalarType(type);
|
||||
} else if (isObjectType(type)) {
|
||||
return extendObjectType(type);
|
||||
} else if (isInterfaceType(type)) {
|
||||
return extendInterfaceType(type);
|
||||
} else if (isUnionType(type)) {
|
||||
return extendUnionType(type);
|
||||
} else if (isEnumType(type)) {
|
||||
return extendEnumType(type);
|
||||
} else if (isInputObjectType(type)) {
|
||||
return extendInputObjectType(type);
|
||||
} // Not reachable. All possible types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
invariant(false, 'Unexpected type: ' + inspect(type));
|
||||
}
|
||||
|
||||
function extendDirective(directive) {
|
||||
var config = directive.toConfig();
|
||||
return new GraphQLDirective(_objectSpread({}, config, {
|
||||
args: mapValue(config.args, extendArg)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendInputObjectType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
var fieldNodes = flatMap(extensions, function (node) {
|
||||
return node.fields || [];
|
||||
});
|
||||
return new GraphQLInputObjectType(_objectSpread({}, config, {
|
||||
fields: function fields() {
|
||||
return _objectSpread({}, mapValue(config.fields, function (field) {
|
||||
return _objectSpread({}, field, {
|
||||
type: replaceType(field.type)
|
||||
});
|
||||
}), {}, keyValMap(fieldNodes, function (field) {
|
||||
return field.name.value;
|
||||
}, function (field) {
|
||||
return astBuilder.buildInputField(field);
|
||||
}));
|
||||
},
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendEnumType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[type.name] || [];
|
||||
var valueNodes = flatMap(extensions, function (node) {
|
||||
return node.values || [];
|
||||
});
|
||||
return new GraphQLEnumType(_objectSpread({}, config, {
|
||||
values: _objectSpread({}, config.values, {}, keyValMap(valueNodes, function (value) {
|
||||
return value.name.value;
|
||||
}, function (value) {
|
||||
return astBuilder.buildEnumValue(value);
|
||||
})),
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendScalarType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
return new GraphQLScalarType(_objectSpread({}, config, {
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendObjectType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
var interfaceNodes = flatMap(extensions, function (node) {
|
||||
return node.interfaces || [];
|
||||
});
|
||||
var fieldNodes = flatMap(extensions, function (node) {
|
||||
return node.fields || [];
|
||||
});
|
||||
return new GraphQLObjectType(_objectSpread({}, config, {
|
||||
interfaces: function interfaces() {
|
||||
return [].concat(type.getInterfaces().map(replaceNamedType), interfaceNodes.map(function (node) {
|
||||
return astBuilder.getNamedType(node);
|
||||
}));
|
||||
},
|
||||
fields: function fields() {
|
||||
return _objectSpread({}, mapValue(config.fields, extendField), {}, keyValMap(fieldNodes, function (node) {
|
||||
return node.name.value;
|
||||
}, function (node) {
|
||||
return astBuilder.buildField(node);
|
||||
}));
|
||||
},
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendInterfaceType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
var fieldNodes = flatMap(extensions, function (node) {
|
||||
return node.fields || [];
|
||||
});
|
||||
return new GraphQLInterfaceType(_objectSpread({}, config, {
|
||||
fields: function fields() {
|
||||
return _objectSpread({}, mapValue(config.fields, extendField), {}, keyValMap(fieldNodes, function (node) {
|
||||
return node.name.value;
|
||||
}, function (node) {
|
||||
return astBuilder.buildField(node);
|
||||
}));
|
||||
},
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendUnionType(type) {
|
||||
var config = type.toConfig();
|
||||
var extensions = typeExtsMap[config.name] || [];
|
||||
var typeNodes = flatMap(extensions, function (node) {
|
||||
return node.types || [];
|
||||
});
|
||||
return new GraphQLUnionType(_objectSpread({}, config, {
|
||||
types: function types() {
|
||||
return [].concat(type.getTypes().map(replaceNamedType), typeNodes.map(function (node) {
|
||||
return astBuilder.getNamedType(node);
|
||||
}));
|
||||
},
|
||||
extensionASTNodes: config.extensionASTNodes.concat(extensions)
|
||||
}));
|
||||
}
|
||||
|
||||
function extendField(field) {
|
||||
return _objectSpread({}, field, {
|
||||
type: replaceType(field.type),
|
||||
args: mapValue(field.args, extendArg)
|
||||
});
|
||||
}
|
||||
|
||||
function extendArg(arg) {
|
||||
return _objectSpread({}, arg, {
|
||||
type: replaceType(arg.type)
|
||||
});
|
||||
}
|
||||
}
|
||||
64
node_modules/graphql/utilities/findBreakingChanges.d.ts
generated
vendored
Normal file
64
node_modules/graphql/utilities/findBreakingChanges.d.ts
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
import { GraphQLDirective } from '../type/directives';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { DirectiveLocationEnum } from '../language/directiveLocation';
|
||||
|
||||
export const BreakingChangeType: _BreakingChangeType;
|
||||
|
||||
// @internal
|
||||
type _BreakingChangeType = {
|
||||
TYPE_REMOVED: 'TYPE_REMOVED';
|
||||
TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND';
|
||||
TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION';
|
||||
VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM';
|
||||
REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED';
|
||||
INTERFACE_REMOVED_FROM_OBJECT: 'INTERFACE_REMOVED_FROM_OBJECT';
|
||||
FIELD_REMOVED: 'FIELD_REMOVED';
|
||||
FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND';
|
||||
REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED';
|
||||
ARG_REMOVED: 'ARG_REMOVED';
|
||||
ARG_CHANGED_KIND: 'ARG_CHANGED_KIND';
|
||||
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED';
|
||||
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED';
|
||||
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED';
|
||||
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED';
|
||||
};
|
||||
|
||||
export const DangerousChangeType: _DangerousChangeType;
|
||||
|
||||
// @internal
|
||||
type _DangerousChangeType = {
|
||||
VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM';
|
||||
TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION';
|
||||
OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED';
|
||||
OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED';
|
||||
INTERFACE_ADDED_TO_OBJECT: 'INTERFACE_ADDED_TO_OBJECT';
|
||||
ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE';
|
||||
};
|
||||
|
||||
export interface BreakingChange {
|
||||
type: keyof _BreakingChangeType;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface DangerousChange {
|
||||
type: keyof _DangerousChangeType;
|
||||
description: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two schemas, returns an Array containing descriptions of all the types
|
||||
* of breaking changes covered by the other functions down below.
|
||||
*/
|
||||
export function findBreakingChanges(
|
||||
oldSchema: GraphQLSchema,
|
||||
newSchema: GraphQLSchema,
|
||||
): Array<BreakingChange>;
|
||||
|
||||
/**
|
||||
* Given two schemas, returns an Array containing descriptions of all the types
|
||||
* of potentially dangerous changes covered by the other functions down below.
|
||||
*/
|
||||
export function findDangerousChanges(
|
||||
oldSchema: GraphQLSchema,
|
||||
newSchema: GraphQLSchema,
|
||||
): Array<DangerousChange>;
|
||||
511
node_modules/graphql/utilities/findBreakingChanges.js
generated
vendored
Normal file
511
node_modules/graphql/utilities/findBreakingChanges.js
generated
vendored
Normal file
@@ -0,0 +1,511 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.findBreakingChanges = findBreakingChanges;
|
||||
exports.findDangerousChanges = findDangerousChanges;
|
||||
exports.DangerousChangeType = exports.BreakingChangeType = void 0;
|
||||
|
||||
var _objectValues = _interopRequireDefault(require("../polyfills/objectValues"));
|
||||
|
||||
var _keyMap = _interopRequireDefault(require("../jsutils/keyMap"));
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _printer = require("../language/printer");
|
||||
|
||||
var _visitor = require("../language/visitor");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
var _astFromValue = require("./astFromValue");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
var BreakingChangeType = Object.freeze({
|
||||
TYPE_REMOVED: 'TYPE_REMOVED',
|
||||
TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND',
|
||||
TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION',
|
||||
VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM',
|
||||
REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED',
|
||||
INTERFACE_REMOVED_FROM_OBJECT: 'INTERFACE_REMOVED_FROM_OBJECT',
|
||||
FIELD_REMOVED: 'FIELD_REMOVED',
|
||||
FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND',
|
||||
REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED',
|
||||
ARG_REMOVED: 'ARG_REMOVED',
|
||||
ARG_CHANGED_KIND: 'ARG_CHANGED_KIND',
|
||||
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED',
|
||||
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED',
|
||||
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED',
|
||||
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED'
|
||||
});
|
||||
exports.BreakingChangeType = BreakingChangeType;
|
||||
var DangerousChangeType = Object.freeze({
|
||||
VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM',
|
||||
TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION',
|
||||
OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED',
|
||||
OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED',
|
||||
INTERFACE_ADDED_TO_OBJECT: 'INTERFACE_ADDED_TO_OBJECT',
|
||||
ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE'
|
||||
});
|
||||
exports.DangerousChangeType = DangerousChangeType;
|
||||
|
||||
/**
|
||||
* Given two schemas, returns an Array containing descriptions of all the types
|
||||
* of breaking changes covered by the other functions down below.
|
||||
*/
|
||||
function findBreakingChanges(oldSchema, newSchema) {
|
||||
var breakingChanges = findSchemaChanges(oldSchema, newSchema).filter(function (change) {
|
||||
return change.type in BreakingChangeType;
|
||||
});
|
||||
return breakingChanges;
|
||||
}
|
||||
/**
|
||||
* Given two schemas, returns an Array containing descriptions of all the types
|
||||
* of potentially dangerous changes covered by the other functions down below.
|
||||
*/
|
||||
|
||||
|
||||
function findDangerousChanges(oldSchema, newSchema) {
|
||||
var dangerousChanges = findSchemaChanges(oldSchema, newSchema).filter(function (change) {
|
||||
return change.type in DangerousChangeType;
|
||||
});
|
||||
return dangerousChanges;
|
||||
}
|
||||
|
||||
function findSchemaChanges(oldSchema, newSchema) {
|
||||
return [].concat(findTypeChanges(oldSchema, newSchema), findDirectiveChanges(oldSchema, newSchema));
|
||||
}
|
||||
|
||||
function findDirectiveChanges(oldSchema, newSchema) {
|
||||
var schemaChanges = [];
|
||||
var directivesDiff = diff(oldSchema.getDirectives(), newSchema.getDirectives());
|
||||
|
||||
for (var _i2 = 0, _directivesDiff$remov2 = directivesDiff.removed; _i2 < _directivesDiff$remov2.length; _i2++) {
|
||||
var oldDirective = _directivesDiff$remov2[_i2];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.DIRECTIVE_REMOVED,
|
||||
description: "".concat(oldDirective.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i4 = 0, _directivesDiff$persi2 = directivesDiff.persisted; _i4 < _directivesDiff$persi2.length; _i4++) {
|
||||
var _ref2 = _directivesDiff$persi2[_i4];
|
||||
var _oldDirective = _ref2[0];
|
||||
var newDirective = _ref2[1];
|
||||
var argsDiff = diff(_oldDirective.args, newDirective.args);
|
||||
|
||||
for (var _i6 = 0, _argsDiff$added2 = argsDiff.added; _i6 < _argsDiff$added2.length; _i6++) {
|
||||
var newArg = _argsDiff$added2[_i6];
|
||||
|
||||
if ((0, _definition.isRequiredArgument)(newArg)) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.REQUIRED_DIRECTIVE_ARG_ADDED,
|
||||
description: "A required arg ".concat(newArg.name, " on directive ").concat(_oldDirective.name, " was added.")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (var _i8 = 0, _argsDiff$removed2 = argsDiff.removed; _i8 < _argsDiff$removed2.length; _i8++) {
|
||||
var oldArg = _argsDiff$removed2[_i8];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.DIRECTIVE_ARG_REMOVED,
|
||||
description: "".concat(oldArg.name, " was removed from ").concat(_oldDirective.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i10 = 0, _oldDirective$locatio2 = _oldDirective.locations; _i10 < _oldDirective$locatio2.length; _i10++) {
|
||||
var location = _oldDirective$locatio2[_i10];
|
||||
|
||||
if (newDirective.locations.indexOf(location) === -1) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
|
||||
description: "".concat(location, " was removed from ").concat(_oldDirective.name, ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findTypeChanges(oldSchema, newSchema) {
|
||||
var schemaChanges = [];
|
||||
var typesDiff = diff((0, _objectValues.default)(oldSchema.getTypeMap()), (0, _objectValues.default)(newSchema.getTypeMap()));
|
||||
|
||||
for (var _i12 = 0, _typesDiff$removed2 = typesDiff.removed; _i12 < _typesDiff$removed2.length; _i12++) {
|
||||
var oldType = _typesDiff$removed2[_i12];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.TYPE_REMOVED,
|
||||
description: "".concat(oldType.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i14 = 0, _typesDiff$persisted2 = typesDiff.persisted; _i14 < _typesDiff$persisted2.length; _i14++) {
|
||||
var _ref4 = _typesDiff$persisted2[_i14];
|
||||
var _oldType = _ref4[0];
|
||||
var newType = _ref4[1];
|
||||
|
||||
if ((0, _definition.isEnumType)(_oldType) && (0, _definition.isEnumType)(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findEnumTypeChanges(_oldType, newType));
|
||||
} else if ((0, _definition.isUnionType)(_oldType) && (0, _definition.isUnionType)(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findUnionTypeChanges(_oldType, newType));
|
||||
} else if ((0, _definition.isInputObjectType)(_oldType) && (0, _definition.isInputObjectType)(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findInputObjectTypeChanges(_oldType, newType));
|
||||
} else if ((0, _definition.isObjectType)(_oldType) && (0, _definition.isObjectType)(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findObjectTypeChanges(_oldType, newType));
|
||||
} else if ((0, _definition.isInterfaceType)(_oldType) && (0, _definition.isInterfaceType)(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findFieldChanges(_oldType, newType));
|
||||
} else if (_oldType.constructor !== newType.constructor) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.TYPE_CHANGED_KIND,
|
||||
description: "".concat(_oldType.name, " changed from ") + "".concat(typeKindName(_oldType), " to ").concat(typeKindName(newType), ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findInputObjectTypeChanges(oldType, newType) {
|
||||
var schemaChanges = [];
|
||||
var fieldsDiff = diff((0, _objectValues.default)(oldType.getFields()), (0, _objectValues.default)(newType.getFields()));
|
||||
|
||||
for (var _i16 = 0, _fieldsDiff$added2 = fieldsDiff.added; _i16 < _fieldsDiff$added2.length; _i16++) {
|
||||
var newField = _fieldsDiff$added2[_i16];
|
||||
|
||||
if ((0, _definition.isRequiredInputField)(newField)) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
|
||||
description: "A required field ".concat(newField.name, " on input type ").concat(oldType.name, " was added.")
|
||||
});
|
||||
} else {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
|
||||
description: "An optional field ".concat(newField.name, " on input type ").concat(oldType.name, " was added.")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (var _i18 = 0, _fieldsDiff$removed2 = fieldsDiff.removed; _i18 < _fieldsDiff$removed2.length; _i18++) {
|
||||
var oldField = _fieldsDiff$removed2[_i18];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_REMOVED,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i20 = 0, _fieldsDiff$persisted2 = fieldsDiff.persisted; _i20 < _fieldsDiff$persisted2.length; _i20++) {
|
||||
var _ref6 = _fieldsDiff$persisted2[_i20];
|
||||
var _oldField = _ref6[0];
|
||||
var _newField = _ref6[1];
|
||||
var isSafe = isChangeSafeForInputObjectFieldOrFieldArg(_oldField.type, _newField.type);
|
||||
|
||||
if (!isSafe) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_CHANGED_KIND,
|
||||
description: "".concat(oldType.name, ".").concat(_oldField.name, " changed type from ") + "".concat(String(_oldField.type), " to ").concat(String(_newField.type), ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findUnionTypeChanges(oldType, newType) {
|
||||
var schemaChanges = [];
|
||||
var possibleTypesDiff = diff(oldType.getTypes(), newType.getTypes());
|
||||
|
||||
for (var _i22 = 0, _possibleTypesDiff$ad2 = possibleTypesDiff.added; _i22 < _possibleTypesDiff$ad2.length; _i22++) {
|
||||
var newPossibleType = _possibleTypesDiff$ad2[_i22];
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.TYPE_ADDED_TO_UNION,
|
||||
description: "".concat(newPossibleType.name, " was added to union type ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i24 = 0, _possibleTypesDiff$re2 = possibleTypesDiff.removed; _i24 < _possibleTypesDiff$re2.length; _i24++) {
|
||||
var oldPossibleType = _possibleTypesDiff$re2[_i24];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.TYPE_REMOVED_FROM_UNION,
|
||||
description: "".concat(oldPossibleType.name, " was removed from union type ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findEnumTypeChanges(oldType, newType) {
|
||||
var schemaChanges = [];
|
||||
var valuesDiff = diff(oldType.getValues(), newType.getValues());
|
||||
|
||||
for (var _i26 = 0, _valuesDiff$added2 = valuesDiff.added; _i26 < _valuesDiff$added2.length; _i26++) {
|
||||
var newValue = _valuesDiff$added2[_i26];
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.VALUE_ADDED_TO_ENUM,
|
||||
description: "".concat(newValue.name, " was added to enum type ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i28 = 0, _valuesDiff$removed2 = valuesDiff.removed; _i28 < _valuesDiff$removed2.length; _i28++) {
|
||||
var oldValue = _valuesDiff$removed2[_i28];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM,
|
||||
description: "".concat(oldValue.name, " was removed from enum type ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findObjectTypeChanges(oldType, newType) {
|
||||
var schemaChanges = findFieldChanges(oldType, newType);
|
||||
var interfacesDiff = diff(oldType.getInterfaces(), newType.getInterfaces());
|
||||
|
||||
for (var _i30 = 0, _interfacesDiff$added2 = interfacesDiff.added; _i30 < _interfacesDiff$added2.length; _i30++) {
|
||||
var newInterface = _interfacesDiff$added2[_i30];
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.INTERFACE_ADDED_TO_OBJECT,
|
||||
description: "".concat(newInterface.name, " added to interfaces implemented by ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i32 = 0, _interfacesDiff$remov2 = interfacesDiff.removed; _i32 < _interfacesDiff$remov2.length; _i32++) {
|
||||
var oldInterface = _interfacesDiff$remov2[_i32];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT,
|
||||
description: "".concat(oldType.name, " no longer implements interface ").concat(oldInterface.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findFieldChanges(oldType, newType) {
|
||||
var schemaChanges = [];
|
||||
var fieldsDiff = diff((0, _objectValues.default)(oldType.getFields()), (0, _objectValues.default)(newType.getFields()));
|
||||
|
||||
for (var _i34 = 0, _fieldsDiff$removed4 = fieldsDiff.removed; _i34 < _fieldsDiff$removed4.length; _i34++) {
|
||||
var oldField = _fieldsDiff$removed4[_i34];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_REMOVED,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i36 = 0, _fieldsDiff$persisted4 = fieldsDiff.persisted; _i36 < _fieldsDiff$persisted4.length; _i36++) {
|
||||
var _ref8 = _fieldsDiff$persisted4[_i36];
|
||||
var _oldField2 = _ref8[0];
|
||||
var newField = _ref8[1];
|
||||
schemaChanges.push.apply(schemaChanges, findArgChanges(oldType, _oldField2, newField));
|
||||
var isSafe = isChangeSafeForObjectOrInterfaceField(_oldField2.type, newField.type);
|
||||
|
||||
if (!isSafe) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_CHANGED_KIND,
|
||||
description: "".concat(oldType.name, ".").concat(_oldField2.name, " changed type from ") + "".concat(String(_oldField2.type), " to ").concat(String(newField.type), ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findArgChanges(oldType, oldField, newField) {
|
||||
var schemaChanges = [];
|
||||
var argsDiff = diff(oldField.args, newField.args);
|
||||
|
||||
for (var _i38 = 0, _argsDiff$removed4 = argsDiff.removed; _i38 < _argsDiff$removed4.length; _i38++) {
|
||||
var oldArg = _argsDiff$removed4[_i38];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.ARG_REMOVED,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(oldArg.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i40 = 0, _argsDiff$persisted2 = argsDiff.persisted; _i40 < _argsDiff$persisted2.length; _i40++) {
|
||||
var _ref10 = _argsDiff$persisted2[_i40];
|
||||
var _oldArg = _ref10[0];
|
||||
var newArg = _ref10[1];
|
||||
var isSafe = isChangeSafeForInputObjectFieldOrFieldArg(_oldArg.type, newArg.type);
|
||||
|
||||
if (!isSafe) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.ARG_CHANGED_KIND,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " has changed type from ") + "".concat(String(_oldArg.type), " to ").concat(String(newArg.type), ".")
|
||||
});
|
||||
} else if (_oldArg.defaultValue !== undefined) {
|
||||
if (newArg.defaultValue === undefined) {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " defaultValue was removed.")
|
||||
});
|
||||
} else {
|
||||
// Since we looking only for client's observable changes we should
|
||||
// compare default values in the same representation as they are
|
||||
// represented inside introspection.
|
||||
var oldValueStr = stringifyValue(_oldArg.defaultValue, _oldArg.type);
|
||||
var newValueStr = stringifyValue(newArg.defaultValue, newArg.type);
|
||||
|
||||
if (oldValueStr !== newValueStr) {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " has changed defaultValue from ").concat(oldValueStr, " to ").concat(newValueStr, ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var _i42 = 0, _argsDiff$added4 = argsDiff.added; _i42 < _argsDiff$added4.length; _i42++) {
|
||||
var _newArg = _argsDiff$added4[_i42];
|
||||
|
||||
if ((0, _definition.isRequiredArgument)(_newArg)) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.REQUIRED_ARG_ADDED,
|
||||
description: "A required arg ".concat(_newArg.name, " on ").concat(oldType.name, ".").concat(oldField.name, " was added.")
|
||||
});
|
||||
} else {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.OPTIONAL_ARG_ADDED,
|
||||
description: "An optional arg ".concat(_newArg.name, " on ").concat(oldType.name, ".").concat(oldField.name, " was added.")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function isChangeSafeForObjectOrInterfaceField(oldType, newType) {
|
||||
if ((0, _definition.isListType)(oldType)) {
|
||||
return (// if they're both lists, make sure the underlying types are compatible
|
||||
(0, _definition.isListType)(newType) && isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType) || // moving from nullable to non-null of the same underlying type is safe
|
||||
(0, _definition.isNonNullType)(newType) && isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)
|
||||
);
|
||||
}
|
||||
|
||||
if ((0, _definition.isNonNullType)(oldType)) {
|
||||
// if they're both non-null, make sure the underlying types are compatible
|
||||
return (0, _definition.isNonNullType)(newType) && isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType);
|
||||
}
|
||||
|
||||
return (// if they're both named types, see if their names are equivalent
|
||||
(0, _definition.isNamedType)(newType) && oldType.name === newType.name || // moving from nullable to non-null of the same underlying type is safe
|
||||
(0, _definition.isNonNullType)(newType) && isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)
|
||||
);
|
||||
}
|
||||
|
||||
function isChangeSafeForInputObjectFieldOrFieldArg(oldType, newType) {
|
||||
if ((0, _definition.isListType)(oldType)) {
|
||||
// if they're both lists, make sure the underlying types are compatible
|
||||
return (0, _definition.isListType)(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType);
|
||||
}
|
||||
|
||||
if ((0, _definition.isNonNullType)(oldType)) {
|
||||
return (// if they're both non-null, make sure the underlying types are
|
||||
// compatible
|
||||
(0, _definition.isNonNullType)(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType) || // moving from non-null to nullable of the same underlying type is safe
|
||||
!(0, _definition.isNonNullType)(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType)
|
||||
);
|
||||
} // if they're both named types, see if their names are equivalent
|
||||
|
||||
|
||||
return (0, _definition.isNamedType)(newType) && oldType.name === newType.name;
|
||||
}
|
||||
|
||||
function typeKindName(type) {
|
||||
if ((0, _definition.isScalarType)(type)) {
|
||||
return 'a Scalar type';
|
||||
}
|
||||
|
||||
if ((0, _definition.isObjectType)(type)) {
|
||||
return 'an Object type';
|
||||
}
|
||||
|
||||
if ((0, _definition.isInterfaceType)(type)) {
|
||||
return 'an Interface type';
|
||||
}
|
||||
|
||||
if ((0, _definition.isUnionType)(type)) {
|
||||
return 'a Union type';
|
||||
}
|
||||
|
||||
if ((0, _definition.isEnumType)(type)) {
|
||||
return 'an Enum type';
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if ((0, _definition.isInputObjectType)(type)) {
|
||||
return 'an Input type';
|
||||
} // Not reachable. All possible named types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
(0, _invariant.default)(false, 'Unexpected type: ' + (0, _inspect.default)(type));
|
||||
}
|
||||
|
||||
function stringifyValue(value, type) {
|
||||
var ast = (0, _astFromValue.astFromValue)(value, type);
|
||||
|
||||
/* istanbul ignore next */
|
||||
ast != null || (0, _invariant.default)(0);
|
||||
var sortedAST = (0, _visitor.visit)(ast, {
|
||||
ObjectValue: function ObjectValue(objectNode) {
|
||||
var fields = [].concat(objectNode.fields).sort(function (fieldA, fieldB) {
|
||||
return fieldA.name.value.localeCompare(fieldB.name.value);
|
||||
});
|
||||
return _objectSpread({}, objectNode, {
|
||||
fields: fields
|
||||
});
|
||||
}
|
||||
});
|
||||
return (0, _printer.print)(sortedAST);
|
||||
}
|
||||
|
||||
function diff(oldArray, newArray) {
|
||||
var added = [];
|
||||
var removed = [];
|
||||
var persisted = [];
|
||||
var oldMap = (0, _keyMap.default)(oldArray, function (_ref11) {
|
||||
var name = _ref11.name;
|
||||
return name;
|
||||
});
|
||||
var newMap = (0, _keyMap.default)(newArray, function (_ref12) {
|
||||
var name = _ref12.name;
|
||||
return name;
|
||||
});
|
||||
|
||||
for (var _i44 = 0; _i44 < oldArray.length; _i44++) {
|
||||
var oldItem = oldArray[_i44];
|
||||
var newItem = newMap[oldItem.name];
|
||||
|
||||
if (newItem === undefined) {
|
||||
removed.push(oldItem);
|
||||
} else {
|
||||
persisted.push([oldItem, newItem]);
|
||||
}
|
||||
}
|
||||
|
||||
for (var _i46 = 0; _i46 < newArray.length; _i46++) {
|
||||
var _newItem = newArray[_i46];
|
||||
|
||||
if (oldMap[_newItem.name] === undefined) {
|
||||
added.push(_newItem);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
added: added,
|
||||
persisted: persisted,
|
||||
removed: removed
|
||||
};
|
||||
}
|
||||
569
node_modules/graphql/utilities/findBreakingChanges.js.flow
generated
vendored
Normal file
569
node_modules/graphql/utilities/findBreakingChanges.js.flow
generated
vendored
Normal file
@@ -0,0 +1,569 @@
|
||||
// @flow strict
|
||||
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
|
||||
import keyMap from '../jsutils/keyMap';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
|
||||
import { print } from '../language/printer';
|
||||
import { visit } from '../language/visitor';
|
||||
|
||||
import { type GraphQLSchema } from '../type/schema';
|
||||
import {
|
||||
type GraphQLField,
|
||||
type GraphQLType,
|
||||
type GraphQLInputType,
|
||||
type GraphQLNamedType,
|
||||
type GraphQLEnumType,
|
||||
type GraphQLUnionType,
|
||||
type GraphQLObjectType,
|
||||
type GraphQLInterfaceType,
|
||||
type GraphQLInputObjectType,
|
||||
isScalarType,
|
||||
isObjectType,
|
||||
isInterfaceType,
|
||||
isUnionType,
|
||||
isEnumType,
|
||||
isInputObjectType,
|
||||
isNonNullType,
|
||||
isListType,
|
||||
isNamedType,
|
||||
isRequiredArgument,
|
||||
isRequiredInputField,
|
||||
} from '../type/definition';
|
||||
|
||||
import { astFromValue } from './astFromValue';
|
||||
|
||||
export const BreakingChangeType = Object.freeze({
|
||||
TYPE_REMOVED: 'TYPE_REMOVED',
|
||||
TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND',
|
||||
TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION',
|
||||
VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM',
|
||||
REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED',
|
||||
INTERFACE_REMOVED_FROM_OBJECT: 'INTERFACE_REMOVED_FROM_OBJECT',
|
||||
FIELD_REMOVED: 'FIELD_REMOVED',
|
||||
FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND',
|
||||
REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED',
|
||||
ARG_REMOVED: 'ARG_REMOVED',
|
||||
ARG_CHANGED_KIND: 'ARG_CHANGED_KIND',
|
||||
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED',
|
||||
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED',
|
||||
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED',
|
||||
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED',
|
||||
});
|
||||
|
||||
export const DangerousChangeType = Object.freeze({
|
||||
VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM',
|
||||
TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION',
|
||||
OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED',
|
||||
OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED',
|
||||
INTERFACE_ADDED_TO_OBJECT: 'INTERFACE_ADDED_TO_OBJECT',
|
||||
ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE',
|
||||
});
|
||||
|
||||
export type BreakingChange = {
|
||||
type: $Keys<typeof BreakingChangeType>,
|
||||
description: string,
|
||||
...
|
||||
};
|
||||
|
||||
export type DangerousChange = {
|
||||
type: $Keys<typeof DangerousChangeType>,
|
||||
description: string,
|
||||
...
|
||||
};
|
||||
|
||||
/**
|
||||
* Given two schemas, returns an Array containing descriptions of all the types
|
||||
* of breaking changes covered by the other functions down below.
|
||||
*/
|
||||
export function findBreakingChanges(
|
||||
oldSchema: GraphQLSchema,
|
||||
newSchema: GraphQLSchema,
|
||||
): Array<BreakingChange> {
|
||||
const breakingChanges = findSchemaChanges(oldSchema, newSchema).filter(
|
||||
change => change.type in BreakingChangeType,
|
||||
);
|
||||
return ((breakingChanges: any): Array<BreakingChange>);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two schemas, returns an Array containing descriptions of all the types
|
||||
* of potentially dangerous changes covered by the other functions down below.
|
||||
*/
|
||||
export function findDangerousChanges(
|
||||
oldSchema: GraphQLSchema,
|
||||
newSchema: GraphQLSchema,
|
||||
): Array<DangerousChange> {
|
||||
const dangerousChanges = findSchemaChanges(oldSchema, newSchema).filter(
|
||||
change => change.type in DangerousChangeType,
|
||||
);
|
||||
return ((dangerousChanges: any): Array<DangerousChange>);
|
||||
}
|
||||
|
||||
function findSchemaChanges(
|
||||
oldSchema: GraphQLSchema,
|
||||
newSchema: GraphQLSchema,
|
||||
): Array<BreakingChange | DangerousChange> {
|
||||
return [
|
||||
...findTypeChanges(oldSchema, newSchema),
|
||||
...findDirectiveChanges(oldSchema, newSchema),
|
||||
];
|
||||
}
|
||||
|
||||
function findDirectiveChanges(
|
||||
oldSchema: GraphQLSchema,
|
||||
newSchema: GraphQLSchema,
|
||||
): Array<BreakingChange | DangerousChange> {
|
||||
const schemaChanges = [];
|
||||
|
||||
const directivesDiff = diff(
|
||||
oldSchema.getDirectives(),
|
||||
newSchema.getDirectives(),
|
||||
);
|
||||
|
||||
for (const oldDirective of directivesDiff.removed) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.DIRECTIVE_REMOVED,
|
||||
description: `${oldDirective.name} was removed.`,
|
||||
});
|
||||
}
|
||||
|
||||
for (const [oldDirective, newDirective] of directivesDiff.persisted) {
|
||||
const argsDiff = diff(oldDirective.args, newDirective.args);
|
||||
|
||||
for (const newArg of argsDiff.added) {
|
||||
if (isRequiredArgument(newArg)) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.REQUIRED_DIRECTIVE_ARG_ADDED,
|
||||
description: `A required arg ${newArg.name} on directive ${oldDirective.name} was added.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const oldArg of argsDiff.removed) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.DIRECTIVE_ARG_REMOVED,
|
||||
description: `${oldArg.name} was removed from ${oldDirective.name}.`,
|
||||
});
|
||||
}
|
||||
|
||||
for (const location of oldDirective.locations) {
|
||||
if (newDirective.locations.indexOf(location) === -1) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
|
||||
description: `${location} was removed from ${oldDirective.name}.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findTypeChanges(
|
||||
oldSchema: GraphQLSchema,
|
||||
newSchema: GraphQLSchema,
|
||||
): Array<BreakingChange | DangerousChange> {
|
||||
const schemaChanges = [];
|
||||
|
||||
const typesDiff = diff(
|
||||
objectValues(oldSchema.getTypeMap()),
|
||||
objectValues(newSchema.getTypeMap()),
|
||||
);
|
||||
|
||||
for (const oldType of typesDiff.removed) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.TYPE_REMOVED,
|
||||
description: `${oldType.name} was removed.`,
|
||||
});
|
||||
}
|
||||
|
||||
for (const [oldType, newType] of typesDiff.persisted) {
|
||||
if (isEnumType(oldType) && isEnumType(newType)) {
|
||||
schemaChanges.push(...findEnumTypeChanges(oldType, newType));
|
||||
} else if (isUnionType(oldType) && isUnionType(newType)) {
|
||||
schemaChanges.push(...findUnionTypeChanges(oldType, newType));
|
||||
} else if (isInputObjectType(oldType) && isInputObjectType(newType)) {
|
||||
schemaChanges.push(...findInputObjectTypeChanges(oldType, newType));
|
||||
} else if (isObjectType(oldType) && isObjectType(newType)) {
|
||||
schemaChanges.push(...findObjectTypeChanges(oldType, newType));
|
||||
} else if (isInterfaceType(oldType) && isInterfaceType(newType)) {
|
||||
schemaChanges.push(...findFieldChanges(oldType, newType));
|
||||
} else if (oldType.constructor !== newType.constructor) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.TYPE_CHANGED_KIND,
|
||||
description:
|
||||
`${oldType.name} changed from ` +
|
||||
`${typeKindName(oldType)} to ${typeKindName(newType)}.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findInputObjectTypeChanges(
|
||||
oldType: GraphQLInputObjectType,
|
||||
newType: GraphQLInputObjectType,
|
||||
): Array<BreakingChange | DangerousChange> {
|
||||
const schemaChanges = [];
|
||||
const fieldsDiff = diff(
|
||||
objectValues(oldType.getFields()),
|
||||
objectValues(newType.getFields()),
|
||||
);
|
||||
|
||||
for (const newField of fieldsDiff.added) {
|
||||
if (isRequiredInputField(newField)) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
|
||||
description: `A required field ${newField.name} on input type ${oldType.name} was added.`,
|
||||
});
|
||||
} else {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
|
||||
description: `An optional field ${newField.name} on input type ${oldType.name} was added.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const oldField of fieldsDiff.removed) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_REMOVED,
|
||||
description: `${oldType.name}.${oldField.name} was removed.`,
|
||||
});
|
||||
}
|
||||
|
||||
for (const [oldField, newField] of fieldsDiff.persisted) {
|
||||
const isSafe = isChangeSafeForInputObjectFieldOrFieldArg(
|
||||
oldField.type,
|
||||
newField.type,
|
||||
);
|
||||
if (!isSafe) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_CHANGED_KIND,
|
||||
description:
|
||||
`${oldType.name}.${oldField.name} changed type from ` +
|
||||
`${String(oldField.type)} to ${String(newField.type)}.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findUnionTypeChanges(
|
||||
oldType: GraphQLUnionType,
|
||||
newType: GraphQLUnionType,
|
||||
): Array<BreakingChange | DangerousChange> {
|
||||
const schemaChanges = [];
|
||||
const possibleTypesDiff = diff(oldType.getTypes(), newType.getTypes());
|
||||
|
||||
for (const newPossibleType of possibleTypesDiff.added) {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.TYPE_ADDED_TO_UNION,
|
||||
description: `${newPossibleType.name} was added to union type ${oldType.name}.`,
|
||||
});
|
||||
}
|
||||
|
||||
for (const oldPossibleType of possibleTypesDiff.removed) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.TYPE_REMOVED_FROM_UNION,
|
||||
description: `${oldPossibleType.name} was removed from union type ${oldType.name}.`,
|
||||
});
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findEnumTypeChanges(
|
||||
oldType: GraphQLEnumType,
|
||||
newType: GraphQLEnumType,
|
||||
): Array<BreakingChange | DangerousChange> {
|
||||
const schemaChanges = [];
|
||||
const valuesDiff = diff(oldType.getValues(), newType.getValues());
|
||||
|
||||
for (const newValue of valuesDiff.added) {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.VALUE_ADDED_TO_ENUM,
|
||||
description: `${newValue.name} was added to enum type ${oldType.name}.`,
|
||||
});
|
||||
}
|
||||
|
||||
for (const oldValue of valuesDiff.removed) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM,
|
||||
description: `${oldValue.name} was removed from enum type ${oldType.name}.`,
|
||||
});
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findObjectTypeChanges(
|
||||
oldType: GraphQLObjectType,
|
||||
newType: GraphQLObjectType,
|
||||
): Array<BreakingChange | DangerousChange> {
|
||||
const schemaChanges = findFieldChanges(oldType, newType);
|
||||
const interfacesDiff = diff(oldType.getInterfaces(), newType.getInterfaces());
|
||||
|
||||
for (const newInterface of interfacesDiff.added) {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.INTERFACE_ADDED_TO_OBJECT,
|
||||
description: `${newInterface.name} added to interfaces implemented by ${oldType.name}.`,
|
||||
});
|
||||
}
|
||||
|
||||
for (const oldInterface of interfacesDiff.removed) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT,
|
||||
description: `${oldType.name} no longer implements interface ${oldInterface.name}.`,
|
||||
});
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findFieldChanges(
|
||||
oldType: GraphQLObjectType | GraphQLInterfaceType,
|
||||
newType: GraphQLObjectType | GraphQLInterfaceType,
|
||||
): Array<BreakingChange | DangerousChange> {
|
||||
const schemaChanges = [];
|
||||
const fieldsDiff = diff(
|
||||
objectValues(oldType.getFields()),
|
||||
objectValues(newType.getFields()),
|
||||
);
|
||||
|
||||
for (const oldField of fieldsDiff.removed) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_REMOVED,
|
||||
description: `${oldType.name}.${oldField.name} was removed.`,
|
||||
});
|
||||
}
|
||||
|
||||
for (const [oldField, newField] of fieldsDiff.persisted) {
|
||||
schemaChanges.push(...findArgChanges(oldType, oldField, newField));
|
||||
|
||||
const isSafe = isChangeSafeForObjectOrInterfaceField(
|
||||
oldField.type,
|
||||
newField.type,
|
||||
);
|
||||
if (!isSafe) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_CHANGED_KIND,
|
||||
description:
|
||||
`${oldType.name}.${oldField.name} changed type from ` +
|
||||
`${String(oldField.type)} to ${String(newField.type)}.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findArgChanges(
|
||||
oldType: GraphQLObjectType | GraphQLInterfaceType,
|
||||
oldField: GraphQLField<mixed, mixed>,
|
||||
newField: GraphQLField<mixed, mixed>,
|
||||
): Array<BreakingChange | DangerousChange> {
|
||||
const schemaChanges = [];
|
||||
const argsDiff = diff(oldField.args, newField.args);
|
||||
|
||||
for (const oldArg of argsDiff.removed) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.ARG_REMOVED,
|
||||
description: `${oldType.name}.${oldField.name} arg ${oldArg.name} was removed.`,
|
||||
});
|
||||
}
|
||||
|
||||
for (const [oldArg, newArg] of argsDiff.persisted) {
|
||||
const isSafe = isChangeSafeForInputObjectFieldOrFieldArg(
|
||||
oldArg.type,
|
||||
newArg.type,
|
||||
);
|
||||
if (!isSafe) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.ARG_CHANGED_KIND,
|
||||
description:
|
||||
`${oldType.name}.${oldField.name} arg ${oldArg.name} has changed type from ` +
|
||||
`${String(oldArg.type)} to ${String(newArg.type)}.`,
|
||||
});
|
||||
} else if (oldArg.defaultValue !== undefined) {
|
||||
if (newArg.defaultValue === undefined) {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
|
||||
description: `${oldType.name}.${oldField.name} arg ${oldArg.name} defaultValue was removed.`,
|
||||
});
|
||||
} else {
|
||||
// Since we looking only for client's observable changes we should
|
||||
// compare default values in the same representation as they are
|
||||
// represented inside introspection.
|
||||
const oldValueStr = stringifyValue(oldArg.defaultValue, oldArg.type);
|
||||
const newValueStr = stringifyValue(newArg.defaultValue, newArg.type);
|
||||
|
||||
if (oldValueStr !== newValueStr) {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
|
||||
description: `${oldType.name}.${oldField.name} arg ${oldArg.name} has changed defaultValue from ${oldValueStr} to ${newValueStr}.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const newArg of argsDiff.added) {
|
||||
if (isRequiredArgument(newArg)) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.REQUIRED_ARG_ADDED,
|
||||
description: `A required arg ${newArg.name} on ${oldType.name}.${oldField.name} was added.`,
|
||||
});
|
||||
} else {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.OPTIONAL_ARG_ADDED,
|
||||
description: `An optional arg ${newArg.name} on ${oldType.name}.${oldField.name} was added.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function isChangeSafeForObjectOrInterfaceField(
|
||||
oldType: GraphQLType,
|
||||
newType: GraphQLType,
|
||||
): boolean {
|
||||
if (isListType(oldType)) {
|
||||
return (
|
||||
// if they're both lists, make sure the underlying types are compatible
|
||||
(isListType(newType) &&
|
||||
isChangeSafeForObjectOrInterfaceField(
|
||||
oldType.ofType,
|
||||
newType.ofType,
|
||||
)) ||
|
||||
// moving from nullable to non-null of the same underlying type is safe
|
||||
(isNonNullType(newType) &&
|
||||
isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType))
|
||||
);
|
||||
}
|
||||
|
||||
if (isNonNullType(oldType)) {
|
||||
// if they're both non-null, make sure the underlying types are compatible
|
||||
return (
|
||||
isNonNullType(newType) &&
|
||||
isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
// if they're both named types, see if their names are equivalent
|
||||
(isNamedType(newType) && oldType.name === newType.name) ||
|
||||
// moving from nullable to non-null of the same underlying type is safe
|
||||
(isNonNullType(newType) &&
|
||||
isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType))
|
||||
);
|
||||
}
|
||||
|
||||
function isChangeSafeForInputObjectFieldOrFieldArg(
|
||||
oldType: GraphQLType,
|
||||
newType: GraphQLType,
|
||||
): boolean {
|
||||
if (isListType(oldType)) {
|
||||
// if they're both lists, make sure the underlying types are compatible
|
||||
return (
|
||||
isListType(newType) &&
|
||||
isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType)
|
||||
);
|
||||
}
|
||||
|
||||
if (isNonNullType(oldType)) {
|
||||
return (
|
||||
// if they're both non-null, make sure the underlying types are
|
||||
// compatible
|
||||
(isNonNullType(newType) &&
|
||||
isChangeSafeForInputObjectFieldOrFieldArg(
|
||||
oldType.ofType,
|
||||
newType.ofType,
|
||||
)) ||
|
||||
// moving from non-null to nullable of the same underlying type is safe
|
||||
(!isNonNullType(newType) &&
|
||||
isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType))
|
||||
);
|
||||
}
|
||||
|
||||
// if they're both named types, see if their names are equivalent
|
||||
return isNamedType(newType) && oldType.name === newType.name;
|
||||
}
|
||||
|
||||
function typeKindName(type: GraphQLNamedType): string {
|
||||
if (isScalarType(type)) {
|
||||
return 'a Scalar type';
|
||||
}
|
||||
if (isObjectType(type)) {
|
||||
return 'an Object type';
|
||||
}
|
||||
if (isInterfaceType(type)) {
|
||||
return 'an Interface type';
|
||||
}
|
||||
if (isUnionType(type)) {
|
||||
return 'a Union type';
|
||||
}
|
||||
if (isEnumType(type)) {
|
||||
return 'an Enum type';
|
||||
}
|
||||
if (isInputObjectType(type)) {
|
||||
return 'an Input type';
|
||||
}
|
||||
|
||||
// Not reachable. All possible named types have been considered.
|
||||
invariant(false, 'Unexpected type: ' + inspect((type: empty)));
|
||||
}
|
||||
|
||||
function stringifyValue(value: mixed, type: GraphQLInputType): string {
|
||||
const ast = astFromValue(value, type);
|
||||
invariant(ast != null);
|
||||
|
||||
const sortedAST = visit(ast, {
|
||||
ObjectValue(objectNode) {
|
||||
const fields = [...objectNode.fields].sort((fieldA, fieldB) =>
|
||||
fieldA.name.value.localeCompare(fieldB.name.value),
|
||||
);
|
||||
return { ...objectNode, fields };
|
||||
},
|
||||
});
|
||||
|
||||
return print(sortedAST);
|
||||
}
|
||||
|
||||
function diff<T: { name: string, ... }>(
|
||||
oldArray: $ReadOnlyArray<T>,
|
||||
newArray: $ReadOnlyArray<T>,
|
||||
): {|
|
||||
added: Array<T>,
|
||||
removed: Array<T>,
|
||||
persisted: Array<[T, T]>,
|
||||
|} {
|
||||
const added = [];
|
||||
const removed = [];
|
||||
const persisted = [];
|
||||
|
||||
const oldMap = keyMap(oldArray, ({ name }) => name);
|
||||
const newMap = keyMap(newArray, ({ name }) => name);
|
||||
|
||||
for (const oldItem of oldArray) {
|
||||
const newItem = newMap[oldItem.name];
|
||||
if (newItem === undefined) {
|
||||
removed.push(oldItem);
|
||||
} else {
|
||||
persisted.push([oldItem, newItem]);
|
||||
}
|
||||
}
|
||||
|
||||
for (const newItem of newArray) {
|
||||
if (oldMap[newItem.name] === undefined) {
|
||||
added.push(newItem);
|
||||
}
|
||||
}
|
||||
|
||||
return { added, persisted, removed };
|
||||
}
|
||||
489
node_modules/graphql/utilities/findBreakingChanges.mjs
generated
vendored
Normal file
489
node_modules/graphql/utilities/findBreakingChanges.mjs
generated
vendored
Normal file
@@ -0,0 +1,489 @@
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
import keyMap from '../jsutils/keyMap';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import { print } from '../language/printer';
|
||||
import { visit } from '../language/visitor';
|
||||
import { isScalarType, isObjectType, isInterfaceType, isUnionType, isEnumType, isInputObjectType, isNonNullType, isListType, isNamedType, isRequiredArgument, isRequiredInputField } from '../type/definition';
|
||||
import { astFromValue } from './astFromValue';
|
||||
export var BreakingChangeType = Object.freeze({
|
||||
TYPE_REMOVED: 'TYPE_REMOVED',
|
||||
TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND',
|
||||
TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION',
|
||||
VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM',
|
||||
REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED',
|
||||
INTERFACE_REMOVED_FROM_OBJECT: 'INTERFACE_REMOVED_FROM_OBJECT',
|
||||
FIELD_REMOVED: 'FIELD_REMOVED',
|
||||
FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND',
|
||||
REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED',
|
||||
ARG_REMOVED: 'ARG_REMOVED',
|
||||
ARG_CHANGED_KIND: 'ARG_CHANGED_KIND',
|
||||
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED',
|
||||
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED',
|
||||
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED',
|
||||
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED'
|
||||
});
|
||||
export var DangerousChangeType = Object.freeze({
|
||||
VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM',
|
||||
TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION',
|
||||
OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED',
|
||||
OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED',
|
||||
INTERFACE_ADDED_TO_OBJECT: 'INTERFACE_ADDED_TO_OBJECT',
|
||||
ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE'
|
||||
});
|
||||
|
||||
/**
|
||||
* Given two schemas, returns an Array containing descriptions of all the types
|
||||
* of breaking changes covered by the other functions down below.
|
||||
*/
|
||||
export function findBreakingChanges(oldSchema, newSchema) {
|
||||
var breakingChanges = findSchemaChanges(oldSchema, newSchema).filter(function (change) {
|
||||
return change.type in BreakingChangeType;
|
||||
});
|
||||
return breakingChanges;
|
||||
}
|
||||
/**
|
||||
* Given two schemas, returns an Array containing descriptions of all the types
|
||||
* of potentially dangerous changes covered by the other functions down below.
|
||||
*/
|
||||
|
||||
export function findDangerousChanges(oldSchema, newSchema) {
|
||||
var dangerousChanges = findSchemaChanges(oldSchema, newSchema).filter(function (change) {
|
||||
return change.type in DangerousChangeType;
|
||||
});
|
||||
return dangerousChanges;
|
||||
}
|
||||
|
||||
function findSchemaChanges(oldSchema, newSchema) {
|
||||
return [].concat(findTypeChanges(oldSchema, newSchema), findDirectiveChanges(oldSchema, newSchema));
|
||||
}
|
||||
|
||||
function findDirectiveChanges(oldSchema, newSchema) {
|
||||
var schemaChanges = [];
|
||||
var directivesDiff = diff(oldSchema.getDirectives(), newSchema.getDirectives());
|
||||
|
||||
for (var _i2 = 0, _directivesDiff$remov2 = directivesDiff.removed; _i2 < _directivesDiff$remov2.length; _i2++) {
|
||||
var oldDirective = _directivesDiff$remov2[_i2];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.DIRECTIVE_REMOVED,
|
||||
description: "".concat(oldDirective.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i4 = 0, _directivesDiff$persi2 = directivesDiff.persisted; _i4 < _directivesDiff$persi2.length; _i4++) {
|
||||
var _ref2 = _directivesDiff$persi2[_i4];
|
||||
var _oldDirective = _ref2[0];
|
||||
var newDirective = _ref2[1];
|
||||
var argsDiff = diff(_oldDirective.args, newDirective.args);
|
||||
|
||||
for (var _i6 = 0, _argsDiff$added2 = argsDiff.added; _i6 < _argsDiff$added2.length; _i6++) {
|
||||
var newArg = _argsDiff$added2[_i6];
|
||||
|
||||
if (isRequiredArgument(newArg)) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.REQUIRED_DIRECTIVE_ARG_ADDED,
|
||||
description: "A required arg ".concat(newArg.name, " on directive ").concat(_oldDirective.name, " was added.")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (var _i8 = 0, _argsDiff$removed2 = argsDiff.removed; _i8 < _argsDiff$removed2.length; _i8++) {
|
||||
var oldArg = _argsDiff$removed2[_i8];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.DIRECTIVE_ARG_REMOVED,
|
||||
description: "".concat(oldArg.name, " was removed from ").concat(_oldDirective.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i10 = 0, _oldDirective$locatio2 = _oldDirective.locations; _i10 < _oldDirective$locatio2.length; _i10++) {
|
||||
var location = _oldDirective$locatio2[_i10];
|
||||
|
||||
if (newDirective.locations.indexOf(location) === -1) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
|
||||
description: "".concat(location, " was removed from ").concat(_oldDirective.name, ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findTypeChanges(oldSchema, newSchema) {
|
||||
var schemaChanges = [];
|
||||
var typesDiff = diff(objectValues(oldSchema.getTypeMap()), objectValues(newSchema.getTypeMap()));
|
||||
|
||||
for (var _i12 = 0, _typesDiff$removed2 = typesDiff.removed; _i12 < _typesDiff$removed2.length; _i12++) {
|
||||
var oldType = _typesDiff$removed2[_i12];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.TYPE_REMOVED,
|
||||
description: "".concat(oldType.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i14 = 0, _typesDiff$persisted2 = typesDiff.persisted; _i14 < _typesDiff$persisted2.length; _i14++) {
|
||||
var _ref4 = _typesDiff$persisted2[_i14];
|
||||
var _oldType = _ref4[0];
|
||||
var newType = _ref4[1];
|
||||
|
||||
if (isEnumType(_oldType) && isEnumType(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findEnumTypeChanges(_oldType, newType));
|
||||
} else if (isUnionType(_oldType) && isUnionType(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findUnionTypeChanges(_oldType, newType));
|
||||
} else if (isInputObjectType(_oldType) && isInputObjectType(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findInputObjectTypeChanges(_oldType, newType));
|
||||
} else if (isObjectType(_oldType) && isObjectType(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findObjectTypeChanges(_oldType, newType));
|
||||
} else if (isInterfaceType(_oldType) && isInterfaceType(newType)) {
|
||||
schemaChanges.push.apply(schemaChanges, findFieldChanges(_oldType, newType));
|
||||
} else if (_oldType.constructor !== newType.constructor) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.TYPE_CHANGED_KIND,
|
||||
description: "".concat(_oldType.name, " changed from ") + "".concat(typeKindName(_oldType), " to ").concat(typeKindName(newType), ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findInputObjectTypeChanges(oldType, newType) {
|
||||
var schemaChanges = [];
|
||||
var fieldsDiff = diff(objectValues(oldType.getFields()), objectValues(newType.getFields()));
|
||||
|
||||
for (var _i16 = 0, _fieldsDiff$added2 = fieldsDiff.added; _i16 < _fieldsDiff$added2.length; _i16++) {
|
||||
var newField = _fieldsDiff$added2[_i16];
|
||||
|
||||
if (isRequiredInputField(newField)) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
|
||||
description: "A required field ".concat(newField.name, " on input type ").concat(oldType.name, " was added.")
|
||||
});
|
||||
} else {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
|
||||
description: "An optional field ".concat(newField.name, " on input type ").concat(oldType.name, " was added.")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (var _i18 = 0, _fieldsDiff$removed2 = fieldsDiff.removed; _i18 < _fieldsDiff$removed2.length; _i18++) {
|
||||
var oldField = _fieldsDiff$removed2[_i18];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_REMOVED,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i20 = 0, _fieldsDiff$persisted2 = fieldsDiff.persisted; _i20 < _fieldsDiff$persisted2.length; _i20++) {
|
||||
var _ref6 = _fieldsDiff$persisted2[_i20];
|
||||
var _oldField = _ref6[0];
|
||||
var _newField = _ref6[1];
|
||||
var isSafe = isChangeSafeForInputObjectFieldOrFieldArg(_oldField.type, _newField.type);
|
||||
|
||||
if (!isSafe) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_CHANGED_KIND,
|
||||
description: "".concat(oldType.name, ".").concat(_oldField.name, " changed type from ") + "".concat(String(_oldField.type), " to ").concat(String(_newField.type), ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findUnionTypeChanges(oldType, newType) {
|
||||
var schemaChanges = [];
|
||||
var possibleTypesDiff = diff(oldType.getTypes(), newType.getTypes());
|
||||
|
||||
for (var _i22 = 0, _possibleTypesDiff$ad2 = possibleTypesDiff.added; _i22 < _possibleTypesDiff$ad2.length; _i22++) {
|
||||
var newPossibleType = _possibleTypesDiff$ad2[_i22];
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.TYPE_ADDED_TO_UNION,
|
||||
description: "".concat(newPossibleType.name, " was added to union type ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i24 = 0, _possibleTypesDiff$re2 = possibleTypesDiff.removed; _i24 < _possibleTypesDiff$re2.length; _i24++) {
|
||||
var oldPossibleType = _possibleTypesDiff$re2[_i24];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.TYPE_REMOVED_FROM_UNION,
|
||||
description: "".concat(oldPossibleType.name, " was removed from union type ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findEnumTypeChanges(oldType, newType) {
|
||||
var schemaChanges = [];
|
||||
var valuesDiff = diff(oldType.getValues(), newType.getValues());
|
||||
|
||||
for (var _i26 = 0, _valuesDiff$added2 = valuesDiff.added; _i26 < _valuesDiff$added2.length; _i26++) {
|
||||
var newValue = _valuesDiff$added2[_i26];
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.VALUE_ADDED_TO_ENUM,
|
||||
description: "".concat(newValue.name, " was added to enum type ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i28 = 0, _valuesDiff$removed2 = valuesDiff.removed; _i28 < _valuesDiff$removed2.length; _i28++) {
|
||||
var oldValue = _valuesDiff$removed2[_i28];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM,
|
||||
description: "".concat(oldValue.name, " was removed from enum type ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findObjectTypeChanges(oldType, newType) {
|
||||
var schemaChanges = findFieldChanges(oldType, newType);
|
||||
var interfacesDiff = diff(oldType.getInterfaces(), newType.getInterfaces());
|
||||
|
||||
for (var _i30 = 0, _interfacesDiff$added2 = interfacesDiff.added; _i30 < _interfacesDiff$added2.length; _i30++) {
|
||||
var newInterface = _interfacesDiff$added2[_i30];
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.INTERFACE_ADDED_TO_OBJECT,
|
||||
description: "".concat(newInterface.name, " added to interfaces implemented by ").concat(oldType.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i32 = 0, _interfacesDiff$remov2 = interfacesDiff.removed; _i32 < _interfacesDiff$remov2.length; _i32++) {
|
||||
var oldInterface = _interfacesDiff$remov2[_i32];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT,
|
||||
description: "".concat(oldType.name, " no longer implements interface ").concat(oldInterface.name, ".")
|
||||
});
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findFieldChanges(oldType, newType) {
|
||||
var schemaChanges = [];
|
||||
var fieldsDiff = diff(objectValues(oldType.getFields()), objectValues(newType.getFields()));
|
||||
|
||||
for (var _i34 = 0, _fieldsDiff$removed4 = fieldsDiff.removed; _i34 < _fieldsDiff$removed4.length; _i34++) {
|
||||
var oldField = _fieldsDiff$removed4[_i34];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_REMOVED,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i36 = 0, _fieldsDiff$persisted4 = fieldsDiff.persisted; _i36 < _fieldsDiff$persisted4.length; _i36++) {
|
||||
var _ref8 = _fieldsDiff$persisted4[_i36];
|
||||
var _oldField2 = _ref8[0];
|
||||
var newField = _ref8[1];
|
||||
schemaChanges.push.apply(schemaChanges, findArgChanges(oldType, _oldField2, newField));
|
||||
var isSafe = isChangeSafeForObjectOrInterfaceField(_oldField2.type, newField.type);
|
||||
|
||||
if (!isSafe) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.FIELD_CHANGED_KIND,
|
||||
description: "".concat(oldType.name, ".").concat(_oldField2.name, " changed type from ") + "".concat(String(_oldField2.type), " to ").concat(String(newField.type), ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function findArgChanges(oldType, oldField, newField) {
|
||||
var schemaChanges = [];
|
||||
var argsDiff = diff(oldField.args, newField.args);
|
||||
|
||||
for (var _i38 = 0, _argsDiff$removed4 = argsDiff.removed; _i38 < _argsDiff$removed4.length; _i38++) {
|
||||
var oldArg = _argsDiff$removed4[_i38];
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.ARG_REMOVED,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(oldArg.name, " was removed.")
|
||||
});
|
||||
}
|
||||
|
||||
for (var _i40 = 0, _argsDiff$persisted2 = argsDiff.persisted; _i40 < _argsDiff$persisted2.length; _i40++) {
|
||||
var _ref10 = _argsDiff$persisted2[_i40];
|
||||
var _oldArg = _ref10[0];
|
||||
var newArg = _ref10[1];
|
||||
var isSafe = isChangeSafeForInputObjectFieldOrFieldArg(_oldArg.type, newArg.type);
|
||||
|
||||
if (!isSafe) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.ARG_CHANGED_KIND,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " has changed type from ") + "".concat(String(_oldArg.type), " to ").concat(String(newArg.type), ".")
|
||||
});
|
||||
} else if (_oldArg.defaultValue !== undefined) {
|
||||
if (newArg.defaultValue === undefined) {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " defaultValue was removed.")
|
||||
});
|
||||
} else {
|
||||
// Since we looking only for client's observable changes we should
|
||||
// compare default values in the same representation as they are
|
||||
// represented inside introspection.
|
||||
var oldValueStr = stringifyValue(_oldArg.defaultValue, _oldArg.type);
|
||||
var newValueStr = stringifyValue(newArg.defaultValue, newArg.type);
|
||||
|
||||
if (oldValueStr !== newValueStr) {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
|
||||
description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " has changed defaultValue from ").concat(oldValueStr, " to ").concat(newValueStr, ".")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var _i42 = 0, _argsDiff$added4 = argsDiff.added; _i42 < _argsDiff$added4.length; _i42++) {
|
||||
var _newArg = _argsDiff$added4[_i42];
|
||||
|
||||
if (isRequiredArgument(_newArg)) {
|
||||
schemaChanges.push({
|
||||
type: BreakingChangeType.REQUIRED_ARG_ADDED,
|
||||
description: "A required arg ".concat(_newArg.name, " on ").concat(oldType.name, ".").concat(oldField.name, " was added.")
|
||||
});
|
||||
} else {
|
||||
schemaChanges.push({
|
||||
type: DangerousChangeType.OPTIONAL_ARG_ADDED,
|
||||
description: "An optional arg ".concat(_newArg.name, " on ").concat(oldType.name, ".").concat(oldField.name, " was added.")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return schemaChanges;
|
||||
}
|
||||
|
||||
function isChangeSafeForObjectOrInterfaceField(oldType, newType) {
|
||||
if (isListType(oldType)) {
|
||||
return (// if they're both lists, make sure the underlying types are compatible
|
||||
isListType(newType) && isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType) || // moving from nullable to non-null of the same underlying type is safe
|
||||
isNonNullType(newType) && isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)
|
||||
);
|
||||
}
|
||||
|
||||
if (isNonNullType(oldType)) {
|
||||
// if they're both non-null, make sure the underlying types are compatible
|
||||
return isNonNullType(newType) && isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType);
|
||||
}
|
||||
|
||||
return (// if they're both named types, see if their names are equivalent
|
||||
isNamedType(newType) && oldType.name === newType.name || // moving from nullable to non-null of the same underlying type is safe
|
||||
isNonNullType(newType) && isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)
|
||||
);
|
||||
}
|
||||
|
||||
function isChangeSafeForInputObjectFieldOrFieldArg(oldType, newType) {
|
||||
if (isListType(oldType)) {
|
||||
// if they're both lists, make sure the underlying types are compatible
|
||||
return isListType(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType);
|
||||
}
|
||||
|
||||
if (isNonNullType(oldType)) {
|
||||
return (// if they're both non-null, make sure the underlying types are
|
||||
// compatible
|
||||
isNonNullType(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType) || // moving from non-null to nullable of the same underlying type is safe
|
||||
!isNonNullType(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType)
|
||||
);
|
||||
} // if they're both named types, see if their names are equivalent
|
||||
|
||||
|
||||
return isNamedType(newType) && oldType.name === newType.name;
|
||||
}
|
||||
|
||||
function typeKindName(type) {
|
||||
if (isScalarType(type)) {
|
||||
return 'a Scalar type';
|
||||
}
|
||||
|
||||
if (isObjectType(type)) {
|
||||
return 'an Object type';
|
||||
}
|
||||
|
||||
if (isInterfaceType(type)) {
|
||||
return 'an Interface type';
|
||||
}
|
||||
|
||||
if (isUnionType(type)) {
|
||||
return 'a Union type';
|
||||
}
|
||||
|
||||
if (isEnumType(type)) {
|
||||
return 'an Enum type';
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (isInputObjectType(type)) {
|
||||
return 'an Input type';
|
||||
} // Not reachable. All possible named types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
invariant(false, 'Unexpected type: ' + inspect(type));
|
||||
}
|
||||
|
||||
function stringifyValue(value, type) {
|
||||
var ast = astFromValue(value, type);
|
||||
|
||||
/* istanbul ignore next */
|
||||
ast != null || invariant(0);
|
||||
var sortedAST = visit(ast, {
|
||||
ObjectValue: function ObjectValue(objectNode) {
|
||||
var fields = [].concat(objectNode.fields).sort(function (fieldA, fieldB) {
|
||||
return fieldA.name.value.localeCompare(fieldB.name.value);
|
||||
});
|
||||
return _objectSpread({}, objectNode, {
|
||||
fields: fields
|
||||
});
|
||||
}
|
||||
});
|
||||
return print(sortedAST);
|
||||
}
|
||||
|
||||
function diff(oldArray, newArray) {
|
||||
var added = [];
|
||||
var removed = [];
|
||||
var persisted = [];
|
||||
var oldMap = keyMap(oldArray, function (_ref11) {
|
||||
var name = _ref11.name;
|
||||
return name;
|
||||
});
|
||||
var newMap = keyMap(newArray, function (_ref12) {
|
||||
var name = _ref12.name;
|
||||
return name;
|
||||
});
|
||||
|
||||
for (var _i44 = 0; _i44 < oldArray.length; _i44++) {
|
||||
var oldItem = oldArray[_i44];
|
||||
var newItem = newMap[oldItem.name];
|
||||
|
||||
if (newItem === undefined) {
|
||||
removed.push(oldItem);
|
||||
} else {
|
||||
persisted.push([oldItem, newItem]);
|
||||
}
|
||||
}
|
||||
|
||||
for (var _i46 = 0; _i46 < newArray.length; _i46++) {
|
||||
var _newItem = newArray[_i46];
|
||||
|
||||
if (oldMap[_newItem.name] === undefined) {
|
||||
added.push(_newItem);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
added: added,
|
||||
persisted: persisted,
|
||||
removed: removed
|
||||
};
|
||||
}
|
||||
13
node_modules/graphql/utilities/findDeprecatedUsages.d.ts
generated
vendored
Normal file
13
node_modules/graphql/utilities/findDeprecatedUsages.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { DocumentNode } from '../language/ast';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
|
||||
/**
|
||||
* A validation rule which reports deprecated usages.
|
||||
*
|
||||
* Returns a list of GraphQLError instances describing each deprecated use.
|
||||
*/
|
||||
export function findDeprecatedUsages(
|
||||
schema: GraphQLSchema,
|
||||
ast: DocumentNode,
|
||||
): GraphQLError[];
|
||||
51
node_modules/graphql/utilities/findDeprecatedUsages.js
generated
vendored
Normal file
51
node_modules/graphql/utilities/findDeprecatedUsages.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.findDeprecatedUsages = findDeprecatedUsages;
|
||||
|
||||
var _GraphQLError = require("../error/GraphQLError");
|
||||
|
||||
var _visitor = require("../language/visitor");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
var _TypeInfo = require("./TypeInfo");
|
||||
|
||||
/**
|
||||
* A validation rule which reports deprecated usages.
|
||||
*
|
||||
* Returns a list of GraphQLError instances describing each deprecated use.
|
||||
*/
|
||||
function findDeprecatedUsages(schema, ast) {
|
||||
var errors = [];
|
||||
var typeInfo = new _TypeInfo.TypeInfo(schema);
|
||||
(0, _visitor.visit)(ast, (0, _visitor.visitWithTypeInfo)(typeInfo, {
|
||||
Field: function Field(node) {
|
||||
var fieldDef = typeInfo.getFieldDef();
|
||||
|
||||
if (fieldDef && fieldDef.isDeprecated) {
|
||||
var parentType = typeInfo.getParentType();
|
||||
|
||||
if (parentType) {
|
||||
var reason = fieldDef.deprecationReason;
|
||||
errors.push(new _GraphQLError.GraphQLError("The field ".concat(parentType.name, ".").concat(fieldDef.name, " is deprecated.") + (reason ? ' ' + reason : ''), node));
|
||||
}
|
||||
}
|
||||
},
|
||||
EnumValue: function EnumValue(node) {
|
||||
var enumVal = typeInfo.getEnumValue();
|
||||
|
||||
if (enumVal && enumVal.isDeprecated) {
|
||||
var type = (0, _definition.getNamedType)(typeInfo.getInputType());
|
||||
|
||||
if (type) {
|
||||
var reason = enumVal.deprecationReason;
|
||||
errors.push(new _GraphQLError.GraphQLError("The enum value ".concat(type.name, ".").concat(enumVal.name, " is deprecated.") + (reason ? ' ' + reason : ''), node));
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
return errors;
|
||||
}
|
||||
64
node_modules/graphql/utilities/findDeprecatedUsages.js.flow
generated
vendored
Normal file
64
node_modules/graphql/utilities/findDeprecatedUsages.js.flow
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// @flow strict
|
||||
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
|
||||
import { type DocumentNode } from '../language/ast';
|
||||
import { visit, visitWithTypeInfo } from '../language/visitor';
|
||||
|
||||
import { getNamedType } from '../type/definition';
|
||||
import { type GraphQLSchema } from '../type/schema';
|
||||
|
||||
import { TypeInfo } from './TypeInfo';
|
||||
|
||||
/**
|
||||
* A validation rule which reports deprecated usages.
|
||||
*
|
||||
* Returns a list of GraphQLError instances describing each deprecated use.
|
||||
*/
|
||||
export function findDeprecatedUsages(
|
||||
schema: GraphQLSchema,
|
||||
ast: DocumentNode,
|
||||
): Array<GraphQLError> {
|
||||
const errors = [];
|
||||
const typeInfo = new TypeInfo(schema);
|
||||
|
||||
visit(
|
||||
ast,
|
||||
visitWithTypeInfo(typeInfo, {
|
||||
Field(node) {
|
||||
const fieldDef = typeInfo.getFieldDef();
|
||||
if (fieldDef && fieldDef.isDeprecated) {
|
||||
const parentType = typeInfo.getParentType();
|
||||
if (parentType) {
|
||||
const reason = fieldDef.deprecationReason;
|
||||
errors.push(
|
||||
new GraphQLError(
|
||||
`The field ${parentType.name}.${fieldDef.name} is deprecated.` +
|
||||
(reason ? ' ' + reason : ''),
|
||||
node,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
EnumValue(node) {
|
||||
const enumVal = typeInfo.getEnumValue();
|
||||
if (enumVal && enumVal.isDeprecated) {
|
||||
const type = getNamedType(typeInfo.getInputType());
|
||||
if (type) {
|
||||
const reason = enumVal.deprecationReason;
|
||||
errors.push(
|
||||
new GraphQLError(
|
||||
`The enum value ${type.name}.${enumVal.name} is deprecated.` +
|
||||
(reason ? ' ' + reason : ''),
|
||||
node,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
return errors;
|
||||
}
|
||||
41
node_modules/graphql/utilities/findDeprecatedUsages.mjs
generated
vendored
Normal file
41
node_modules/graphql/utilities/findDeprecatedUsages.mjs
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { visit, visitWithTypeInfo } from '../language/visitor';
|
||||
import { getNamedType } from '../type/definition';
|
||||
import { TypeInfo } from './TypeInfo';
|
||||
/**
|
||||
* A validation rule which reports deprecated usages.
|
||||
*
|
||||
* Returns a list of GraphQLError instances describing each deprecated use.
|
||||
*/
|
||||
|
||||
export function findDeprecatedUsages(schema, ast) {
|
||||
var errors = [];
|
||||
var typeInfo = new TypeInfo(schema);
|
||||
visit(ast, visitWithTypeInfo(typeInfo, {
|
||||
Field: function Field(node) {
|
||||
var fieldDef = typeInfo.getFieldDef();
|
||||
|
||||
if (fieldDef && fieldDef.isDeprecated) {
|
||||
var parentType = typeInfo.getParentType();
|
||||
|
||||
if (parentType) {
|
||||
var reason = fieldDef.deprecationReason;
|
||||
errors.push(new GraphQLError("The field ".concat(parentType.name, ".").concat(fieldDef.name, " is deprecated.") + (reason ? ' ' + reason : ''), node));
|
||||
}
|
||||
}
|
||||
},
|
||||
EnumValue: function EnumValue(node) {
|
||||
var enumVal = typeInfo.getEnumValue();
|
||||
|
||||
if (enumVal && enumVal.isDeprecated) {
|
||||
var type = getNamedType(typeInfo.getInputType());
|
||||
|
||||
if (type) {
|
||||
var reason = enumVal.deprecationReason;
|
||||
errors.push(new GraphQLError("The enum value ".concat(type.name, ".").concat(enumVal.name, " is deprecated.") + (reason ? ' ' + reason : ''), node));
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
return errors;
|
||||
}
|
||||
12
node_modules/graphql/utilities/getOperationAST.d.ts
generated
vendored
Normal file
12
node_modules/graphql/utilities/getOperationAST.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import Maybe from '../tsutils/Maybe';
|
||||
import { DocumentNode, OperationDefinitionNode } from '../language/ast';
|
||||
|
||||
/**
|
||||
* Returns an operation AST given a document AST and optionally an operation
|
||||
* name. If a name is not provided, an operation is only returned if only one is
|
||||
* provided in the document.
|
||||
*/
|
||||
export function getOperationAST(
|
||||
documentAST: DocumentNode,
|
||||
operationName: Maybe<string>,
|
||||
): Maybe<OperationDefinitionNode>;
|
||||
38
node_modules/graphql/utilities/getOperationAST.js
generated
vendored
Normal file
38
node_modules/graphql/utilities/getOperationAST.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getOperationAST = getOperationAST;
|
||||
|
||||
var _kinds = require("../language/kinds");
|
||||
|
||||
/**
|
||||
* Returns an operation AST given a document AST and optionally an operation
|
||||
* name. If a name is not provided, an operation is only returned if only one is
|
||||
* provided in the document.
|
||||
*/
|
||||
function getOperationAST(documentAST, operationName) {
|
||||
var operation = null;
|
||||
|
||||
for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
|
||||
var definition = _documentAST$definiti2[_i2];
|
||||
|
||||
if (definition.kind === _kinds.Kind.OPERATION_DEFINITION) {
|
||||
if (!operationName) {
|
||||
// If no operation name was provided, only return an Operation if there
|
||||
// is one defined in the document. Upon encountering the second, return
|
||||
// null.
|
||||
if (operation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
operation = definition;
|
||||
} else if (definition.name && definition.name.value === operationName) {
|
||||
return definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return operation;
|
||||
}
|
||||
35
node_modules/graphql/utilities/getOperationAST.js.flow
generated
vendored
Normal file
35
node_modules/graphql/utilities/getOperationAST.js.flow
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// @flow strict
|
||||
|
||||
import { Kind } from '../language/kinds';
|
||||
import {
|
||||
type DocumentNode,
|
||||
type OperationDefinitionNode,
|
||||
} from '../language/ast';
|
||||
|
||||
/**
|
||||
* Returns an operation AST given a document AST and optionally an operation
|
||||
* name. If a name is not provided, an operation is only returned if only one is
|
||||
* provided in the document.
|
||||
*/
|
||||
export function getOperationAST(
|
||||
documentAST: DocumentNode,
|
||||
operationName: ?string,
|
||||
): ?OperationDefinitionNode {
|
||||
let operation = null;
|
||||
for (const definition of documentAST.definitions) {
|
||||
if (definition.kind === Kind.OPERATION_DEFINITION) {
|
||||
if (!operationName) {
|
||||
// If no operation name was provided, only return an Operation if there
|
||||
// is one defined in the document. Upon encountering the second, return
|
||||
// null.
|
||||
if (operation) {
|
||||
return null;
|
||||
}
|
||||
operation = definition;
|
||||
} else if (definition.name && definition.name.value === operationName) {
|
||||
return definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
31
node_modules/graphql/utilities/getOperationAST.mjs
generated
vendored
Normal file
31
node_modules/graphql/utilities/getOperationAST.mjs
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Kind } from '../language/kinds';
|
||||
|
||||
/**
|
||||
* Returns an operation AST given a document AST and optionally an operation
|
||||
* name. If a name is not provided, an operation is only returned if only one is
|
||||
* provided in the document.
|
||||
*/
|
||||
export function getOperationAST(documentAST, operationName) {
|
||||
var operation = null;
|
||||
|
||||
for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
|
||||
var definition = _documentAST$definiti2[_i2];
|
||||
|
||||
if (definition.kind === Kind.OPERATION_DEFINITION) {
|
||||
if (!operationName) {
|
||||
// If no operation name was provided, only return an Operation if there
|
||||
// is one defined in the document. Upon encountering the second, return
|
||||
// null.
|
||||
if (operation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
operation = definition;
|
||||
} else if (definition.name && definition.name.value === operationName) {
|
||||
return definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return operation;
|
||||
}
|
||||
14
node_modules/graphql/utilities/getOperationRootType.d.ts
generated
vendored
Normal file
14
node_modules/graphql/utilities/getOperationRootType.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
OperationDefinitionNode,
|
||||
OperationTypeDefinitionNode,
|
||||
} from '../language/ast';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { GraphQLObjectType } from '../type/definition';
|
||||
|
||||
/**
|
||||
* Extracts the root type of the operation from the schema.
|
||||
*/
|
||||
export function getOperationRootType(
|
||||
schema: GraphQLSchema,
|
||||
operation: OperationDefinitionNode | OperationTypeDefinitionNode,
|
||||
): GraphQLObjectType;
|
||||
45
node_modules/graphql/utilities/getOperationRootType.js
generated
vendored
Normal file
45
node_modules/graphql/utilities/getOperationRootType.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getOperationRootType = getOperationRootType;
|
||||
|
||||
var _GraphQLError = require("../error/GraphQLError");
|
||||
|
||||
/**
|
||||
* Extracts the root type of the operation from the schema.
|
||||
*/
|
||||
function getOperationRootType(schema, operation) {
|
||||
if (operation.operation === 'query') {
|
||||
var queryType = schema.getQueryType();
|
||||
|
||||
if (!queryType) {
|
||||
throw new _GraphQLError.GraphQLError('Schema does not define the required query root type.', operation);
|
||||
}
|
||||
|
||||
return queryType;
|
||||
}
|
||||
|
||||
if (operation.operation === 'mutation') {
|
||||
var mutationType = schema.getMutationType();
|
||||
|
||||
if (!mutationType) {
|
||||
throw new _GraphQLError.GraphQLError('Schema is not configured for mutations.', operation);
|
||||
}
|
||||
|
||||
return mutationType;
|
||||
}
|
||||
|
||||
if (operation.operation === 'subscription') {
|
||||
var subscriptionType = schema.getSubscriptionType();
|
||||
|
||||
if (!subscriptionType) {
|
||||
throw new _GraphQLError.GraphQLError('Schema is not configured for subscriptions.', operation);
|
||||
}
|
||||
|
||||
return subscriptionType;
|
||||
}
|
||||
|
||||
throw new _GraphQLError.GraphQLError('Can only have query, mutation and subscription operations.', operation);
|
||||
}
|
||||
57
node_modules/graphql/utilities/getOperationRootType.js.flow
generated
vendored
Normal file
57
node_modules/graphql/utilities/getOperationRootType.js.flow
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
// @flow strict
|
||||
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
|
||||
import {
|
||||
type OperationDefinitionNode,
|
||||
type OperationTypeDefinitionNode,
|
||||
} from '../language/ast';
|
||||
|
||||
import { type GraphQLSchema } from '../type/schema';
|
||||
import { type GraphQLObjectType } from '../type/definition';
|
||||
|
||||
/**
|
||||
* Extracts the root type of the operation from the schema.
|
||||
*/
|
||||
export function getOperationRootType(
|
||||
schema: GraphQLSchema,
|
||||
operation: OperationDefinitionNode | OperationTypeDefinitionNode,
|
||||
): GraphQLObjectType {
|
||||
if (operation.operation === 'query') {
|
||||
const queryType = schema.getQueryType();
|
||||
if (!queryType) {
|
||||
throw new GraphQLError(
|
||||
'Schema does not define the required query root type.',
|
||||
operation,
|
||||
);
|
||||
}
|
||||
return queryType;
|
||||
}
|
||||
|
||||
if (operation.operation === 'mutation') {
|
||||
const mutationType = schema.getMutationType();
|
||||
if (!mutationType) {
|
||||
throw new GraphQLError(
|
||||
'Schema is not configured for mutations.',
|
||||
operation,
|
||||
);
|
||||
}
|
||||
return mutationType;
|
||||
}
|
||||
|
||||
if (operation.operation === 'subscription') {
|
||||
const subscriptionType = schema.getSubscriptionType();
|
||||
if (!subscriptionType) {
|
||||
throw new GraphQLError(
|
||||
'Schema is not configured for subscriptions.',
|
||||
operation,
|
||||
);
|
||||
}
|
||||
return subscriptionType;
|
||||
}
|
||||
|
||||
throw new GraphQLError(
|
||||
'Can only have query, mutation and subscription operations.',
|
||||
operation,
|
||||
);
|
||||
}
|
||||
38
node_modules/graphql/utilities/getOperationRootType.mjs
generated
vendored
Normal file
38
node_modules/graphql/utilities/getOperationRootType.mjs
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
|
||||
/**
|
||||
* Extracts the root type of the operation from the schema.
|
||||
*/
|
||||
export function getOperationRootType(schema, operation) {
|
||||
if (operation.operation === 'query') {
|
||||
var queryType = schema.getQueryType();
|
||||
|
||||
if (!queryType) {
|
||||
throw new GraphQLError('Schema does not define the required query root type.', operation);
|
||||
}
|
||||
|
||||
return queryType;
|
||||
}
|
||||
|
||||
if (operation.operation === 'mutation') {
|
||||
var mutationType = schema.getMutationType();
|
||||
|
||||
if (!mutationType) {
|
||||
throw new GraphQLError('Schema is not configured for mutations.', operation);
|
||||
}
|
||||
|
||||
return mutationType;
|
||||
}
|
||||
|
||||
if (operation.operation === 'subscription') {
|
||||
var subscriptionType = schema.getSubscriptionType();
|
||||
|
||||
if (!subscriptionType) {
|
||||
throw new GraphQLError('Schema is not configured for subscriptions.', operation);
|
||||
}
|
||||
|
||||
return subscriptionType;
|
||||
}
|
||||
|
||||
throw new GraphQLError('Can only have query, mutation and subscription operations.', operation);
|
||||
}
|
||||
127
node_modules/graphql/utilities/index.d.ts
generated
vendored
Normal file
127
node_modules/graphql/utilities/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
// The GraphQL query recommended for a full schema introspection.
|
||||
export {
|
||||
getIntrospectionQuery,
|
||||
// @deprecated, use getIntrospectionQuery() - will be removed in v15
|
||||
introspectionQuery,
|
||||
} from './introspectionQuery';
|
||||
|
||||
export {
|
||||
IntrospectionOptions,
|
||||
IntrospectionQuery,
|
||||
IntrospectionSchema,
|
||||
IntrospectionType,
|
||||
IntrospectionInputType,
|
||||
IntrospectionOutputType,
|
||||
IntrospectionScalarType,
|
||||
IntrospectionObjectType,
|
||||
IntrospectionInterfaceType,
|
||||
IntrospectionUnionType,
|
||||
IntrospectionEnumType,
|
||||
IntrospectionInputObjectType,
|
||||
IntrospectionTypeRef,
|
||||
IntrospectionInputTypeRef,
|
||||
IntrospectionOutputTypeRef,
|
||||
IntrospectionNamedTypeRef,
|
||||
IntrospectionListTypeRef,
|
||||
IntrospectionNonNullTypeRef,
|
||||
IntrospectionField,
|
||||
IntrospectionInputValue,
|
||||
IntrospectionEnumValue,
|
||||
IntrospectionDirective,
|
||||
} from './introspectionQuery';
|
||||
|
||||
// Gets the target Operation from a Document
|
||||
export { getOperationAST } from './getOperationAST';
|
||||
|
||||
// Gets the Type for the target Operation AST.
|
||||
export { getOperationRootType } from './getOperationRootType';
|
||||
|
||||
// Convert a GraphQLSchema to an IntrospectionQuery
|
||||
export { introspectionFromSchema } from './introspectionFromSchema';
|
||||
|
||||
// Build a GraphQLSchema from an introspection result.
|
||||
export { buildClientSchema } from './buildClientSchema';
|
||||
|
||||
// Build a GraphQLSchema from GraphQL Schema language.
|
||||
export {
|
||||
buildASTSchema,
|
||||
buildSchema,
|
||||
// @deprecated: Get the description from a schema AST node and supports legacy
|
||||
// syntax for specifying descriptions - will be removed in v16
|
||||
getDescription,
|
||||
BuildSchemaOptions,
|
||||
} from './buildASTSchema';
|
||||
|
||||
// Extends an existing GraphQLSchema from a parsed GraphQL Schema language AST.
|
||||
export { extendSchema } from './extendSchema';
|
||||
|
||||
// Sort a GraphQLSchema.
|
||||
export { lexicographicSortSchema } from './lexicographicSortSchema';
|
||||
|
||||
// Print a GraphQLSchema to GraphQL Schema language.
|
||||
export {
|
||||
printSchema,
|
||||
printType,
|
||||
printIntrospectionSchema,
|
||||
} from './schemaPrinter';
|
||||
|
||||
// Create a GraphQLType from a GraphQL language AST.
|
||||
export { typeFromAST } from './typeFromAST';
|
||||
|
||||
// Create a JavaScript value from a GraphQL language AST with a type.
|
||||
export { valueFromAST } from './valueFromAST';
|
||||
|
||||
// Create a JavaScript value from a GraphQL language AST without a type.
|
||||
export { valueFromASTUntyped } from './valueFromASTUntyped';
|
||||
|
||||
// Create a GraphQL language AST from a JavaScript value.
|
||||
export { astFromValue } from './astFromValue';
|
||||
|
||||
// A helper to use within recursive-descent visitors which need to be aware of
|
||||
// the GraphQL type system.
|
||||
export { TypeInfo } from './TypeInfo';
|
||||
|
||||
// Coerces a JavaScript value to a GraphQL type, or produces errors.
|
||||
export { coerceInputValue } from './coerceInputValue';
|
||||
|
||||
// Coerces a JavaScript value to a GraphQL type, or produces errors.
|
||||
export { coerceValue } from './coerceValue';
|
||||
|
||||
// @deprecated use coerceValue - will be removed in v15
|
||||
export { isValidJSValue } from './isValidJSValue';
|
||||
|
||||
// @deprecated use validation - will be removed in v15
|
||||
export { isValidLiteralValue } from './isValidLiteralValue';
|
||||
|
||||
// Concatenates multiple AST together.
|
||||
export { concatAST } from './concatAST';
|
||||
|
||||
// Separates an AST into an AST per Operation.
|
||||
export { separateOperations } from './separateOperations';
|
||||
|
||||
// Strips characters that are not significant to the validity or execution
|
||||
// of a GraphQL document.
|
||||
export { stripIgnoredCharacters } from './stripIgnoredCharacters';
|
||||
|
||||
// Comparators for types
|
||||
export {
|
||||
isEqualType,
|
||||
isTypeSubTypeOf,
|
||||
doTypesOverlap,
|
||||
} from './typeComparators';
|
||||
|
||||
// Asserts that a string is a valid GraphQL name
|
||||
export { assertValidName, isValidNameError } from './assertValidName';
|
||||
|
||||
// Compares two GraphQLSchemas and detects breaking changes.
|
||||
export {
|
||||
BreakingChangeType,
|
||||
DangerousChangeType,
|
||||
findBreakingChanges,
|
||||
findDangerousChanges,
|
||||
BreakingChange,
|
||||
DangerousChange,
|
||||
} from './findBreakingChanges';
|
||||
|
||||
// Report all deprecated usage within a GraphQL document.
|
||||
export { findDeprecatedUsages } from './findDeprecatedUsages';
|
||||
271
node_modules/graphql/utilities/index.js
generated
vendored
Normal file
271
node_modules/graphql/utilities/index.js
generated
vendored
Normal file
@@ -0,0 +1,271 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "getIntrospectionQuery", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _introspectionQuery.getIntrospectionQuery;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "introspectionQuery", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _introspectionQuery.introspectionQuery;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "getOperationAST", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _getOperationAST.getOperationAST;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "getOperationRootType", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _getOperationRootType.getOperationRootType;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "introspectionFromSchema", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _introspectionFromSchema.introspectionFromSchema;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "buildClientSchema", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _buildClientSchema.buildClientSchema;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "buildASTSchema", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _buildASTSchema.buildASTSchema;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "buildSchema", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _buildASTSchema.buildSchema;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "getDescription", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _buildASTSchema.getDescription;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "extendSchema", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _extendSchema.extendSchema;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "lexicographicSortSchema", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _lexicographicSortSchema.lexicographicSortSchema;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "printSchema", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _schemaPrinter.printSchema;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "printType", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _schemaPrinter.printType;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "printIntrospectionSchema", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _schemaPrinter.printIntrospectionSchema;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "typeFromAST", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _typeFromAST.typeFromAST;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "valueFromAST", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _valueFromAST.valueFromAST;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "valueFromASTUntyped", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _valueFromASTUntyped.valueFromASTUntyped;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "astFromValue", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _astFromValue.astFromValue;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "TypeInfo", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _TypeInfo.TypeInfo;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "coerceInputValue", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _coerceInputValue.coerceInputValue;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "coerceValue", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _coerceValue.coerceValue;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isValidJSValue", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _isValidJSValue.isValidJSValue;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isValidLiteralValue", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _isValidLiteralValue.isValidLiteralValue;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "concatAST", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _concatAST.concatAST;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "separateOperations", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _separateOperations.separateOperations;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "stripIgnoredCharacters", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _stripIgnoredCharacters.stripIgnoredCharacters;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isEqualType", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _typeComparators.isEqualType;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isTypeSubTypeOf", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _typeComparators.isTypeSubTypeOf;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "doTypesOverlap", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _typeComparators.doTypesOverlap;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "assertValidName", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _assertValidName.assertValidName;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isValidNameError", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _assertValidName.isValidNameError;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "BreakingChangeType", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _findBreakingChanges.BreakingChangeType;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "DangerousChangeType", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _findBreakingChanges.DangerousChangeType;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "findBreakingChanges", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _findBreakingChanges.findBreakingChanges;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "findDangerousChanges", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _findBreakingChanges.findDangerousChanges;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "findDeprecatedUsages", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _findDeprecatedUsages.findDeprecatedUsages;
|
||||
}
|
||||
});
|
||||
|
||||
var _introspectionQuery = require("./introspectionQuery");
|
||||
|
||||
var _getOperationAST = require("./getOperationAST");
|
||||
|
||||
var _getOperationRootType = require("./getOperationRootType");
|
||||
|
||||
var _introspectionFromSchema = require("./introspectionFromSchema");
|
||||
|
||||
var _buildClientSchema = require("./buildClientSchema");
|
||||
|
||||
var _buildASTSchema = require("./buildASTSchema");
|
||||
|
||||
var _extendSchema = require("./extendSchema");
|
||||
|
||||
var _lexicographicSortSchema = require("./lexicographicSortSchema");
|
||||
|
||||
var _schemaPrinter = require("./schemaPrinter");
|
||||
|
||||
var _typeFromAST = require("./typeFromAST");
|
||||
|
||||
var _valueFromAST = require("./valueFromAST");
|
||||
|
||||
var _valueFromASTUntyped = require("./valueFromASTUntyped");
|
||||
|
||||
var _astFromValue = require("./astFromValue");
|
||||
|
||||
var _TypeInfo = require("./TypeInfo");
|
||||
|
||||
var _coerceInputValue = require("./coerceInputValue");
|
||||
|
||||
var _coerceValue = require("./coerceValue");
|
||||
|
||||
var _isValidJSValue = require("./isValidJSValue");
|
||||
|
||||
var _isValidLiteralValue = require("./isValidLiteralValue");
|
||||
|
||||
var _concatAST = require("./concatAST");
|
||||
|
||||
var _separateOperations = require("./separateOperations");
|
||||
|
||||
var _stripIgnoredCharacters = require("./stripIgnoredCharacters");
|
||||
|
||||
var _typeComparators = require("./typeComparators");
|
||||
|
||||
var _assertValidName = require("./assertValidName");
|
||||
|
||||
var _findBreakingChanges = require("./findBreakingChanges");
|
||||
|
||||
var _findDeprecatedUsages = require("./findDeprecatedUsages");
|
||||
130
node_modules/graphql/utilities/index.js.flow
generated
vendored
Normal file
130
node_modules/graphql/utilities/index.js.flow
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
// @flow strict
|
||||
|
||||
// The GraphQL query recommended for a full schema introspection.
|
||||
export {
|
||||
// Produce the GraphQL query recommended for a full schema introspection.
|
||||
// Accepts optional IntrospectionOptions.
|
||||
getIntrospectionQuery,
|
||||
// @deprecated, use getIntrospectionQuery() - will be removed in v15.
|
||||
introspectionQuery,
|
||||
} from './introspectionQuery';
|
||||
|
||||
export type {
|
||||
IntrospectionOptions,
|
||||
IntrospectionQuery,
|
||||
IntrospectionSchema,
|
||||
IntrospectionType,
|
||||
IntrospectionInputType,
|
||||
IntrospectionOutputType,
|
||||
IntrospectionScalarType,
|
||||
IntrospectionObjectType,
|
||||
IntrospectionInterfaceType,
|
||||
IntrospectionUnionType,
|
||||
IntrospectionEnumType,
|
||||
IntrospectionInputObjectType,
|
||||
IntrospectionTypeRef,
|
||||
IntrospectionInputTypeRef,
|
||||
IntrospectionOutputTypeRef,
|
||||
IntrospectionNamedTypeRef,
|
||||
IntrospectionListTypeRef,
|
||||
IntrospectionNonNullTypeRef,
|
||||
IntrospectionField,
|
||||
IntrospectionInputValue,
|
||||
IntrospectionEnumValue,
|
||||
IntrospectionDirective,
|
||||
} from './introspectionQuery';
|
||||
|
||||
// Gets the target Operation from a Document.
|
||||
export { getOperationAST } from './getOperationAST';
|
||||
|
||||
// Gets the Type for the target Operation AST.
|
||||
export { getOperationRootType } from './getOperationRootType';
|
||||
|
||||
// Convert a GraphQLSchema to an IntrospectionQuery.
|
||||
export { introspectionFromSchema } from './introspectionFromSchema';
|
||||
|
||||
// Build a GraphQLSchema from an introspection result.
|
||||
export { buildClientSchema } from './buildClientSchema';
|
||||
|
||||
// Build a GraphQLSchema from GraphQL Schema language.
|
||||
export {
|
||||
buildASTSchema,
|
||||
buildSchema,
|
||||
// @deprecated: Get the description from a schema AST node and supports legacy
|
||||
// syntax for specifying descriptions - will be removed in v16.
|
||||
getDescription,
|
||||
} from './buildASTSchema';
|
||||
export type { BuildSchemaOptions } from './buildASTSchema';
|
||||
|
||||
// Extends an existing GraphQLSchema from a parsed GraphQL Schema language AST.
|
||||
export { extendSchema } from './extendSchema';
|
||||
|
||||
// Sort a GraphQLSchema.
|
||||
export { lexicographicSortSchema } from './lexicographicSortSchema';
|
||||
|
||||
// Print a GraphQLSchema to GraphQL Schema language.
|
||||
export {
|
||||
printSchema,
|
||||
printType,
|
||||
printIntrospectionSchema,
|
||||
} from './schemaPrinter';
|
||||
|
||||
// Create a GraphQLType from a GraphQL language AST.
|
||||
export { typeFromAST } from './typeFromAST';
|
||||
|
||||
// Create a JavaScript value from a GraphQL language AST with a type.
|
||||
export { valueFromAST } from './valueFromAST';
|
||||
|
||||
// Create a JavaScript value from a GraphQL language AST without a type.
|
||||
export { valueFromASTUntyped } from './valueFromASTUntyped';
|
||||
|
||||
// Create a GraphQL language AST from a JavaScript value.
|
||||
export { astFromValue } from './astFromValue';
|
||||
|
||||
// A helper to use within recursive-descent visitors which need to be aware of
|
||||
// the GraphQL type system.
|
||||
export { TypeInfo } from './TypeInfo';
|
||||
|
||||
// Coerces a JavaScript value to a GraphQL type, or produces errors.
|
||||
export { coerceInputValue } from './coerceInputValue';
|
||||
|
||||
// @deprecated use coerceInputValue - will be removed in v15.
|
||||
export { coerceValue } from './coerceValue';
|
||||
|
||||
// @deprecated use coerceInputValue - will be removed in v15.
|
||||
export { isValidJSValue } from './isValidJSValue';
|
||||
|
||||
// @deprecated use validation - will be removed in v15
|
||||
export { isValidLiteralValue } from './isValidLiteralValue';
|
||||
|
||||
// Concatenates multiple AST together.
|
||||
export { concatAST } from './concatAST';
|
||||
|
||||
// Separates an AST into an AST per Operation.
|
||||
export { separateOperations } from './separateOperations';
|
||||
|
||||
// Strips characters that are not significant to the validity or execution
|
||||
// of a GraphQL document.
|
||||
export { stripIgnoredCharacters } from './stripIgnoredCharacters';
|
||||
|
||||
// Comparators for types
|
||||
export {
|
||||
isEqualType,
|
||||
isTypeSubTypeOf,
|
||||
doTypesOverlap,
|
||||
} from './typeComparators';
|
||||
|
||||
// Asserts that a string is a valid GraphQL name
|
||||
export { assertValidName, isValidNameError } from './assertValidName';
|
||||
|
||||
// Compares two GraphQLSchemas and detects breaking changes.
|
||||
export {
|
||||
BreakingChangeType,
|
||||
DangerousChangeType,
|
||||
findBreakingChanges,
|
||||
findDangerousChanges,
|
||||
} from './findBreakingChanges';
|
||||
export type { BreakingChange, DangerousChange } from './findBreakingChanges';
|
||||
|
||||
// Report all deprecated usage within a GraphQL document.
|
||||
export { findDeprecatedUsages } from './findDeprecatedUsages';
|
||||
57
node_modules/graphql/utilities/index.mjs
generated
vendored
Normal file
57
node_modules/graphql/utilities/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
// The GraphQL query recommended for a full schema introspection.
|
||||
export { // Produce the GraphQL query recommended for a full schema introspection.
|
||||
// Accepts optional IntrospectionOptions.
|
||||
getIntrospectionQuery, // @deprecated, use getIntrospectionQuery() - will be removed in v15.
|
||||
introspectionQuery } from './introspectionQuery';
|
||||
// Gets the target Operation from a Document.
|
||||
export { getOperationAST } from './getOperationAST'; // Gets the Type for the target Operation AST.
|
||||
|
||||
export { getOperationRootType } from './getOperationRootType'; // Convert a GraphQLSchema to an IntrospectionQuery.
|
||||
|
||||
export { introspectionFromSchema } from './introspectionFromSchema'; // Build a GraphQLSchema from an introspection result.
|
||||
|
||||
export { buildClientSchema } from './buildClientSchema'; // Build a GraphQLSchema from GraphQL Schema language.
|
||||
|
||||
export { buildASTSchema, buildSchema, // @deprecated: Get the description from a schema AST node and supports legacy
|
||||
// syntax for specifying descriptions - will be removed in v16.
|
||||
getDescription } from './buildASTSchema';
|
||||
// Extends an existing GraphQLSchema from a parsed GraphQL Schema language AST.
|
||||
export { extendSchema } from './extendSchema'; // Sort a GraphQLSchema.
|
||||
|
||||
export { lexicographicSortSchema } from './lexicographicSortSchema'; // Print a GraphQLSchema to GraphQL Schema language.
|
||||
|
||||
export { printSchema, printType, printIntrospectionSchema } from './schemaPrinter'; // Create a GraphQLType from a GraphQL language AST.
|
||||
|
||||
export { typeFromAST } from './typeFromAST'; // Create a JavaScript value from a GraphQL language AST with a type.
|
||||
|
||||
export { valueFromAST } from './valueFromAST'; // Create a JavaScript value from a GraphQL language AST without a type.
|
||||
|
||||
export { valueFromASTUntyped } from './valueFromASTUntyped'; // Create a GraphQL language AST from a JavaScript value.
|
||||
|
||||
export { astFromValue } from './astFromValue'; // A helper to use within recursive-descent visitors which need to be aware of
|
||||
// the GraphQL type system.
|
||||
|
||||
export { TypeInfo } from './TypeInfo'; // Coerces a JavaScript value to a GraphQL type, or produces errors.
|
||||
|
||||
export { coerceInputValue } from './coerceInputValue'; // @deprecated use coerceInputValue - will be removed in v15.
|
||||
|
||||
export { coerceValue } from './coerceValue'; // @deprecated use coerceInputValue - will be removed in v15.
|
||||
|
||||
export { isValidJSValue } from './isValidJSValue'; // @deprecated use validation - will be removed in v15
|
||||
|
||||
export { isValidLiteralValue } from './isValidLiteralValue'; // Concatenates multiple AST together.
|
||||
|
||||
export { concatAST } from './concatAST'; // Separates an AST into an AST per Operation.
|
||||
|
||||
export { separateOperations } from './separateOperations'; // Strips characters that are not significant to the validity or execution
|
||||
// of a GraphQL document.
|
||||
|
||||
export { stripIgnoredCharacters } from './stripIgnoredCharacters'; // Comparators for types
|
||||
|
||||
export { isEqualType, isTypeSubTypeOf, doTypesOverlap } from './typeComparators'; // Asserts that a string is a valid GraphQL name
|
||||
|
||||
export { assertValidName, isValidNameError } from './assertValidName'; // Compares two GraphQLSchemas and detects breaking changes.
|
||||
|
||||
export { BreakingChangeType, DangerousChangeType, findBreakingChanges, findDangerousChanges } from './findBreakingChanges';
|
||||
// Report all deprecated usage within a GraphQL document.
|
||||
export { findDeprecatedUsages } from './findDeprecatedUsages';
|
||||
16
node_modules/graphql/utilities/introspectionFromSchema.d.ts
generated
vendored
Normal file
16
node_modules/graphql/utilities/introspectionFromSchema.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { IntrospectionQuery, IntrospectionOptions } from './introspectionQuery';
|
||||
|
||||
/**
|
||||
* Build an IntrospectionQuery from a GraphQLSchema
|
||||
*
|
||||
* IntrospectionQuery is useful for utilities that care about type and field
|
||||
* relationships, but do not need to traverse through those relationships.
|
||||
*
|
||||
* This is the inverse of buildClientSchema. The primary use case is outside
|
||||
* of the server context, for instance when doing schema comparisons.
|
||||
*/
|
||||
export function introspectionFromSchema(
|
||||
schema: GraphQLSchema,
|
||||
options?: IntrospectionOptions,
|
||||
): IntrospectionQuery;
|
||||
36
node_modules/graphql/utilities/introspectionFromSchema.js
generated
vendored
Normal file
36
node_modules/graphql/utilities/introspectionFromSchema.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.introspectionFromSchema = introspectionFromSchema;
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _isPromise = _interopRequireDefault(require("../jsutils/isPromise"));
|
||||
|
||||
var _parser = require("../language/parser");
|
||||
|
||||
var _execute = require("../execution/execute");
|
||||
|
||||
var _introspectionQuery = require("./introspectionQuery");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Build an IntrospectionQuery from a GraphQLSchema
|
||||
*
|
||||
* IntrospectionQuery is useful for utilities that care about type and field
|
||||
* relationships, but do not need to traverse through those relationships.
|
||||
*
|
||||
* This is the inverse of buildClientSchema. The primary use case is outside
|
||||
* of the server context, for instance when doing schema comparisons.
|
||||
*/
|
||||
function introspectionFromSchema(schema, options) {
|
||||
var queryAST = (0, _parser.parse)((0, _introspectionQuery.getIntrospectionQuery)(options));
|
||||
var result = (0, _execute.execute)(schema, queryAST);
|
||||
|
||||
/* istanbul ignore next */
|
||||
!(0, _isPromise.default)(result) && !result.errors && result.data || (0, _invariant.default)(0);
|
||||
return result.data;
|
||||
}
|
||||
33
node_modules/graphql/utilities/introspectionFromSchema.js.flow
generated
vendored
Normal file
33
node_modules/graphql/utilities/introspectionFromSchema.js.flow
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// @flow strict
|
||||
|
||||
import invariant from '../jsutils/invariant';
|
||||
import isPromise from '../jsutils/isPromise';
|
||||
|
||||
import { parse } from '../language/parser';
|
||||
import { execute } from '../execution/execute';
|
||||
import { type GraphQLSchema } from '../type/schema';
|
||||
|
||||
import {
|
||||
type IntrospectionQuery,
|
||||
type IntrospectionOptions,
|
||||
getIntrospectionQuery,
|
||||
} from './introspectionQuery';
|
||||
|
||||
/**
|
||||
* Build an IntrospectionQuery from a GraphQLSchema
|
||||
*
|
||||
* IntrospectionQuery is useful for utilities that care about type and field
|
||||
* relationships, but do not need to traverse through those relationships.
|
||||
*
|
||||
* This is the inverse of buildClientSchema. The primary use case is outside
|
||||
* of the server context, for instance when doing schema comparisons.
|
||||
*/
|
||||
export function introspectionFromSchema(
|
||||
schema: GraphQLSchema,
|
||||
options?: IntrospectionOptions,
|
||||
): IntrospectionQuery {
|
||||
const queryAST = parse(getIntrospectionQuery(options));
|
||||
const result = execute(schema, queryAST);
|
||||
invariant(!isPromise(result) && !result.errors && result.data);
|
||||
return (result.data: any);
|
||||
}
|
||||
23
node_modules/graphql/utilities/introspectionFromSchema.mjs
generated
vendored
Normal file
23
node_modules/graphql/utilities/introspectionFromSchema.mjs
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import invariant from '../jsutils/invariant';
|
||||
import isPromise from '../jsutils/isPromise';
|
||||
import { parse } from '../language/parser';
|
||||
import { execute } from '../execution/execute';
|
||||
import { getIntrospectionQuery } from './introspectionQuery';
|
||||
/**
|
||||
* Build an IntrospectionQuery from a GraphQLSchema
|
||||
*
|
||||
* IntrospectionQuery is useful for utilities that care about type and field
|
||||
* relationships, but do not need to traverse through those relationships.
|
||||
*
|
||||
* This is the inverse of buildClientSchema. The primary use case is outside
|
||||
* of the server context, for instance when doing schema comparisons.
|
||||
*/
|
||||
|
||||
export function introspectionFromSchema(schema, options) {
|
||||
var queryAST = parse(getIntrospectionQuery(options));
|
||||
var result = execute(schema, queryAST);
|
||||
|
||||
/* istanbul ignore next */
|
||||
!isPromise(result) && !result.errors && result.data || invariant(0);
|
||||
return result.data;
|
||||
}
|
||||
177
node_modules/graphql/utilities/introspectionQuery.d.ts
generated
vendored
Normal file
177
node_modules/graphql/utilities/introspectionQuery.d.ts
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
import Maybe from '../tsutils/Maybe';
|
||||
import { DirectiveLocationEnum } from '../language/directiveLocation';
|
||||
|
||||
export interface IntrospectionOptions {
|
||||
// Whether to include descriptions in the introspection result.
|
||||
// Default: true
|
||||
descriptions: boolean;
|
||||
}
|
||||
|
||||
export function getIntrospectionQuery(options?: IntrospectionOptions): string;
|
||||
|
||||
/**
|
||||
* Deprecated, call getIntrospectionQuery directly.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
export const introspectionQuery: string;
|
||||
|
||||
export interface IntrospectionQuery {
|
||||
readonly __schema: IntrospectionSchema;
|
||||
}
|
||||
|
||||
export interface IntrospectionSchema {
|
||||
readonly queryType: IntrospectionNamedTypeRef<IntrospectionObjectType>;
|
||||
readonly mutationType: Maybe<
|
||||
IntrospectionNamedTypeRef<IntrospectionObjectType>
|
||||
>;
|
||||
readonly subscriptionType: Maybe<
|
||||
IntrospectionNamedTypeRef<IntrospectionObjectType>
|
||||
>;
|
||||
readonly types: ReadonlyArray<IntrospectionType>;
|
||||
readonly directives: ReadonlyArray<IntrospectionDirective>;
|
||||
}
|
||||
|
||||
export type IntrospectionType =
|
||||
| IntrospectionScalarType
|
||||
| IntrospectionObjectType
|
||||
| IntrospectionInterfaceType
|
||||
| IntrospectionUnionType
|
||||
| IntrospectionEnumType
|
||||
| IntrospectionInputObjectType;
|
||||
|
||||
export type IntrospectionOutputType =
|
||||
| IntrospectionScalarType
|
||||
| IntrospectionObjectType
|
||||
| IntrospectionInterfaceType
|
||||
| IntrospectionUnionType
|
||||
| IntrospectionEnumType;
|
||||
|
||||
export type IntrospectionInputType =
|
||||
| IntrospectionScalarType
|
||||
| IntrospectionEnumType
|
||||
| IntrospectionInputObjectType;
|
||||
|
||||
export interface IntrospectionScalarType {
|
||||
readonly kind: 'SCALAR';
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
}
|
||||
|
||||
export interface IntrospectionObjectType {
|
||||
readonly kind: 'OBJECT';
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
readonly fields: ReadonlyArray<IntrospectionField>;
|
||||
readonly interfaces: ReadonlyArray<
|
||||
IntrospectionNamedTypeRef<IntrospectionInterfaceType>
|
||||
>;
|
||||
}
|
||||
|
||||
export interface IntrospectionInterfaceType {
|
||||
readonly kind: 'INTERFACE';
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
readonly fields: ReadonlyArray<IntrospectionField>;
|
||||
readonly possibleTypes: ReadonlyArray<
|
||||
IntrospectionNamedTypeRef<IntrospectionObjectType>
|
||||
>;
|
||||
}
|
||||
|
||||
export interface IntrospectionUnionType {
|
||||
readonly kind: 'UNION';
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
readonly possibleTypes: ReadonlyArray<
|
||||
IntrospectionNamedTypeRef<IntrospectionObjectType>
|
||||
>;
|
||||
}
|
||||
|
||||
export interface IntrospectionEnumType {
|
||||
readonly kind: 'ENUM';
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
readonly enumValues: ReadonlyArray<IntrospectionEnumValue>;
|
||||
}
|
||||
|
||||
export interface IntrospectionInputObjectType {
|
||||
readonly kind: 'INPUT_OBJECT';
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
readonly inputFields: ReadonlyArray<IntrospectionInputValue>;
|
||||
}
|
||||
|
||||
export interface IntrospectionListTypeRef<
|
||||
T extends IntrospectionTypeRef = IntrospectionTypeRef
|
||||
> {
|
||||
readonly kind: 'LIST';
|
||||
readonly ofType: T;
|
||||
}
|
||||
|
||||
export interface IntrospectionNonNullTypeRef<
|
||||
T extends IntrospectionTypeRef = IntrospectionTypeRef
|
||||
> {
|
||||
readonly kind: 'NON_NULL';
|
||||
readonly ofType: T;
|
||||
}
|
||||
|
||||
export type IntrospectionTypeRef =
|
||||
| IntrospectionNamedTypeRef<IntrospectionType>
|
||||
| IntrospectionListTypeRef<any>
|
||||
| IntrospectionNonNullTypeRef<
|
||||
| IntrospectionNamedTypeRef<IntrospectionType>
|
||||
| IntrospectionListTypeRef<any>
|
||||
>;
|
||||
|
||||
export type IntrospectionOutputTypeRef =
|
||||
| IntrospectionNamedTypeRef<IntrospectionOutputType>
|
||||
| IntrospectionListTypeRef<any>
|
||||
| IntrospectionNonNullTypeRef<
|
||||
| IntrospectionNamedTypeRef<IntrospectionOutputType>
|
||||
| IntrospectionListTypeRef<any>
|
||||
>;
|
||||
|
||||
export type IntrospectionInputTypeRef =
|
||||
| IntrospectionNamedTypeRef<IntrospectionInputType>
|
||||
| IntrospectionListTypeRef<any>
|
||||
| IntrospectionNonNullTypeRef<
|
||||
| IntrospectionNamedTypeRef<IntrospectionInputType>
|
||||
| IntrospectionListTypeRef<any>
|
||||
>;
|
||||
|
||||
export interface IntrospectionNamedTypeRef<
|
||||
T extends IntrospectionType = IntrospectionType
|
||||
> {
|
||||
readonly kind: T['kind'];
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
export interface IntrospectionField {
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
readonly args: ReadonlyArray<IntrospectionInputValue>;
|
||||
readonly type: IntrospectionOutputTypeRef;
|
||||
readonly isDeprecated: boolean;
|
||||
readonly deprecationReason?: Maybe<string>;
|
||||
}
|
||||
|
||||
export interface IntrospectionInputValue {
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
readonly type: IntrospectionInputTypeRef;
|
||||
readonly defaultValue?: Maybe<string>;
|
||||
}
|
||||
|
||||
export interface IntrospectionEnumValue {
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
readonly isDeprecated: boolean;
|
||||
readonly deprecationReason?: Maybe<string>;
|
||||
}
|
||||
|
||||
export interface IntrospectionDirective {
|
||||
readonly name: string;
|
||||
readonly description?: Maybe<string>;
|
||||
readonly locations: ReadonlyArray<DirectiveLocationEnum>;
|
||||
readonly args: ReadonlyArray<IntrospectionInputValue>;
|
||||
}
|
||||
21
node_modules/graphql/utilities/introspectionQuery.js
generated
vendored
Normal file
21
node_modules/graphql/utilities/introspectionQuery.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getIntrospectionQuery = getIntrospectionQuery;
|
||||
exports.introspectionQuery = void 0;
|
||||
|
||||
function getIntrospectionQuery(options) {
|
||||
var descriptions = !(options && options.descriptions === false);
|
||||
return "\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n ".concat(descriptions ? 'description' : '', "\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n ").concat(descriptions ? 'description' : '', "\n fields(includeDeprecated: true) {\n name\n ").concat(descriptions ? 'description' : '', "\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n ").concat(descriptions ? 'description' : '', "\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n ").concat(descriptions ? 'description' : '', "\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n ");
|
||||
}
|
||||
/**
|
||||
* Deprecated, call getIntrospectionQuery directly.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
|
||||
|
||||
var introspectionQuery = getIntrospectionQuery();
|
||||
exports.introspectionQuery = introspectionQuery;
|
||||
278
node_modules/graphql/utilities/introspectionQuery.js.flow
generated
vendored
Normal file
278
node_modules/graphql/utilities/introspectionQuery.js.flow
generated
vendored
Normal file
@@ -0,0 +1,278 @@
|
||||
// @flow strict
|
||||
|
||||
import { type DirectiveLocationEnum } from '../language/directiveLocation';
|
||||
|
||||
export type IntrospectionOptions = {|
|
||||
// Whether to include descriptions in the introspection result.
|
||||
// Default: true
|
||||
descriptions: boolean,
|
||||
|};
|
||||
|
||||
export function getIntrospectionQuery(options?: IntrospectionOptions): string {
|
||||
const descriptions = !(options && options.descriptions === false);
|
||||
return `
|
||||
query IntrospectionQuery {
|
||||
__schema {
|
||||
queryType { name }
|
||||
mutationType { name }
|
||||
subscriptionType { name }
|
||||
types {
|
||||
...FullType
|
||||
}
|
||||
directives {
|
||||
name
|
||||
${descriptions ? 'description' : ''}
|
||||
locations
|
||||
args {
|
||||
...InputValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment FullType on __Type {
|
||||
kind
|
||||
name
|
||||
${descriptions ? 'description' : ''}
|
||||
fields(includeDeprecated: true) {
|
||||
name
|
||||
${descriptions ? 'description' : ''}
|
||||
args {
|
||||
...InputValue
|
||||
}
|
||||
type {
|
||||
...TypeRef
|
||||
}
|
||||
isDeprecated
|
||||
deprecationReason
|
||||
}
|
||||
inputFields {
|
||||
...InputValue
|
||||
}
|
||||
interfaces {
|
||||
...TypeRef
|
||||
}
|
||||
enumValues(includeDeprecated: true) {
|
||||
name
|
||||
${descriptions ? 'description' : ''}
|
||||
isDeprecated
|
||||
deprecationReason
|
||||
}
|
||||
possibleTypes {
|
||||
...TypeRef
|
||||
}
|
||||
}
|
||||
|
||||
fragment InputValue on __InputValue {
|
||||
name
|
||||
${descriptions ? 'description' : ''}
|
||||
type { ...TypeRef }
|
||||
defaultValue
|
||||
}
|
||||
|
||||
fragment TypeRef on __Type {
|
||||
kind
|
||||
name
|
||||
ofType {
|
||||
kind
|
||||
name
|
||||
ofType {
|
||||
kind
|
||||
name
|
||||
ofType {
|
||||
kind
|
||||
name
|
||||
ofType {
|
||||
kind
|
||||
name
|
||||
ofType {
|
||||
kind
|
||||
name
|
||||
ofType {
|
||||
kind
|
||||
name
|
||||
ofType {
|
||||
kind
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, call getIntrospectionQuery directly.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
export const introspectionQuery = getIntrospectionQuery();
|
||||
|
||||
export type IntrospectionQuery = {|
|
||||
+__schema: IntrospectionSchema,
|
||||
|};
|
||||
|
||||
export type IntrospectionSchema = {|
|
||||
+queryType: IntrospectionNamedTypeRef<IntrospectionObjectType>,
|
||||
+mutationType: ?IntrospectionNamedTypeRef<IntrospectionObjectType>,
|
||||
+subscriptionType: ?IntrospectionNamedTypeRef<IntrospectionObjectType>,
|
||||
+types: $ReadOnlyArray<IntrospectionType>,
|
||||
+directives: $ReadOnlyArray<IntrospectionDirective>,
|
||||
|};
|
||||
|
||||
export type IntrospectionType =
|
||||
| IntrospectionScalarType
|
||||
| IntrospectionObjectType
|
||||
| IntrospectionInterfaceType
|
||||
| IntrospectionUnionType
|
||||
| IntrospectionEnumType
|
||||
| IntrospectionInputObjectType;
|
||||
|
||||
export type IntrospectionOutputType =
|
||||
| IntrospectionScalarType
|
||||
| IntrospectionObjectType
|
||||
| IntrospectionInterfaceType
|
||||
| IntrospectionUnionType
|
||||
| IntrospectionEnumType;
|
||||
|
||||
export type IntrospectionInputType =
|
||||
| IntrospectionScalarType
|
||||
| IntrospectionEnumType
|
||||
| IntrospectionInputObjectType;
|
||||
|
||||
export type IntrospectionScalarType = {
|
||||
+kind: 'SCALAR',
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
...
|
||||
};
|
||||
|
||||
export type IntrospectionObjectType = {
|
||||
+kind: 'OBJECT',
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
+fields: $ReadOnlyArray<IntrospectionField>,
|
||||
+interfaces: $ReadOnlyArray<
|
||||
IntrospectionNamedTypeRef<IntrospectionInterfaceType>,
|
||||
>,
|
||||
...
|
||||
};
|
||||
|
||||
export type IntrospectionInterfaceType = {
|
||||
+kind: 'INTERFACE',
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
+fields: $ReadOnlyArray<IntrospectionField>,
|
||||
+possibleTypes: $ReadOnlyArray<
|
||||
IntrospectionNamedTypeRef<IntrospectionObjectType>,
|
||||
>,
|
||||
...
|
||||
};
|
||||
|
||||
export type IntrospectionUnionType = {
|
||||
+kind: 'UNION',
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
+possibleTypes: $ReadOnlyArray<
|
||||
IntrospectionNamedTypeRef<IntrospectionObjectType>,
|
||||
>,
|
||||
...
|
||||
};
|
||||
|
||||
export type IntrospectionEnumType = {
|
||||
+kind: 'ENUM',
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
+enumValues: $ReadOnlyArray<IntrospectionEnumValue>,
|
||||
...
|
||||
};
|
||||
|
||||
export type IntrospectionInputObjectType = {
|
||||
+kind: 'INPUT_OBJECT',
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
+inputFields: $ReadOnlyArray<IntrospectionInputValue>,
|
||||
...
|
||||
};
|
||||
|
||||
export type IntrospectionListTypeRef<
|
||||
T: IntrospectionTypeRef = IntrospectionTypeRef,
|
||||
> = {
|
||||
+kind: 'LIST',
|
||||
+ofType: T,
|
||||
...
|
||||
};
|
||||
|
||||
export type IntrospectionNonNullTypeRef<
|
||||
T: IntrospectionTypeRef = IntrospectionTypeRef,
|
||||
> = {
|
||||
+kind: 'NON_NULL',
|
||||
+ofType: T,
|
||||
...
|
||||
};
|
||||
|
||||
export type IntrospectionTypeRef =
|
||||
| IntrospectionNamedTypeRef<IntrospectionType>
|
||||
| IntrospectionListTypeRef<IntrospectionTypeRef>
|
||||
| IntrospectionNonNullTypeRef<
|
||||
| IntrospectionNamedTypeRef<IntrospectionType>
|
||||
| IntrospectionListTypeRef<IntrospectionTypeRef>,
|
||||
>;
|
||||
|
||||
export type IntrospectionOutputTypeRef =
|
||||
| IntrospectionNamedTypeRef<IntrospectionOutputType>
|
||||
| IntrospectionListTypeRef<IntrospectionOutputTypeRef>
|
||||
| IntrospectionNonNullTypeRef<
|
||||
| IntrospectionNamedTypeRef<IntrospectionOutputType>
|
||||
| IntrospectionListTypeRef<IntrospectionOutputTypeRef>,
|
||||
>;
|
||||
|
||||
export type IntrospectionInputTypeRef =
|
||||
| IntrospectionNamedTypeRef<IntrospectionInputType>
|
||||
| IntrospectionListTypeRef<IntrospectionInputTypeRef>
|
||||
| IntrospectionNonNullTypeRef<
|
||||
| IntrospectionNamedTypeRef<IntrospectionInputType>
|
||||
| IntrospectionListTypeRef<IntrospectionInputTypeRef>,
|
||||
>;
|
||||
|
||||
export type IntrospectionNamedTypeRef<
|
||||
T: IntrospectionType = IntrospectionType,
|
||||
> = {
|
||||
+kind: $PropertyType<T, 'kind'>,
|
||||
+name: string,
|
||||
...
|
||||
};
|
||||
|
||||
export type IntrospectionField = {|
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
+args: $ReadOnlyArray<IntrospectionInputValue>,
|
||||
+type: IntrospectionOutputTypeRef,
|
||||
+isDeprecated: boolean,
|
||||
+deprecationReason: ?string,
|
||||
|};
|
||||
|
||||
export type IntrospectionInputValue = {|
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
+type: IntrospectionInputTypeRef,
|
||||
+defaultValue: ?string,
|
||||
|};
|
||||
|
||||
export type IntrospectionEnumValue = {|
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
+isDeprecated: boolean,
|
||||
+deprecationReason: ?string,
|
||||
|};
|
||||
|
||||
export type IntrospectionDirective = {|
|
||||
+name: string,
|
||||
+description?: ?string,
|
||||
+locations: $ReadOnlyArray<DirectiveLocationEnum>,
|
||||
+args: $ReadOnlyArray<IntrospectionInputValue>,
|
||||
|};
|
||||
11
node_modules/graphql/utilities/introspectionQuery.mjs
generated
vendored
Normal file
11
node_modules/graphql/utilities/introspectionQuery.mjs
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export function getIntrospectionQuery(options) {
|
||||
var descriptions = !(options && options.descriptions === false);
|
||||
return "\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n ".concat(descriptions ? 'description' : '', "\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n ").concat(descriptions ? 'description' : '', "\n fields(includeDeprecated: true) {\n name\n ").concat(descriptions ? 'description' : '', "\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n ").concat(descriptions ? 'description' : '', "\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n ").concat(descriptions ? 'description' : '', "\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n ");
|
||||
}
|
||||
/**
|
||||
* Deprecated, call getIntrospectionQuery directly.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
|
||||
export var introspectionQuery = getIntrospectionQuery();
|
||||
8
node_modules/graphql/utilities/isValidJSValue.d.ts
generated
vendored
Normal file
8
node_modules/graphql/utilities/isValidJSValue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { GraphQLInputType } from '../type/definition';
|
||||
|
||||
/**
|
||||
* Deprecated. Use coerceValue() directly for richer information.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
export function isValidJSValue(value: any, type: GraphQLInputType): string[];
|
||||
22
node_modules/graphql/utilities/isValidJSValue.js
generated
vendored
Normal file
22
node_modules/graphql/utilities/isValidJSValue.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isValidJSValue = isValidJSValue;
|
||||
|
||||
var _coerceValue = require("./coerceValue");
|
||||
|
||||
/* istanbul ignore file */
|
||||
|
||||
/**
|
||||
* Deprecated. Use coerceInputValue() directly for richer information.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
function isValidJSValue(value, type) {
|
||||
var errors = (0, _coerceValue.coerceValue)(value, type).errors;
|
||||
return errors ? errors.map(function (error) {
|
||||
return error.message;
|
||||
}) : [];
|
||||
}
|
||||
19
node_modules/graphql/utilities/isValidJSValue.js.flow
generated
vendored
Normal file
19
node_modules/graphql/utilities/isValidJSValue.js.flow
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// @flow strict
|
||||
|
||||
/* istanbul ignore file */
|
||||
import { type GraphQLInputType } from '../type/definition';
|
||||
|
||||
import { coerceValue } from './coerceValue';
|
||||
|
||||
/**
|
||||
* Deprecated. Use coerceInputValue() directly for richer information.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
export function isValidJSValue(
|
||||
value: mixed,
|
||||
type: GraphQLInputType,
|
||||
): Array<string> {
|
||||
const errors = coerceValue(value, type).errors;
|
||||
return errors ? errors.map(error => error.message) : [];
|
||||
}
|
||||
14
node_modules/graphql/utilities/isValidJSValue.mjs
generated
vendored
Normal file
14
node_modules/graphql/utilities/isValidJSValue.mjs
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
/* istanbul ignore file */
|
||||
import { coerceValue } from './coerceValue';
|
||||
/**
|
||||
* Deprecated. Use coerceInputValue() directly for richer information.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
|
||||
export function isValidJSValue(value, type) {
|
||||
var errors = coerceValue(value, type).errors;
|
||||
return errors ? errors.map(function (error) {
|
||||
return error.message;
|
||||
}) : [];
|
||||
}
|
||||
15
node_modules/graphql/utilities/isValidLiteralValue.d.ts
generated
vendored
Normal file
15
node_modules/graphql/utilities/isValidLiteralValue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { ValueNode } from '../language/ast';
|
||||
import { GraphQLInputType } from '../type/definition';
|
||||
|
||||
/**
|
||||
* Utility which determines if a value literal node is valid for an input type.
|
||||
*
|
||||
* Deprecated. Rely on validation for documents containing literal values.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
export function isValidLiteralValue(
|
||||
type: GraphQLInputType,
|
||||
valueNode: ValueNode,
|
||||
): ReadonlyArray<GraphQLError>;
|
||||
38
node_modules/graphql/utilities/isValidLiteralValue.js
generated
vendored
Normal file
38
node_modules/graphql/utilities/isValidLiteralValue.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isValidLiteralValue = isValidLiteralValue;
|
||||
|
||||
var _kinds = require("../language/kinds");
|
||||
|
||||
var _visitor = require("../language/visitor");
|
||||
|
||||
var _ValuesOfCorrectType = require("../validation/rules/ValuesOfCorrectType");
|
||||
|
||||
var _ValidationContext = require("../validation/ValidationContext");
|
||||
|
||||
var _schema = require("../type/schema");
|
||||
|
||||
var _TypeInfo = require("./TypeInfo");
|
||||
|
||||
/**
|
||||
* Utility which determines if a value literal node is valid for an input type.
|
||||
*
|
||||
* Deprecated. Rely on validation for documents containing literal values.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
function isValidLiteralValue(type, valueNode) {
|
||||
var emptySchema = new _schema.GraphQLSchema({});
|
||||
var emptyDoc = {
|
||||
kind: _kinds.Kind.DOCUMENT,
|
||||
definitions: []
|
||||
};
|
||||
var typeInfo = new _TypeInfo.TypeInfo(emptySchema, undefined, type);
|
||||
var context = new _ValidationContext.ValidationContext(emptySchema, emptyDoc, typeInfo);
|
||||
var visitor = (0, _ValuesOfCorrectType.ValuesOfCorrectType)(context);
|
||||
(0, _visitor.visit)(valueNode, (0, _visitor.visitWithTypeInfo)(typeInfo, visitor));
|
||||
return context.getErrors();
|
||||
}
|
||||
35
node_modules/graphql/utilities/isValidLiteralValue.js.flow
generated
vendored
Normal file
35
node_modules/graphql/utilities/isValidLiteralValue.js.flow
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// @flow strict
|
||||
|
||||
import { type GraphQLError } from '../error/GraphQLError';
|
||||
|
||||
import { Kind } from '../language/kinds';
|
||||
import { type ValueNode } from '../language/ast';
|
||||
import { visit, visitWithTypeInfo } from '../language/visitor';
|
||||
|
||||
import { ValuesOfCorrectType } from '../validation/rules/ValuesOfCorrectType';
|
||||
import { ValidationContext } from '../validation/ValidationContext';
|
||||
|
||||
import { type GraphQLInputType } from '../type/definition';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
|
||||
import { TypeInfo } from './TypeInfo';
|
||||
|
||||
/**
|
||||
* Utility which determines if a value literal node is valid for an input type.
|
||||
*
|
||||
* Deprecated. Rely on validation for documents containing literal values.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
export function isValidLiteralValue(
|
||||
type: GraphQLInputType,
|
||||
valueNode: ValueNode,
|
||||
): $ReadOnlyArray<GraphQLError> {
|
||||
const emptySchema = new GraphQLSchema({});
|
||||
const emptyDoc = { kind: Kind.DOCUMENT, definitions: [] };
|
||||
const typeInfo = new TypeInfo(emptySchema, undefined, type);
|
||||
const context = new ValidationContext(emptySchema, emptyDoc, typeInfo);
|
||||
const visitor = ValuesOfCorrectType(context);
|
||||
visit(valueNode, visitWithTypeInfo(typeInfo, visitor));
|
||||
return context.getErrors();
|
||||
}
|
||||
26
node_modules/graphql/utilities/isValidLiteralValue.mjs
generated
vendored
Normal file
26
node_modules/graphql/utilities/isValidLiteralValue.mjs
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Kind } from '../language/kinds';
|
||||
import { visit, visitWithTypeInfo } from '../language/visitor';
|
||||
import { ValuesOfCorrectType } from '../validation/rules/ValuesOfCorrectType';
|
||||
import { ValidationContext } from '../validation/ValidationContext';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { TypeInfo } from './TypeInfo';
|
||||
/**
|
||||
* Utility which determines if a value literal node is valid for an input type.
|
||||
*
|
||||
* Deprecated. Rely on validation for documents containing literal values.
|
||||
*
|
||||
* This function will be removed in v15
|
||||
*/
|
||||
|
||||
export function isValidLiteralValue(type, valueNode) {
|
||||
var emptySchema = new GraphQLSchema({});
|
||||
var emptyDoc = {
|
||||
kind: Kind.DOCUMENT,
|
||||
definitions: []
|
||||
};
|
||||
var typeInfo = new TypeInfo(emptySchema, undefined, type);
|
||||
var context = new ValidationContext(emptySchema, emptyDoc, typeInfo);
|
||||
var visitor = ValuesOfCorrectType(context);
|
||||
visit(valueNode, visitWithTypeInfo(typeInfo, visitor));
|
||||
return context.getErrors();
|
||||
}
|
||||
6
node_modules/graphql/utilities/lexicographicSortSchema.d.ts
generated
vendored
Normal file
6
node_modules/graphql/utilities/lexicographicSortSchema.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
|
||||
/**
|
||||
* Sort GraphQLSchema.
|
||||
*/
|
||||
export function lexicographicSortSchema(schema: GraphQLSchema): GraphQLSchema;
|
||||
183
node_modules/graphql/utilities/lexicographicSortSchema.js
generated
vendored
Normal file
183
node_modules/graphql/utilities/lexicographicSortSchema.js
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.lexicographicSortSchema = lexicographicSortSchema;
|
||||
|
||||
var _objectValues = _interopRequireDefault(require("../polyfills/objectValues"));
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _keyValMap = _interopRequireDefault(require("../jsutils/keyValMap"));
|
||||
|
||||
var _schema = require("../type/schema");
|
||||
|
||||
var _directives = require("../type/directives");
|
||||
|
||||
var _introspection = require("../type/introspection");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
/**
|
||||
* Sort GraphQLSchema.
|
||||
*/
|
||||
function lexicographicSortSchema(schema) {
|
||||
var schemaConfig = schema.toConfig();
|
||||
var typeMap = (0, _keyValMap.default)(sortByName(schemaConfig.types), function (type) {
|
||||
return type.name;
|
||||
}, sortNamedType);
|
||||
return new _schema.GraphQLSchema(_objectSpread({}, schemaConfig, {
|
||||
types: (0, _objectValues.default)(typeMap),
|
||||
directives: sortByName(schemaConfig.directives).map(sortDirective),
|
||||
query: replaceMaybeType(schemaConfig.query),
|
||||
mutation: replaceMaybeType(schemaConfig.mutation),
|
||||
subscription: replaceMaybeType(schemaConfig.subscription)
|
||||
}));
|
||||
|
||||
function replaceType(type) {
|
||||
if ((0, _definition.isListType)(type)) {
|
||||
return new _definition.GraphQLList(replaceType(type.ofType));
|
||||
} else if ((0, _definition.isNonNullType)(type)) {
|
||||
return new _definition.GraphQLNonNull(replaceType(type.ofType));
|
||||
}
|
||||
|
||||
return replaceNamedType(type);
|
||||
}
|
||||
|
||||
function replaceNamedType(type) {
|
||||
return typeMap[type.name];
|
||||
}
|
||||
|
||||
function replaceMaybeType(maybeType) {
|
||||
return maybeType && replaceNamedType(maybeType);
|
||||
}
|
||||
|
||||
function sortDirective(directive) {
|
||||
var config = directive.toConfig();
|
||||
return new _directives.GraphQLDirective(_objectSpread({}, config, {
|
||||
locations: sortBy(config.locations, function (x) {
|
||||
return x;
|
||||
}),
|
||||
args: sortArgs(config.args)
|
||||
}));
|
||||
}
|
||||
|
||||
function sortArgs(args) {
|
||||
return sortObjMap(args, function (arg) {
|
||||
return _objectSpread({}, arg, {
|
||||
type: replaceType(arg.type)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function sortFields(fieldsMap) {
|
||||
return sortObjMap(fieldsMap, function (field) {
|
||||
return _objectSpread({}, field, {
|
||||
type: replaceType(field.type),
|
||||
args: sortArgs(field.args)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function sortInputFields(fieldsMap) {
|
||||
return sortObjMap(fieldsMap, function (field) {
|
||||
return _objectSpread({}, field, {
|
||||
type: replaceType(field.type)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function sortTypes(arr) {
|
||||
return sortByName(arr).map(replaceNamedType);
|
||||
}
|
||||
|
||||
function sortNamedType(type) {
|
||||
if ((0, _definition.isScalarType)(type) || (0, _introspection.isIntrospectionType)(type)) {
|
||||
return type;
|
||||
} else if ((0, _definition.isObjectType)(type)) {
|
||||
var config = type.toConfig();
|
||||
return new _definition.GraphQLObjectType(_objectSpread({}, config, {
|
||||
interfaces: function interfaces() {
|
||||
return sortTypes(config.interfaces);
|
||||
},
|
||||
fields: function fields() {
|
||||
return sortFields(config.fields);
|
||||
}
|
||||
}));
|
||||
} else if ((0, _definition.isInterfaceType)(type)) {
|
||||
var _config = type.toConfig();
|
||||
|
||||
return new _definition.GraphQLInterfaceType(_objectSpread({}, _config, {
|
||||
fields: function fields() {
|
||||
return sortFields(_config.fields);
|
||||
}
|
||||
}));
|
||||
} else if ((0, _definition.isUnionType)(type)) {
|
||||
var _config2 = type.toConfig();
|
||||
|
||||
return new _definition.GraphQLUnionType(_objectSpread({}, _config2, {
|
||||
types: function types() {
|
||||
return sortTypes(_config2.types);
|
||||
}
|
||||
}));
|
||||
} else if ((0, _definition.isEnumType)(type)) {
|
||||
var _config3 = type.toConfig();
|
||||
|
||||
return new _definition.GraphQLEnumType(_objectSpread({}, _config3, {
|
||||
values: sortObjMap(_config3.values)
|
||||
}));
|
||||
} else if ((0, _definition.isInputObjectType)(type)) {
|
||||
var _config4 = type.toConfig();
|
||||
|
||||
return new _definition.GraphQLInputObjectType(_objectSpread({}, _config4, {
|
||||
fields: function fields() {
|
||||
return sortInputFields(_config4.fields);
|
||||
}
|
||||
}));
|
||||
} // Not reachable. All possible types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
(0, _invariant.default)(false, 'Unexpected type: ' + (0, _inspect.default)(type));
|
||||
}
|
||||
}
|
||||
|
||||
function sortObjMap(map, sortValueFn) {
|
||||
var sortedMap = Object.create(null);
|
||||
var sortedKeys = sortBy(Object.keys(map), function (x) {
|
||||
return x;
|
||||
});
|
||||
|
||||
for (var _i2 = 0; _i2 < sortedKeys.length; _i2++) {
|
||||
var key = sortedKeys[_i2];
|
||||
var value = map[key];
|
||||
sortedMap[key] = sortValueFn ? sortValueFn(value) : value;
|
||||
}
|
||||
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
function sortByName(array) {
|
||||
return sortBy(array, function (obj) {
|
||||
return obj.name;
|
||||
});
|
||||
}
|
||||
|
||||
function sortBy(array, mapToKey) {
|
||||
return array.slice().sort(function (obj1, obj2) {
|
||||
var key1 = mapToKey(obj1);
|
||||
var key2 = mapToKey(obj2);
|
||||
return key1.localeCompare(key2);
|
||||
});
|
||||
}
|
||||
167
node_modules/graphql/utilities/lexicographicSortSchema.js.flow
generated
vendored
Normal file
167
node_modules/graphql/utilities/lexicographicSortSchema.js.flow
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
// @flow strict
|
||||
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import keyValMap from '../jsutils/keyValMap';
|
||||
import { type ObjMap } from '../jsutils/ObjMap';
|
||||
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { GraphQLDirective } from '../type/directives';
|
||||
import { isIntrospectionType } from '../type/introspection';
|
||||
import {
|
||||
type GraphQLNamedType,
|
||||
GraphQLObjectType,
|
||||
GraphQLInterfaceType,
|
||||
GraphQLUnionType,
|
||||
GraphQLEnumType,
|
||||
GraphQLInputObjectType,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
isListType,
|
||||
isNonNullType,
|
||||
isScalarType,
|
||||
isObjectType,
|
||||
isInterfaceType,
|
||||
isUnionType,
|
||||
isEnumType,
|
||||
isInputObjectType,
|
||||
} from '../type/definition';
|
||||
|
||||
/**
|
||||
* Sort GraphQLSchema.
|
||||
*/
|
||||
export function lexicographicSortSchema(schema: GraphQLSchema): GraphQLSchema {
|
||||
const schemaConfig = schema.toConfig();
|
||||
const typeMap = keyValMap(
|
||||
sortByName(schemaConfig.types),
|
||||
type => type.name,
|
||||
sortNamedType,
|
||||
);
|
||||
|
||||
return new GraphQLSchema({
|
||||
...schemaConfig,
|
||||
types: objectValues(typeMap),
|
||||
directives: sortByName(schemaConfig.directives).map(sortDirective),
|
||||
query: replaceMaybeType(schemaConfig.query),
|
||||
mutation: replaceMaybeType(schemaConfig.mutation),
|
||||
subscription: replaceMaybeType(schemaConfig.subscription),
|
||||
});
|
||||
|
||||
function replaceType(type) {
|
||||
if (isListType(type)) {
|
||||
return new GraphQLList(replaceType(type.ofType));
|
||||
} else if (isNonNullType(type)) {
|
||||
return new GraphQLNonNull(replaceType(type.ofType));
|
||||
}
|
||||
return replaceNamedType(type);
|
||||
}
|
||||
|
||||
function replaceNamedType<T: GraphQLNamedType>(type: T): T {
|
||||
return ((typeMap[type.name]: any): T);
|
||||
}
|
||||
|
||||
function replaceMaybeType(maybeType) {
|
||||
return maybeType && replaceNamedType(maybeType);
|
||||
}
|
||||
|
||||
function sortDirective(directive) {
|
||||
const config = directive.toConfig();
|
||||
return new GraphQLDirective({
|
||||
...config,
|
||||
locations: sortBy(config.locations, x => x),
|
||||
args: sortArgs(config.args),
|
||||
});
|
||||
}
|
||||
|
||||
function sortArgs(args) {
|
||||
return sortObjMap(args, arg => ({
|
||||
...arg,
|
||||
type: replaceType(arg.type),
|
||||
}));
|
||||
}
|
||||
|
||||
function sortFields(fieldsMap) {
|
||||
return sortObjMap(fieldsMap, field => ({
|
||||
...field,
|
||||
type: replaceType(field.type),
|
||||
args: sortArgs(field.args),
|
||||
}));
|
||||
}
|
||||
|
||||
function sortInputFields(fieldsMap) {
|
||||
return sortObjMap(fieldsMap, field => ({
|
||||
...field,
|
||||
type: replaceType(field.type),
|
||||
}));
|
||||
}
|
||||
|
||||
function sortTypes<T: GraphQLNamedType>(arr: $ReadOnlyArray<T>): Array<T> {
|
||||
return sortByName(arr).map(replaceNamedType);
|
||||
}
|
||||
|
||||
function sortNamedType(type) {
|
||||
if (isScalarType(type) || isIntrospectionType(type)) {
|
||||
return type;
|
||||
} else if (isObjectType(type)) {
|
||||
const config = type.toConfig();
|
||||
return new GraphQLObjectType({
|
||||
...config,
|
||||
interfaces: () => sortTypes(config.interfaces),
|
||||
fields: () => sortFields(config.fields),
|
||||
});
|
||||
} else if (isInterfaceType(type)) {
|
||||
const config = type.toConfig();
|
||||
return new GraphQLInterfaceType({
|
||||
...config,
|
||||
fields: () => sortFields(config.fields),
|
||||
});
|
||||
} else if (isUnionType(type)) {
|
||||
const config = type.toConfig();
|
||||
return new GraphQLUnionType({
|
||||
...config,
|
||||
types: () => sortTypes(config.types),
|
||||
});
|
||||
} else if (isEnumType(type)) {
|
||||
const config = type.toConfig();
|
||||
return new GraphQLEnumType({
|
||||
...config,
|
||||
values: sortObjMap(config.values),
|
||||
});
|
||||
} else if (isInputObjectType(type)) {
|
||||
const config = type.toConfig();
|
||||
return new GraphQLInputObjectType({
|
||||
...config,
|
||||
fields: () => sortInputFields(config.fields),
|
||||
});
|
||||
}
|
||||
|
||||
// Not reachable. All possible types have been considered.
|
||||
invariant(false, 'Unexpected type: ' + inspect((type: empty)));
|
||||
}
|
||||
}
|
||||
|
||||
function sortObjMap<T, R>(map: ObjMap<T>, sortValueFn?: T => R): ObjMap<R> {
|
||||
const sortedMap = Object.create(null);
|
||||
const sortedKeys = sortBy(Object.keys(map), x => x);
|
||||
for (const key of sortedKeys) {
|
||||
const value = map[key];
|
||||
sortedMap[key] = sortValueFn ? sortValueFn(value) : value;
|
||||
}
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
function sortByName<T: { +name: string, ... }>(
|
||||
array: $ReadOnlyArray<T>,
|
||||
): Array<T> {
|
||||
return sortBy(array, obj => obj.name);
|
||||
}
|
||||
|
||||
function sortBy<T>(array: $ReadOnlyArray<T>, mapToKey: T => string): Array<T> {
|
||||
return array.slice().sort((obj1, obj2) => {
|
||||
const key1 = mapToKey(obj1);
|
||||
const key2 = mapToKey(obj2);
|
||||
return key1.localeCompare(key2);
|
||||
});
|
||||
}
|
||||
167
node_modules/graphql/utilities/lexicographicSortSchema.mjs
generated
vendored
Normal file
167
node_modules/graphql/utilities/lexicographicSortSchema.mjs
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import keyValMap from '../jsutils/keyValMap';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { GraphQLDirective } from '../type/directives';
|
||||
import { isIntrospectionType } from '../type/introspection';
|
||||
import { GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, GraphQLNonNull, isListType, isNonNullType, isScalarType, isObjectType, isInterfaceType, isUnionType, isEnumType, isInputObjectType } from '../type/definition';
|
||||
/**
|
||||
* Sort GraphQLSchema.
|
||||
*/
|
||||
|
||||
export function lexicographicSortSchema(schema) {
|
||||
var schemaConfig = schema.toConfig();
|
||||
var typeMap = keyValMap(sortByName(schemaConfig.types), function (type) {
|
||||
return type.name;
|
||||
}, sortNamedType);
|
||||
return new GraphQLSchema(_objectSpread({}, schemaConfig, {
|
||||
types: objectValues(typeMap),
|
||||
directives: sortByName(schemaConfig.directives).map(sortDirective),
|
||||
query: replaceMaybeType(schemaConfig.query),
|
||||
mutation: replaceMaybeType(schemaConfig.mutation),
|
||||
subscription: replaceMaybeType(schemaConfig.subscription)
|
||||
}));
|
||||
|
||||
function replaceType(type) {
|
||||
if (isListType(type)) {
|
||||
return new GraphQLList(replaceType(type.ofType));
|
||||
} else if (isNonNullType(type)) {
|
||||
return new GraphQLNonNull(replaceType(type.ofType));
|
||||
}
|
||||
|
||||
return replaceNamedType(type);
|
||||
}
|
||||
|
||||
function replaceNamedType(type) {
|
||||
return typeMap[type.name];
|
||||
}
|
||||
|
||||
function replaceMaybeType(maybeType) {
|
||||
return maybeType && replaceNamedType(maybeType);
|
||||
}
|
||||
|
||||
function sortDirective(directive) {
|
||||
var config = directive.toConfig();
|
||||
return new GraphQLDirective(_objectSpread({}, config, {
|
||||
locations: sortBy(config.locations, function (x) {
|
||||
return x;
|
||||
}),
|
||||
args: sortArgs(config.args)
|
||||
}));
|
||||
}
|
||||
|
||||
function sortArgs(args) {
|
||||
return sortObjMap(args, function (arg) {
|
||||
return _objectSpread({}, arg, {
|
||||
type: replaceType(arg.type)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function sortFields(fieldsMap) {
|
||||
return sortObjMap(fieldsMap, function (field) {
|
||||
return _objectSpread({}, field, {
|
||||
type: replaceType(field.type),
|
||||
args: sortArgs(field.args)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function sortInputFields(fieldsMap) {
|
||||
return sortObjMap(fieldsMap, function (field) {
|
||||
return _objectSpread({}, field, {
|
||||
type: replaceType(field.type)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function sortTypes(arr) {
|
||||
return sortByName(arr).map(replaceNamedType);
|
||||
}
|
||||
|
||||
function sortNamedType(type) {
|
||||
if (isScalarType(type) || isIntrospectionType(type)) {
|
||||
return type;
|
||||
} else if (isObjectType(type)) {
|
||||
var config = type.toConfig();
|
||||
return new GraphQLObjectType(_objectSpread({}, config, {
|
||||
interfaces: function interfaces() {
|
||||
return sortTypes(config.interfaces);
|
||||
},
|
||||
fields: function fields() {
|
||||
return sortFields(config.fields);
|
||||
}
|
||||
}));
|
||||
} else if (isInterfaceType(type)) {
|
||||
var _config = type.toConfig();
|
||||
|
||||
return new GraphQLInterfaceType(_objectSpread({}, _config, {
|
||||
fields: function fields() {
|
||||
return sortFields(_config.fields);
|
||||
}
|
||||
}));
|
||||
} else if (isUnionType(type)) {
|
||||
var _config2 = type.toConfig();
|
||||
|
||||
return new GraphQLUnionType(_objectSpread({}, _config2, {
|
||||
types: function types() {
|
||||
return sortTypes(_config2.types);
|
||||
}
|
||||
}));
|
||||
} else if (isEnumType(type)) {
|
||||
var _config3 = type.toConfig();
|
||||
|
||||
return new GraphQLEnumType(_objectSpread({}, _config3, {
|
||||
values: sortObjMap(_config3.values)
|
||||
}));
|
||||
} else if (isInputObjectType(type)) {
|
||||
var _config4 = type.toConfig();
|
||||
|
||||
return new GraphQLInputObjectType(_objectSpread({}, _config4, {
|
||||
fields: function fields() {
|
||||
return sortInputFields(_config4.fields);
|
||||
}
|
||||
}));
|
||||
} // Not reachable. All possible types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
invariant(false, 'Unexpected type: ' + inspect(type));
|
||||
}
|
||||
}
|
||||
|
||||
function sortObjMap(map, sortValueFn) {
|
||||
var sortedMap = Object.create(null);
|
||||
var sortedKeys = sortBy(Object.keys(map), function (x) {
|
||||
return x;
|
||||
});
|
||||
|
||||
for (var _i2 = 0; _i2 < sortedKeys.length; _i2++) {
|
||||
var key = sortedKeys[_i2];
|
||||
var value = map[key];
|
||||
sortedMap[key] = sortValueFn ? sortValueFn(value) : value;
|
||||
}
|
||||
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
function sortByName(array) {
|
||||
return sortBy(array, function (obj) {
|
||||
return obj.name;
|
||||
});
|
||||
}
|
||||
|
||||
function sortBy(array, mapToKey) {
|
||||
return array.slice().sort(function (obj1, obj2) {
|
||||
var key1 = mapToKey(obj1);
|
||||
var key2 = mapToKey(obj2);
|
||||
return key1.localeCompare(key2);
|
||||
});
|
||||
}
|
||||
30
node_modules/graphql/utilities/schemaPrinter.d.ts
generated
vendored
Normal file
30
node_modules/graphql/utilities/schemaPrinter.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { GraphQLType, GraphQLNamedType } from '../type/definition';
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
* Descriptions are defined as preceding string literals, however an older
|
||||
* experimental version of the SDL supported preceding comments as
|
||||
* descriptions. Set to true to enable this deprecated behavior.
|
||||
* This option is provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
commentDescriptions?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function printSchema(schema: GraphQLSchema, options?: Options): string;
|
||||
|
||||
export function printIntrospectionSchema(
|
||||
schema: GraphQLSchema,
|
||||
options?: Options,
|
||||
): string;
|
||||
|
||||
export function printType(type: GraphQLNamedType, options?: Options): string;
|
||||
310
node_modules/graphql/utilities/schemaPrinter.js
generated
vendored
Normal file
310
node_modules/graphql/utilities/schemaPrinter.js
generated
vendored
Normal file
@@ -0,0 +1,310 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.printSchema = printSchema;
|
||||
exports.printIntrospectionSchema = printIntrospectionSchema;
|
||||
exports.printType = printType;
|
||||
|
||||
var _flatMap = _interopRequireDefault(require("../polyfills/flatMap"));
|
||||
|
||||
var _objectValues = _interopRequireDefault(require("../polyfills/objectValues"));
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _printer = require("../language/printer");
|
||||
|
||||
var _blockString = require("../language/blockString");
|
||||
|
||||
var _introspection = require("../type/introspection");
|
||||
|
||||
var _scalars = require("../type/scalars");
|
||||
|
||||
var _directives = require("../type/directives");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
var _astFromValue = require("../utilities/astFromValue");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
function printSchema(schema, options) {
|
||||
return printFilteredSchema(schema, function (n) {
|
||||
return !(0, _directives.isSpecifiedDirective)(n);
|
||||
}, isDefinedType, options);
|
||||
}
|
||||
|
||||
function printIntrospectionSchema(schema, options) {
|
||||
return printFilteredSchema(schema, _directives.isSpecifiedDirective, _introspection.isIntrospectionType, options);
|
||||
}
|
||||
|
||||
function isDefinedType(type) {
|
||||
return !(0, _scalars.isSpecifiedScalarType)(type) && !(0, _introspection.isIntrospectionType)(type);
|
||||
}
|
||||
|
||||
function printFilteredSchema(schema, directiveFilter, typeFilter, options) {
|
||||
var directives = schema.getDirectives().filter(directiveFilter);
|
||||
var typeMap = schema.getTypeMap();
|
||||
var types = (0, _objectValues.default)(typeMap).sort(function (type1, type2) {
|
||||
return type1.name.localeCompare(type2.name);
|
||||
}).filter(typeFilter);
|
||||
return [printSchemaDefinition(schema)].concat(directives.map(function (directive) {
|
||||
return printDirective(directive, options);
|
||||
}), types.map(function (type) {
|
||||
return printType(type, options);
|
||||
})).filter(Boolean).join('\n\n') + '\n';
|
||||
}
|
||||
|
||||
function printSchemaDefinition(schema) {
|
||||
if (isSchemaOfCommonNames(schema)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var operationTypes = [];
|
||||
var queryType = schema.getQueryType();
|
||||
|
||||
if (queryType) {
|
||||
operationTypes.push(" query: ".concat(queryType.name));
|
||||
}
|
||||
|
||||
var mutationType = schema.getMutationType();
|
||||
|
||||
if (mutationType) {
|
||||
operationTypes.push(" mutation: ".concat(mutationType.name));
|
||||
}
|
||||
|
||||
var subscriptionType = schema.getSubscriptionType();
|
||||
|
||||
if (subscriptionType) {
|
||||
operationTypes.push(" subscription: ".concat(subscriptionType.name));
|
||||
}
|
||||
|
||||
return "schema {\n".concat(operationTypes.join('\n'), "\n}");
|
||||
}
|
||||
/**
|
||||
* GraphQL schema define root types for each type of operation. These types are
|
||||
* the same as any other type and can be named in any manner, however there is
|
||||
* a common naming convention:
|
||||
*
|
||||
* schema {
|
||||
* query: Query
|
||||
* mutation: Mutation
|
||||
* }
|
||||
*
|
||||
* When using this naming convention, the schema description can be omitted.
|
||||
*/
|
||||
|
||||
|
||||
function isSchemaOfCommonNames(schema) {
|
||||
var queryType = schema.getQueryType();
|
||||
|
||||
if (queryType && queryType.name !== 'Query') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var mutationType = schema.getMutationType();
|
||||
|
||||
if (mutationType && mutationType.name !== 'Mutation') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var subscriptionType = schema.getSubscriptionType();
|
||||
|
||||
if (subscriptionType && subscriptionType.name !== 'Subscription') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function printType(type, options) {
|
||||
if ((0, _definition.isScalarType)(type)) {
|
||||
return printScalar(type, options);
|
||||
} else if ((0, _definition.isObjectType)(type)) {
|
||||
return printObject(type, options);
|
||||
} else if ((0, _definition.isInterfaceType)(type)) {
|
||||
return printInterface(type, options);
|
||||
} else if ((0, _definition.isUnionType)(type)) {
|
||||
return printUnion(type, options);
|
||||
} else if ((0, _definition.isEnumType)(type)) {
|
||||
return printEnum(type, options);
|
||||
} else if ((0, _definition.isInputObjectType)(type)) {
|
||||
return printInputObject(type, options);
|
||||
} // Not reachable. All possible types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
(0, _invariant.default)(false, 'Unexpected type: ' + (0, _inspect.default)(type));
|
||||
}
|
||||
|
||||
function printScalar(type, options) {
|
||||
return printDescription(options, type) + "scalar ".concat(type.name);
|
||||
}
|
||||
|
||||
function printObject(type, options) {
|
||||
var interfaces = type.getInterfaces();
|
||||
var implementedInterfaces = interfaces.length ? ' implements ' + interfaces.map(function (i) {
|
||||
return i.name;
|
||||
}).join(' & ') : '';
|
||||
return printDescription(options, type) + "type ".concat(type.name).concat(implementedInterfaces) + printFields(options, type);
|
||||
}
|
||||
|
||||
function printInterface(type, options) {
|
||||
return printDescription(options, type) + "interface ".concat(type.name) + printFields(options, type);
|
||||
}
|
||||
|
||||
function printUnion(type, options) {
|
||||
var types = type.getTypes();
|
||||
var possibleTypes = types.length ? ' = ' + types.join(' | ') : '';
|
||||
return printDescription(options, type) + 'union ' + type.name + possibleTypes;
|
||||
}
|
||||
|
||||
function printEnum(type, options) {
|
||||
var values = type.getValues().map(function (value, i) {
|
||||
return printDescription(options, value, ' ', !i) + ' ' + value.name + printDeprecated(value);
|
||||
});
|
||||
return printDescription(options, type) + "enum ".concat(type.name) + printBlock(values);
|
||||
}
|
||||
|
||||
function printInputObject(type, options) {
|
||||
var fields = (0, _objectValues.default)(type.getFields()).map(function (f, i) {
|
||||
return printDescription(options, f, ' ', !i) + ' ' + printInputValue(f);
|
||||
});
|
||||
return printDescription(options, type) + "input ".concat(type.name) + printBlock(fields);
|
||||
}
|
||||
|
||||
function printFields(options, type) {
|
||||
var fields = (0, _objectValues.default)(type.getFields()).map(function (f, i) {
|
||||
return printDescription(options, f, ' ', !i) + ' ' + f.name + printArgs(options, f.args, ' ') + ': ' + String(f.type) + printDeprecated(f);
|
||||
});
|
||||
return printBlock(fields);
|
||||
}
|
||||
|
||||
function printBlock(items) {
|
||||
return items.length !== 0 ? ' {\n' + items.join('\n') + '\n}' : '';
|
||||
}
|
||||
|
||||
function printArgs(options, args) {
|
||||
var indentation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
||||
|
||||
if (args.length === 0) {
|
||||
return '';
|
||||
} // If every arg does not have a description, print them on one line.
|
||||
|
||||
|
||||
if (args.every(function (arg) {
|
||||
return !arg.description;
|
||||
})) {
|
||||
return '(' + args.map(printInputValue).join(', ') + ')';
|
||||
}
|
||||
|
||||
return '(\n' + args.map(function (arg, i) {
|
||||
return printDescription(options, arg, ' ' + indentation, !i) + ' ' + indentation + printInputValue(arg);
|
||||
}).join('\n') + '\n' + indentation + ')';
|
||||
}
|
||||
|
||||
function printInputValue(arg) {
|
||||
var defaultAST = (0, _astFromValue.astFromValue)(arg.defaultValue, arg.type);
|
||||
var argDecl = arg.name + ': ' + String(arg.type);
|
||||
|
||||
if (defaultAST) {
|
||||
argDecl += " = ".concat((0, _printer.print)(defaultAST));
|
||||
}
|
||||
|
||||
return argDecl;
|
||||
}
|
||||
|
||||
function printDirective(directive, options) {
|
||||
return printDescription(options, directive) + 'directive @' + directive.name + printArgs(options, directive.args) + (directive.isRepeatable ? ' repeatable' : '') + ' on ' + directive.locations.join(' | ');
|
||||
}
|
||||
|
||||
function printDeprecated(fieldOrEnumVal) {
|
||||
if (!fieldOrEnumVal.isDeprecated) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var reason = fieldOrEnumVal.deprecationReason;
|
||||
var reasonAST = (0, _astFromValue.astFromValue)(reason, _scalars.GraphQLString);
|
||||
|
||||
if (reasonAST && reason !== '' && reason !== _directives.DEFAULT_DEPRECATION_REASON) {
|
||||
return ' @deprecated(reason: ' + (0, _printer.print)(reasonAST) + ')';
|
||||
}
|
||||
|
||||
return ' @deprecated';
|
||||
}
|
||||
|
||||
function printDescription(options, def) {
|
||||
var indentation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
||||
var firstInBlock = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
||||
|
||||
if (!def.description) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var lines = descriptionLines(def.description, 120 - indentation.length);
|
||||
|
||||
if (options && options.commentDescriptions) {
|
||||
return printDescriptionWithComments(lines, indentation, firstInBlock);
|
||||
}
|
||||
|
||||
var text = lines.join('\n');
|
||||
var preferMultipleLines = text.length > 70;
|
||||
var blockString = (0, _blockString.printBlockString)(text, '', preferMultipleLines);
|
||||
var prefix = indentation && !firstInBlock ? '\n' + indentation : indentation;
|
||||
return prefix + blockString.replace(/\n/g, '\n' + indentation) + '\n';
|
||||
}
|
||||
|
||||
function printDescriptionWithComments(lines, indentation, firstInBlock) {
|
||||
var description = indentation && !firstInBlock ? '\n' : '';
|
||||
|
||||
for (var _i2 = 0; _i2 < lines.length; _i2++) {
|
||||
var line = lines[_i2];
|
||||
|
||||
if (line === '') {
|
||||
description += indentation + '#\n';
|
||||
} else {
|
||||
description += indentation + '# ' + line + '\n';
|
||||
}
|
||||
}
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
function descriptionLines(description, maxLen) {
|
||||
var rawLines = description.split('\n');
|
||||
return (0, _flatMap.default)(rawLines, function (line) {
|
||||
if (line.length < maxLen + 5) {
|
||||
return line;
|
||||
} // For > 120 character long lines, cut at space boundaries into sublines
|
||||
// of ~80 chars.
|
||||
|
||||
|
||||
return breakLine(line, maxLen);
|
||||
});
|
||||
}
|
||||
|
||||
function breakLine(line, maxLen) {
|
||||
var parts = line.split(new RegExp("((?: |^).{15,".concat(maxLen - 40, "}(?= |$))")));
|
||||
|
||||
if (parts.length < 4) {
|
||||
return [line];
|
||||
}
|
||||
|
||||
var sublines = [parts[0] + parts[1] + parts[2]];
|
||||
|
||||
for (var i = 3; i < parts.length; i += 2) {
|
||||
sublines.push(parts[i].slice(1) + parts[i + 1]);
|
||||
}
|
||||
|
||||
return sublines;
|
||||
}
|
||||
372
node_modules/graphql/utilities/schemaPrinter.js.flow
generated
vendored
Normal file
372
node_modules/graphql/utilities/schemaPrinter.js.flow
generated
vendored
Normal file
@@ -0,0 +1,372 @@
|
||||
// @flow strict
|
||||
|
||||
import flatMap from '../polyfills/flatMap';
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
|
||||
import { print } from '../language/printer';
|
||||
import { printBlockString } from '../language/blockString';
|
||||
|
||||
import { type GraphQLSchema } from '../type/schema';
|
||||
import { isIntrospectionType } from '../type/introspection';
|
||||
import { GraphQLString, isSpecifiedScalarType } from '../type/scalars';
|
||||
import {
|
||||
GraphQLDirective,
|
||||
DEFAULT_DEPRECATION_REASON,
|
||||
isSpecifiedDirective,
|
||||
} from '../type/directives';
|
||||
import {
|
||||
type GraphQLNamedType,
|
||||
type GraphQLScalarType,
|
||||
type GraphQLEnumType,
|
||||
type GraphQLObjectType,
|
||||
type GraphQLInterfaceType,
|
||||
type GraphQLUnionType,
|
||||
type GraphQLInputObjectType,
|
||||
isScalarType,
|
||||
isObjectType,
|
||||
isInterfaceType,
|
||||
isUnionType,
|
||||
isEnumType,
|
||||
isInputObjectType,
|
||||
} from '../type/definition';
|
||||
|
||||
import { astFromValue } from '../utilities/astFromValue';
|
||||
|
||||
type Options = {|
|
||||
/**
|
||||
* Descriptions are defined as preceding string literals, however an older
|
||||
* experimental version of the SDL supported preceding comments as
|
||||
* descriptions. Set to true to enable this deprecated behavior.
|
||||
* This option is provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
commentDescriptions?: boolean,
|
||||
|};
|
||||
|
||||
/**
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function printSchema(schema: GraphQLSchema, options?: Options): string {
|
||||
return printFilteredSchema(
|
||||
schema,
|
||||
n => !isSpecifiedDirective(n),
|
||||
isDefinedType,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
export function printIntrospectionSchema(
|
||||
schema: GraphQLSchema,
|
||||
options?: Options,
|
||||
): string {
|
||||
return printFilteredSchema(
|
||||
schema,
|
||||
isSpecifiedDirective,
|
||||
isIntrospectionType,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
function isDefinedType(type: GraphQLNamedType): boolean {
|
||||
return !isSpecifiedScalarType(type) && !isIntrospectionType(type);
|
||||
}
|
||||
|
||||
function printFilteredSchema(
|
||||
schema: GraphQLSchema,
|
||||
directiveFilter: (type: GraphQLDirective) => boolean,
|
||||
typeFilter: (type: GraphQLNamedType) => boolean,
|
||||
options,
|
||||
): string {
|
||||
const directives = schema.getDirectives().filter(directiveFilter);
|
||||
const typeMap = schema.getTypeMap();
|
||||
const types = objectValues(typeMap)
|
||||
.sort((type1, type2) => type1.name.localeCompare(type2.name))
|
||||
.filter(typeFilter);
|
||||
|
||||
return (
|
||||
[printSchemaDefinition(schema)]
|
||||
.concat(
|
||||
directives.map(directive => printDirective(directive, options)),
|
||||
types.map(type => printType(type, options)),
|
||||
)
|
||||
.filter(Boolean)
|
||||
.join('\n\n') + '\n'
|
||||
);
|
||||
}
|
||||
|
||||
function printSchemaDefinition(schema: GraphQLSchema): ?string {
|
||||
if (isSchemaOfCommonNames(schema)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const operationTypes = [];
|
||||
|
||||
const queryType = schema.getQueryType();
|
||||
if (queryType) {
|
||||
operationTypes.push(` query: ${queryType.name}`);
|
||||
}
|
||||
|
||||
const mutationType = schema.getMutationType();
|
||||
if (mutationType) {
|
||||
operationTypes.push(` mutation: ${mutationType.name}`);
|
||||
}
|
||||
|
||||
const subscriptionType = schema.getSubscriptionType();
|
||||
if (subscriptionType) {
|
||||
operationTypes.push(` subscription: ${subscriptionType.name}`);
|
||||
}
|
||||
|
||||
return `schema {\n${operationTypes.join('\n')}\n}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* GraphQL schema define root types for each type of operation. These types are
|
||||
* the same as any other type and can be named in any manner, however there is
|
||||
* a common naming convention:
|
||||
*
|
||||
* schema {
|
||||
* query: Query
|
||||
* mutation: Mutation
|
||||
* }
|
||||
*
|
||||
* When using this naming convention, the schema description can be omitted.
|
||||
*/
|
||||
function isSchemaOfCommonNames(schema: GraphQLSchema): boolean {
|
||||
const queryType = schema.getQueryType();
|
||||
if (queryType && queryType.name !== 'Query') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const mutationType = schema.getMutationType();
|
||||
if (mutationType && mutationType.name !== 'Mutation') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const subscriptionType = schema.getSubscriptionType();
|
||||
if (subscriptionType && subscriptionType.name !== 'Subscription') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function printType(type: GraphQLNamedType, options?: Options): string {
|
||||
if (isScalarType(type)) {
|
||||
return printScalar(type, options);
|
||||
} else if (isObjectType(type)) {
|
||||
return printObject(type, options);
|
||||
} else if (isInterfaceType(type)) {
|
||||
return printInterface(type, options);
|
||||
} else if (isUnionType(type)) {
|
||||
return printUnion(type, options);
|
||||
} else if (isEnumType(type)) {
|
||||
return printEnum(type, options);
|
||||
} else if (isInputObjectType(type)) {
|
||||
return printInputObject(type, options);
|
||||
}
|
||||
|
||||
// Not reachable. All possible types have been considered.
|
||||
invariant(false, 'Unexpected type: ' + inspect((type: empty)));
|
||||
}
|
||||
|
||||
function printScalar(type: GraphQLScalarType, options): string {
|
||||
return printDescription(options, type) + `scalar ${type.name}`;
|
||||
}
|
||||
|
||||
function printObject(type: GraphQLObjectType, options): string {
|
||||
const interfaces = type.getInterfaces();
|
||||
const implementedInterfaces = interfaces.length
|
||||
? ' implements ' + interfaces.map(i => i.name).join(' & ')
|
||||
: '';
|
||||
return (
|
||||
printDescription(options, type) +
|
||||
`type ${type.name}${implementedInterfaces}` +
|
||||
printFields(options, type)
|
||||
);
|
||||
}
|
||||
|
||||
function printInterface(type: GraphQLInterfaceType, options): string {
|
||||
return (
|
||||
printDescription(options, type) +
|
||||
`interface ${type.name}` +
|
||||
printFields(options, type)
|
||||
);
|
||||
}
|
||||
|
||||
function printUnion(type: GraphQLUnionType, options): string {
|
||||
const types = type.getTypes();
|
||||
const possibleTypes = types.length ? ' = ' + types.join(' | ') : '';
|
||||
return printDescription(options, type) + 'union ' + type.name + possibleTypes;
|
||||
}
|
||||
|
||||
function printEnum(type: GraphQLEnumType, options): string {
|
||||
const values = type
|
||||
.getValues()
|
||||
.map(
|
||||
(value, i) =>
|
||||
printDescription(options, value, ' ', !i) +
|
||||
' ' +
|
||||
value.name +
|
||||
printDeprecated(value),
|
||||
);
|
||||
|
||||
return (
|
||||
printDescription(options, type) + `enum ${type.name}` + printBlock(values)
|
||||
);
|
||||
}
|
||||
|
||||
function printInputObject(type: GraphQLInputObjectType, options): string {
|
||||
const fields = objectValues(type.getFields()).map(
|
||||
(f, i) =>
|
||||
printDescription(options, f, ' ', !i) + ' ' + printInputValue(f),
|
||||
);
|
||||
return (
|
||||
printDescription(options, type) + `input ${type.name}` + printBlock(fields)
|
||||
);
|
||||
}
|
||||
|
||||
function printFields(options, type) {
|
||||
const fields = objectValues(type.getFields()).map(
|
||||
(f, i) =>
|
||||
printDescription(options, f, ' ', !i) +
|
||||
' ' +
|
||||
f.name +
|
||||
printArgs(options, f.args, ' ') +
|
||||
': ' +
|
||||
String(f.type) +
|
||||
printDeprecated(f),
|
||||
);
|
||||
return printBlock(fields);
|
||||
}
|
||||
|
||||
function printBlock(items) {
|
||||
return items.length !== 0 ? ' {\n' + items.join('\n') + '\n}' : '';
|
||||
}
|
||||
|
||||
function printArgs(options, args, indentation = '') {
|
||||
if (args.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// If every arg does not have a description, print them on one line.
|
||||
if (args.every(arg => !arg.description)) {
|
||||
return '(' + args.map(printInputValue).join(', ') + ')';
|
||||
}
|
||||
|
||||
return (
|
||||
'(\n' +
|
||||
args
|
||||
.map(
|
||||
(arg, i) =>
|
||||
printDescription(options, arg, ' ' + indentation, !i) +
|
||||
' ' +
|
||||
indentation +
|
||||
printInputValue(arg),
|
||||
)
|
||||
.join('\n') +
|
||||
'\n' +
|
||||
indentation +
|
||||
')'
|
||||
);
|
||||
}
|
||||
|
||||
function printInputValue(arg) {
|
||||
const defaultAST = astFromValue(arg.defaultValue, arg.type);
|
||||
let argDecl = arg.name + ': ' + String(arg.type);
|
||||
if (defaultAST) {
|
||||
argDecl += ` = ${print(defaultAST)}`;
|
||||
}
|
||||
return argDecl;
|
||||
}
|
||||
|
||||
function printDirective(directive, options) {
|
||||
return (
|
||||
printDescription(options, directive) +
|
||||
'directive @' +
|
||||
directive.name +
|
||||
printArgs(options, directive.args) +
|
||||
(directive.isRepeatable ? ' repeatable' : '') +
|
||||
' on ' +
|
||||
directive.locations.join(' | ')
|
||||
);
|
||||
}
|
||||
|
||||
function printDeprecated(fieldOrEnumVal) {
|
||||
if (!fieldOrEnumVal.isDeprecated) {
|
||||
return '';
|
||||
}
|
||||
const reason = fieldOrEnumVal.deprecationReason;
|
||||
const reasonAST = astFromValue(reason, GraphQLString);
|
||||
if (reasonAST && reason !== '' && reason !== DEFAULT_DEPRECATION_REASON) {
|
||||
return ' @deprecated(reason: ' + print(reasonAST) + ')';
|
||||
}
|
||||
return ' @deprecated';
|
||||
}
|
||||
|
||||
function printDescription(
|
||||
options,
|
||||
def,
|
||||
indentation = '',
|
||||
firstInBlock = true,
|
||||
): string {
|
||||
if (!def.description) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const lines = descriptionLines(def.description, 120 - indentation.length);
|
||||
if (options && options.commentDescriptions) {
|
||||
return printDescriptionWithComments(lines, indentation, firstInBlock);
|
||||
}
|
||||
|
||||
const text = lines.join('\n');
|
||||
const preferMultipleLines = text.length > 70;
|
||||
const blockString = printBlockString(text, '', preferMultipleLines);
|
||||
const prefix =
|
||||
indentation && !firstInBlock ? '\n' + indentation : indentation;
|
||||
|
||||
return prefix + blockString.replace(/\n/g, '\n' + indentation) + '\n';
|
||||
}
|
||||
|
||||
function printDescriptionWithComments(lines, indentation, firstInBlock) {
|
||||
let description = indentation && !firstInBlock ? '\n' : '';
|
||||
for (const line of lines) {
|
||||
if (line === '') {
|
||||
description += indentation + '#\n';
|
||||
} else {
|
||||
description += indentation + '# ' + line + '\n';
|
||||
}
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
function descriptionLines(description: string, maxLen: number): Array<string> {
|
||||
const rawLines = description.split('\n');
|
||||
return flatMap(rawLines, line => {
|
||||
if (line.length < maxLen + 5) {
|
||||
return line;
|
||||
}
|
||||
// For > 120 character long lines, cut at space boundaries into sublines
|
||||
// of ~80 chars.
|
||||
return breakLine(line, maxLen);
|
||||
});
|
||||
}
|
||||
|
||||
function breakLine(line: string, maxLen: number): Array<string> {
|
||||
const parts = line.split(new RegExp(`((?: |^).{15,${maxLen - 40}}(?= |$))`));
|
||||
if (parts.length < 4) {
|
||||
return [line];
|
||||
}
|
||||
const sublines = [parts[0] + parts[1] + parts[2]];
|
||||
for (let i = 3; i < parts.length; i += 2) {
|
||||
sublines.push(parts[i].slice(1) + parts[i + 1]);
|
||||
}
|
||||
return sublines;
|
||||
}
|
||||
288
node_modules/graphql/utilities/schemaPrinter.mjs
generated
vendored
Normal file
288
node_modules/graphql/utilities/schemaPrinter.mjs
generated
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
import flatMap from '../polyfills/flatMap';
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import { print } from '../language/printer';
|
||||
import { printBlockString } from '../language/blockString';
|
||||
import { isIntrospectionType } from '../type/introspection';
|
||||
import { GraphQLString, isSpecifiedScalarType } from '../type/scalars';
|
||||
import { GraphQLDirective, DEFAULT_DEPRECATION_REASON, isSpecifiedDirective } from '../type/directives';
|
||||
import { isScalarType, isObjectType, isInterfaceType, isUnionType, isEnumType, isInputObjectType } from '../type/definition';
|
||||
import { astFromValue } from '../utilities/astFromValue';
|
||||
|
||||
/**
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
*/
|
||||
export function printSchema(schema, options) {
|
||||
return printFilteredSchema(schema, function (n) {
|
||||
return !isSpecifiedDirective(n);
|
||||
}, isDefinedType, options);
|
||||
}
|
||||
export function printIntrospectionSchema(schema, options) {
|
||||
return printFilteredSchema(schema, isSpecifiedDirective, isIntrospectionType, options);
|
||||
}
|
||||
|
||||
function isDefinedType(type) {
|
||||
return !isSpecifiedScalarType(type) && !isIntrospectionType(type);
|
||||
}
|
||||
|
||||
function printFilteredSchema(schema, directiveFilter, typeFilter, options) {
|
||||
var directives = schema.getDirectives().filter(directiveFilter);
|
||||
var typeMap = schema.getTypeMap();
|
||||
var types = objectValues(typeMap).sort(function (type1, type2) {
|
||||
return type1.name.localeCompare(type2.name);
|
||||
}).filter(typeFilter);
|
||||
return [printSchemaDefinition(schema)].concat(directives.map(function (directive) {
|
||||
return printDirective(directive, options);
|
||||
}), types.map(function (type) {
|
||||
return printType(type, options);
|
||||
})).filter(Boolean).join('\n\n') + '\n';
|
||||
}
|
||||
|
||||
function printSchemaDefinition(schema) {
|
||||
if (isSchemaOfCommonNames(schema)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var operationTypes = [];
|
||||
var queryType = schema.getQueryType();
|
||||
|
||||
if (queryType) {
|
||||
operationTypes.push(" query: ".concat(queryType.name));
|
||||
}
|
||||
|
||||
var mutationType = schema.getMutationType();
|
||||
|
||||
if (mutationType) {
|
||||
operationTypes.push(" mutation: ".concat(mutationType.name));
|
||||
}
|
||||
|
||||
var subscriptionType = schema.getSubscriptionType();
|
||||
|
||||
if (subscriptionType) {
|
||||
operationTypes.push(" subscription: ".concat(subscriptionType.name));
|
||||
}
|
||||
|
||||
return "schema {\n".concat(operationTypes.join('\n'), "\n}");
|
||||
}
|
||||
/**
|
||||
* GraphQL schema define root types for each type of operation. These types are
|
||||
* the same as any other type and can be named in any manner, however there is
|
||||
* a common naming convention:
|
||||
*
|
||||
* schema {
|
||||
* query: Query
|
||||
* mutation: Mutation
|
||||
* }
|
||||
*
|
||||
* When using this naming convention, the schema description can be omitted.
|
||||
*/
|
||||
|
||||
|
||||
function isSchemaOfCommonNames(schema) {
|
||||
var queryType = schema.getQueryType();
|
||||
|
||||
if (queryType && queryType.name !== 'Query') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var mutationType = schema.getMutationType();
|
||||
|
||||
if (mutationType && mutationType.name !== 'Mutation') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var subscriptionType = schema.getSubscriptionType();
|
||||
|
||||
if (subscriptionType && subscriptionType.name !== 'Subscription') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function printType(type, options) {
|
||||
if (isScalarType(type)) {
|
||||
return printScalar(type, options);
|
||||
} else if (isObjectType(type)) {
|
||||
return printObject(type, options);
|
||||
} else if (isInterfaceType(type)) {
|
||||
return printInterface(type, options);
|
||||
} else if (isUnionType(type)) {
|
||||
return printUnion(type, options);
|
||||
} else if (isEnumType(type)) {
|
||||
return printEnum(type, options);
|
||||
} else if (isInputObjectType(type)) {
|
||||
return printInputObject(type, options);
|
||||
} // Not reachable. All possible types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
invariant(false, 'Unexpected type: ' + inspect(type));
|
||||
}
|
||||
|
||||
function printScalar(type, options) {
|
||||
return printDescription(options, type) + "scalar ".concat(type.name);
|
||||
}
|
||||
|
||||
function printObject(type, options) {
|
||||
var interfaces = type.getInterfaces();
|
||||
var implementedInterfaces = interfaces.length ? ' implements ' + interfaces.map(function (i) {
|
||||
return i.name;
|
||||
}).join(' & ') : '';
|
||||
return printDescription(options, type) + "type ".concat(type.name).concat(implementedInterfaces) + printFields(options, type);
|
||||
}
|
||||
|
||||
function printInterface(type, options) {
|
||||
return printDescription(options, type) + "interface ".concat(type.name) + printFields(options, type);
|
||||
}
|
||||
|
||||
function printUnion(type, options) {
|
||||
var types = type.getTypes();
|
||||
var possibleTypes = types.length ? ' = ' + types.join(' | ') : '';
|
||||
return printDescription(options, type) + 'union ' + type.name + possibleTypes;
|
||||
}
|
||||
|
||||
function printEnum(type, options) {
|
||||
var values = type.getValues().map(function (value, i) {
|
||||
return printDescription(options, value, ' ', !i) + ' ' + value.name + printDeprecated(value);
|
||||
});
|
||||
return printDescription(options, type) + "enum ".concat(type.name) + printBlock(values);
|
||||
}
|
||||
|
||||
function printInputObject(type, options) {
|
||||
var fields = objectValues(type.getFields()).map(function (f, i) {
|
||||
return printDescription(options, f, ' ', !i) + ' ' + printInputValue(f);
|
||||
});
|
||||
return printDescription(options, type) + "input ".concat(type.name) + printBlock(fields);
|
||||
}
|
||||
|
||||
function printFields(options, type) {
|
||||
var fields = objectValues(type.getFields()).map(function (f, i) {
|
||||
return printDescription(options, f, ' ', !i) + ' ' + f.name + printArgs(options, f.args, ' ') + ': ' + String(f.type) + printDeprecated(f);
|
||||
});
|
||||
return printBlock(fields);
|
||||
}
|
||||
|
||||
function printBlock(items) {
|
||||
return items.length !== 0 ? ' {\n' + items.join('\n') + '\n}' : '';
|
||||
}
|
||||
|
||||
function printArgs(options, args) {
|
||||
var indentation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
||||
|
||||
if (args.length === 0) {
|
||||
return '';
|
||||
} // If every arg does not have a description, print them on one line.
|
||||
|
||||
|
||||
if (args.every(function (arg) {
|
||||
return !arg.description;
|
||||
})) {
|
||||
return '(' + args.map(printInputValue).join(', ') + ')';
|
||||
}
|
||||
|
||||
return '(\n' + args.map(function (arg, i) {
|
||||
return printDescription(options, arg, ' ' + indentation, !i) + ' ' + indentation + printInputValue(arg);
|
||||
}).join('\n') + '\n' + indentation + ')';
|
||||
}
|
||||
|
||||
function printInputValue(arg) {
|
||||
var defaultAST = astFromValue(arg.defaultValue, arg.type);
|
||||
var argDecl = arg.name + ': ' + String(arg.type);
|
||||
|
||||
if (defaultAST) {
|
||||
argDecl += " = ".concat(print(defaultAST));
|
||||
}
|
||||
|
||||
return argDecl;
|
||||
}
|
||||
|
||||
function printDirective(directive, options) {
|
||||
return printDescription(options, directive) + 'directive @' + directive.name + printArgs(options, directive.args) + (directive.isRepeatable ? ' repeatable' : '') + ' on ' + directive.locations.join(' | ');
|
||||
}
|
||||
|
||||
function printDeprecated(fieldOrEnumVal) {
|
||||
if (!fieldOrEnumVal.isDeprecated) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var reason = fieldOrEnumVal.deprecationReason;
|
||||
var reasonAST = astFromValue(reason, GraphQLString);
|
||||
|
||||
if (reasonAST && reason !== '' && reason !== DEFAULT_DEPRECATION_REASON) {
|
||||
return ' @deprecated(reason: ' + print(reasonAST) + ')';
|
||||
}
|
||||
|
||||
return ' @deprecated';
|
||||
}
|
||||
|
||||
function printDescription(options, def) {
|
||||
var indentation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
||||
var firstInBlock = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
||||
|
||||
if (!def.description) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var lines = descriptionLines(def.description, 120 - indentation.length);
|
||||
|
||||
if (options && options.commentDescriptions) {
|
||||
return printDescriptionWithComments(lines, indentation, firstInBlock);
|
||||
}
|
||||
|
||||
var text = lines.join('\n');
|
||||
var preferMultipleLines = text.length > 70;
|
||||
var blockString = printBlockString(text, '', preferMultipleLines);
|
||||
var prefix = indentation && !firstInBlock ? '\n' + indentation : indentation;
|
||||
return prefix + blockString.replace(/\n/g, '\n' + indentation) + '\n';
|
||||
}
|
||||
|
||||
function printDescriptionWithComments(lines, indentation, firstInBlock) {
|
||||
var description = indentation && !firstInBlock ? '\n' : '';
|
||||
|
||||
for (var _i2 = 0; _i2 < lines.length; _i2++) {
|
||||
var line = lines[_i2];
|
||||
|
||||
if (line === '') {
|
||||
description += indentation + '#\n';
|
||||
} else {
|
||||
description += indentation + '# ' + line + '\n';
|
||||
}
|
||||
}
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
function descriptionLines(description, maxLen) {
|
||||
var rawLines = description.split('\n');
|
||||
return flatMap(rawLines, function (line) {
|
||||
if (line.length < maxLen + 5) {
|
||||
return line;
|
||||
} // For > 120 character long lines, cut at space boundaries into sublines
|
||||
// of ~80 chars.
|
||||
|
||||
|
||||
return breakLine(line, maxLen);
|
||||
});
|
||||
}
|
||||
|
||||
function breakLine(line, maxLen) {
|
||||
var parts = line.split(new RegExp("((?: |^).{15,".concat(maxLen - 40, "}(?= |$))")));
|
||||
|
||||
if (parts.length < 4) {
|
||||
return [line];
|
||||
}
|
||||
|
||||
var sublines = [parts[0] + parts[1] + parts[2]];
|
||||
|
||||
for (var i = 3; i < parts.length; i += 2) {
|
||||
sublines.push(parts[i].slice(1) + parts[i + 1]);
|
||||
}
|
||||
|
||||
return sublines;
|
||||
}
|
||||
11
node_modules/graphql/utilities/separateOperations.d.ts
generated
vendored
Normal file
11
node_modules/graphql/utilities/separateOperations.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { DocumentNode } from '../language/ast';
|
||||
|
||||
/**
|
||||
* separateOperations accepts a single AST document which may contain many
|
||||
* operations and fragments and returns a collection of AST documents each of
|
||||
* which contains a single operation as well the fragment definitions it
|
||||
* refers to.
|
||||
*/
|
||||
export function separateOperations(
|
||||
documentAST: DocumentNode,
|
||||
): { [key: string]: DocumentNode };
|
||||
90
node_modules/graphql/utilities/separateOperations.js
generated
vendored
Normal file
90
node_modules/graphql/utilities/separateOperations.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.separateOperations = separateOperations;
|
||||
|
||||
var _visitor = require("../language/visitor");
|
||||
|
||||
/**
|
||||
* separateOperations accepts a single AST document which may contain many
|
||||
* operations and fragments and returns a collection of AST documents each of
|
||||
* which contains a single operation as well the fragment definitions it
|
||||
* refers to.
|
||||
*/
|
||||
function separateOperations(documentAST) {
|
||||
var operations = [];
|
||||
var fragments = Object.create(null);
|
||||
var positions = new Map();
|
||||
var depGraph = Object.create(null);
|
||||
var fromName;
|
||||
var idx = 0; // Populate metadata and build a dependency graph.
|
||||
|
||||
(0, _visitor.visit)(documentAST, {
|
||||
OperationDefinition: function OperationDefinition(node) {
|
||||
fromName = opName(node);
|
||||
operations.push(node);
|
||||
positions.set(node, idx++);
|
||||
},
|
||||
FragmentDefinition: function FragmentDefinition(node) {
|
||||
fromName = node.name.value;
|
||||
fragments[fromName] = node;
|
||||
positions.set(node, idx++);
|
||||
},
|
||||
FragmentSpread: function FragmentSpread(node) {
|
||||
var toName = node.name.value;
|
||||
(depGraph[fromName] || (depGraph[fromName] = Object.create(null)))[toName] = true;
|
||||
}
|
||||
}); // For each operation, produce a new synthesized AST which includes only what
|
||||
// is necessary for completing that operation.
|
||||
|
||||
var separatedDocumentASTs = Object.create(null);
|
||||
|
||||
for (var _i2 = 0; _i2 < operations.length; _i2++) {
|
||||
var operation = operations[_i2];
|
||||
var operationName = opName(operation);
|
||||
var dependencies = Object.create(null);
|
||||
collectTransitiveDependencies(dependencies, depGraph, operationName); // The list of definition nodes to be included for this operation, sorted
|
||||
// to retain the same order as the original document.
|
||||
|
||||
var definitions = [operation];
|
||||
|
||||
for (var _i4 = 0, _Object$keys2 = Object.keys(dependencies); _i4 < _Object$keys2.length; _i4++) {
|
||||
var name = _Object$keys2[_i4];
|
||||
definitions.push(fragments[name]);
|
||||
}
|
||||
|
||||
definitions.sort(function (n1, n2) {
|
||||
return (positions.get(n1) || 0) - (positions.get(n2) || 0);
|
||||
});
|
||||
separatedDocumentASTs[operationName] = {
|
||||
kind: 'Document',
|
||||
definitions: definitions
|
||||
};
|
||||
}
|
||||
|
||||
return separatedDocumentASTs;
|
||||
}
|
||||
|
||||
// Provides the empty string for anonymous operations.
|
||||
function opName(operation) {
|
||||
return operation.name ? operation.name.value : '';
|
||||
} // From a dependency graph, collects a list of transitive dependencies by
|
||||
// recursing through a dependency graph.
|
||||
|
||||
|
||||
function collectTransitiveDependencies(collected, depGraph, fromName) {
|
||||
var immediateDeps = depGraph[fromName];
|
||||
|
||||
if (immediateDeps) {
|
||||
for (var _i6 = 0, _Object$keys4 = Object.keys(immediateDeps); _i6 < _Object$keys4.length; _i6++) {
|
||||
var toName = _Object$keys4[_i6];
|
||||
|
||||
if (!collected[toName]) {
|
||||
collected[toName] = true;
|
||||
collectTransitiveDependencies(collected, depGraph, toName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
97
node_modules/graphql/utilities/separateOperations.js.flow
generated
vendored
Normal file
97
node_modules/graphql/utilities/separateOperations.js.flow
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
// @flow strict
|
||||
|
||||
import { type ObjMap } from '../jsutils/ObjMap';
|
||||
|
||||
import { visit } from '../language/visitor';
|
||||
import {
|
||||
type DocumentNode,
|
||||
type OperationDefinitionNode,
|
||||
} from '../language/ast';
|
||||
|
||||
/**
|
||||
* separateOperations accepts a single AST document which may contain many
|
||||
* operations and fragments and returns a collection of AST documents each of
|
||||
* which contains a single operation as well the fragment definitions it
|
||||
* refers to.
|
||||
*/
|
||||
export function separateOperations(
|
||||
documentAST: DocumentNode,
|
||||
): ObjMap<DocumentNode> {
|
||||
const operations = [];
|
||||
const fragments = Object.create(null);
|
||||
const positions = new Map();
|
||||
const depGraph: DepGraph = Object.create(null);
|
||||
let fromName;
|
||||
let idx = 0;
|
||||
|
||||
// Populate metadata and build a dependency graph.
|
||||
visit(documentAST, {
|
||||
OperationDefinition(node) {
|
||||
fromName = opName(node);
|
||||
operations.push(node);
|
||||
positions.set(node, idx++);
|
||||
},
|
||||
FragmentDefinition(node) {
|
||||
fromName = node.name.value;
|
||||
fragments[fromName] = node;
|
||||
positions.set(node, idx++);
|
||||
},
|
||||
FragmentSpread(node) {
|
||||
const toName = node.name.value;
|
||||
(depGraph[fromName] || (depGraph[fromName] = Object.create(null)))[
|
||||
toName
|
||||
] = true;
|
||||
},
|
||||
});
|
||||
|
||||
// For each operation, produce a new synthesized AST which includes only what
|
||||
// is necessary for completing that operation.
|
||||
const separatedDocumentASTs = Object.create(null);
|
||||
for (const operation of operations) {
|
||||
const operationName = opName(operation);
|
||||
const dependencies = Object.create(null);
|
||||
collectTransitiveDependencies(dependencies, depGraph, operationName);
|
||||
|
||||
// The list of definition nodes to be included for this operation, sorted
|
||||
// to retain the same order as the original document.
|
||||
const definitions = [operation];
|
||||
for (const name of Object.keys(dependencies)) {
|
||||
definitions.push(fragments[name]);
|
||||
}
|
||||
definitions.sort(
|
||||
(n1, n2) => (positions.get(n1) || 0) - (positions.get(n2) || 0),
|
||||
);
|
||||
|
||||
separatedDocumentASTs[operationName] = {
|
||||
kind: 'Document',
|
||||
definitions,
|
||||
};
|
||||
}
|
||||
|
||||
return separatedDocumentASTs;
|
||||
}
|
||||
|
||||
type DepGraph = ObjMap<ObjMap<boolean>>;
|
||||
|
||||
// Provides the empty string for anonymous operations.
|
||||
function opName(operation: OperationDefinitionNode): string {
|
||||
return operation.name ? operation.name.value : '';
|
||||
}
|
||||
|
||||
// From a dependency graph, collects a list of transitive dependencies by
|
||||
// recursing through a dependency graph.
|
||||
function collectTransitiveDependencies(
|
||||
collected: ObjMap<boolean>,
|
||||
depGraph: DepGraph,
|
||||
fromName: string,
|
||||
): void {
|
||||
const immediateDeps = depGraph[fromName];
|
||||
if (immediateDeps) {
|
||||
for (const toName of Object.keys(immediateDeps)) {
|
||||
if (!collected[toName]) {
|
||||
collected[toName] = true;
|
||||
collectTransitiveDependencies(collected, depGraph, toName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
83
node_modules/graphql/utilities/separateOperations.mjs
generated
vendored
Normal file
83
node_modules/graphql/utilities/separateOperations.mjs
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
import { visit } from '../language/visitor';
|
||||
|
||||
/**
|
||||
* separateOperations accepts a single AST document which may contain many
|
||||
* operations and fragments and returns a collection of AST documents each of
|
||||
* which contains a single operation as well the fragment definitions it
|
||||
* refers to.
|
||||
*/
|
||||
export function separateOperations(documentAST) {
|
||||
var operations = [];
|
||||
var fragments = Object.create(null);
|
||||
var positions = new Map();
|
||||
var depGraph = Object.create(null);
|
||||
var fromName;
|
||||
var idx = 0; // Populate metadata and build a dependency graph.
|
||||
|
||||
visit(documentAST, {
|
||||
OperationDefinition: function OperationDefinition(node) {
|
||||
fromName = opName(node);
|
||||
operations.push(node);
|
||||
positions.set(node, idx++);
|
||||
},
|
||||
FragmentDefinition: function FragmentDefinition(node) {
|
||||
fromName = node.name.value;
|
||||
fragments[fromName] = node;
|
||||
positions.set(node, idx++);
|
||||
},
|
||||
FragmentSpread: function FragmentSpread(node) {
|
||||
var toName = node.name.value;
|
||||
(depGraph[fromName] || (depGraph[fromName] = Object.create(null)))[toName] = true;
|
||||
}
|
||||
}); // For each operation, produce a new synthesized AST which includes only what
|
||||
// is necessary for completing that operation.
|
||||
|
||||
var separatedDocumentASTs = Object.create(null);
|
||||
|
||||
for (var _i2 = 0; _i2 < operations.length; _i2++) {
|
||||
var operation = operations[_i2];
|
||||
var operationName = opName(operation);
|
||||
var dependencies = Object.create(null);
|
||||
collectTransitiveDependencies(dependencies, depGraph, operationName); // The list of definition nodes to be included for this operation, sorted
|
||||
// to retain the same order as the original document.
|
||||
|
||||
var definitions = [operation];
|
||||
|
||||
for (var _i4 = 0, _Object$keys2 = Object.keys(dependencies); _i4 < _Object$keys2.length; _i4++) {
|
||||
var name = _Object$keys2[_i4];
|
||||
definitions.push(fragments[name]);
|
||||
}
|
||||
|
||||
definitions.sort(function (n1, n2) {
|
||||
return (positions.get(n1) || 0) - (positions.get(n2) || 0);
|
||||
});
|
||||
separatedDocumentASTs[operationName] = {
|
||||
kind: 'Document',
|
||||
definitions: definitions
|
||||
};
|
||||
}
|
||||
|
||||
return separatedDocumentASTs;
|
||||
}
|
||||
|
||||
// Provides the empty string for anonymous operations.
|
||||
function opName(operation) {
|
||||
return operation.name ? operation.name.value : '';
|
||||
} // From a dependency graph, collects a list of transitive dependencies by
|
||||
// recursing through a dependency graph.
|
||||
|
||||
|
||||
function collectTransitiveDependencies(collected, depGraph, fromName) {
|
||||
var immediateDeps = depGraph[fromName];
|
||||
|
||||
if (immediateDeps) {
|
||||
for (var _i6 = 0, _Object$keys4 = Object.keys(immediateDeps); _i6 < _Object$keys4.length; _i6++) {
|
||||
var toName = _Object$keys4[_i6];
|
||||
|
||||
if (!collected[toName]) {
|
||||
collected[toName] = true;
|
||||
collectTransitiveDependencies(collected, depGraph, toName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
node_modules/graphql/utilities/stripIgnoredCharacters.d.ts
generated
vendored
Normal file
55
node_modules/graphql/utilities/stripIgnoredCharacters.d.ts
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import { Source } from '../language/source';
|
||||
|
||||
/**
|
||||
* Strips characters that are not significant to the validity or execution
|
||||
* of a GraphQL document:
|
||||
* - UnicodeBOM
|
||||
* - WhiteSpace
|
||||
* - LineTerminator
|
||||
* - Comment
|
||||
* - Comma
|
||||
* - BlockString indentation
|
||||
*
|
||||
* Note: It is required to have a delimiter character between neighboring
|
||||
* non-punctuator tokens and this function always uses single space as delimiter.
|
||||
*
|
||||
* It is guaranteed that both input and output documents if parsed would result
|
||||
* in the exact same AST except for nodes location.
|
||||
*
|
||||
* Warning: It is guaranteed that this function will always produce stable results.
|
||||
* However, it's not guaranteed that it will stay the same between different
|
||||
* releases due to bugfixes or changes in the GraphQL specification.
|
||||
*
|
||||
* Query example:
|
||||
*
|
||||
* query SomeQuery($foo: String!, $bar: String) {
|
||||
* someField(foo: $foo, bar: $bar) {
|
||||
* a
|
||||
* b {
|
||||
* c
|
||||
* d
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Becomes:
|
||||
*
|
||||
* query SomeQuery($foo:String!$bar:String){someField(foo:$foo bar:$bar){a b{c d}}}
|
||||
*
|
||||
* SDL example:
|
||||
*
|
||||
* """
|
||||
* Type description
|
||||
* """
|
||||
* type Foo {
|
||||
* """
|
||||
* Field description
|
||||
* """
|
||||
* bar: String
|
||||
* }
|
||||
*
|
||||
* Becomes:
|
||||
*
|
||||
* """Type description""" type Foo{"""Field description""" bar:String}
|
||||
*/
|
||||
export function stripIgnoredCharacters(source: string | Source): string;
|
||||
133
node_modules/graphql/utilities/stripIgnoredCharacters.js
generated
vendored
Normal file
133
node_modules/graphql/utilities/stripIgnoredCharacters.js
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.stripIgnoredCharacters = stripIgnoredCharacters;
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _source = require("../language/source");
|
||||
|
||||
var _tokenKind = require("../language/tokenKind");
|
||||
|
||||
var _lexer = require("../language/lexer");
|
||||
|
||||
var _blockString = require("../language/blockString");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Strips characters that are not significant to the validity or execution
|
||||
* of a GraphQL document:
|
||||
* - UnicodeBOM
|
||||
* - WhiteSpace
|
||||
* - LineTerminator
|
||||
* - Comment
|
||||
* - Comma
|
||||
* - BlockString indentation
|
||||
*
|
||||
* Note: It is required to have a delimiter character between neighboring
|
||||
* non-punctuator tokens and this function always uses single space as delimiter.
|
||||
*
|
||||
* It is guaranteed that both input and output documents if parsed would result
|
||||
* in the exact same AST except for nodes location.
|
||||
*
|
||||
* Warning: It is guaranteed that this function will always produce stable results.
|
||||
* However, it's not guaranteed that it will stay the same between different
|
||||
* releases due to bugfixes or changes in the GraphQL specification.
|
||||
*
|
||||
* Query example:
|
||||
*
|
||||
* query SomeQuery($foo: String!, $bar: String) {
|
||||
* someField(foo: $foo, bar: $bar) {
|
||||
* a
|
||||
* b {
|
||||
* c
|
||||
* d
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Becomes:
|
||||
*
|
||||
* query SomeQuery($foo:String!$bar:String){someField(foo:$foo bar:$bar){a b{c d}}}
|
||||
*
|
||||
* SDL example:
|
||||
*
|
||||
* """
|
||||
* Type description
|
||||
* """
|
||||
* type Foo {
|
||||
* """
|
||||
* Field description
|
||||
* """
|
||||
* bar: String
|
||||
* }
|
||||
*
|
||||
* Becomes:
|
||||
*
|
||||
* """Type description""" type Foo{"""Field description""" bar:String}
|
||||
*/
|
||||
function stripIgnoredCharacters(source) {
|
||||
var sourceObj = typeof source === 'string' ? new _source.Source(source) : source;
|
||||
|
||||
if (!(sourceObj instanceof _source.Source)) {
|
||||
throw new TypeError("Must provide string or Source. Received: ".concat((0, _inspect.default)(sourceObj)));
|
||||
}
|
||||
|
||||
var body = sourceObj.body;
|
||||
var lexer = (0, _lexer.createLexer)(sourceObj);
|
||||
var strippedBody = '';
|
||||
var wasLastAddedTokenNonPunctuator = false;
|
||||
|
||||
while (lexer.advance().kind !== _tokenKind.TokenKind.EOF) {
|
||||
var currentToken = lexer.token;
|
||||
var tokenKind = currentToken.kind;
|
||||
/**
|
||||
* Every two non-punctuator tokens should have space between them.
|
||||
* Also prevent case of non-punctuator token following by spread resulting
|
||||
* in invalid token (e.g. `1...` is invalid Float token).
|
||||
*/
|
||||
|
||||
var isNonPunctuator = !(0, _lexer.isPunctuatorToken)(currentToken);
|
||||
|
||||
if (wasLastAddedTokenNonPunctuator) {
|
||||
if (isNonPunctuator || currentToken.kind === _tokenKind.TokenKind.SPREAD) {
|
||||
strippedBody += ' ';
|
||||
}
|
||||
}
|
||||
|
||||
var tokenBody = body.slice(currentToken.start, currentToken.end);
|
||||
|
||||
if (tokenKind === _tokenKind.TokenKind.BLOCK_STRING) {
|
||||
strippedBody += dedentBlockString(tokenBody);
|
||||
} else {
|
||||
strippedBody += tokenBody;
|
||||
}
|
||||
|
||||
wasLastAddedTokenNonPunctuator = isNonPunctuator;
|
||||
}
|
||||
|
||||
return strippedBody;
|
||||
}
|
||||
|
||||
function dedentBlockString(blockStr) {
|
||||
// skip leading and trailing triple quotations
|
||||
var rawStr = blockStr.slice(3, -3);
|
||||
var body = (0, _blockString.dedentBlockStringValue)(rawStr);
|
||||
var lines = body.split(/\r\n|[\n\r]/g);
|
||||
|
||||
if ((0, _blockString.getBlockStringIndentation)(lines) > 0) {
|
||||
body = '\n' + body;
|
||||
}
|
||||
|
||||
var lastChar = body[body.length - 1];
|
||||
var hasTrailingQuote = lastChar === '"' && body.slice(-4) !== '\\"""';
|
||||
|
||||
if (hasTrailingQuote || lastChar === '\\') {
|
||||
body += '\n';
|
||||
}
|
||||
|
||||
return '"""' + body + '"""';
|
||||
}
|
||||
124
node_modules/graphql/utilities/stripIgnoredCharacters.js.flow
generated
vendored
Normal file
124
node_modules/graphql/utilities/stripIgnoredCharacters.js.flow
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
// @flow strict
|
||||
|
||||
import inspect from '../jsutils/inspect';
|
||||
|
||||
import { Source } from '../language/source';
|
||||
import { TokenKind } from '../language/tokenKind';
|
||||
import { createLexer, isPunctuatorToken } from '../language/lexer';
|
||||
import {
|
||||
dedentBlockStringValue,
|
||||
getBlockStringIndentation,
|
||||
} from '../language/blockString';
|
||||
|
||||
/**
|
||||
* Strips characters that are not significant to the validity or execution
|
||||
* of a GraphQL document:
|
||||
* - UnicodeBOM
|
||||
* - WhiteSpace
|
||||
* - LineTerminator
|
||||
* - Comment
|
||||
* - Comma
|
||||
* - BlockString indentation
|
||||
*
|
||||
* Note: It is required to have a delimiter character between neighboring
|
||||
* non-punctuator tokens and this function always uses single space as delimiter.
|
||||
*
|
||||
* It is guaranteed that both input and output documents if parsed would result
|
||||
* in the exact same AST except for nodes location.
|
||||
*
|
||||
* Warning: It is guaranteed that this function will always produce stable results.
|
||||
* However, it's not guaranteed that it will stay the same between different
|
||||
* releases due to bugfixes or changes in the GraphQL specification.
|
||||
*
|
||||
* Query example:
|
||||
*
|
||||
* query SomeQuery($foo: String!, $bar: String) {
|
||||
* someField(foo: $foo, bar: $bar) {
|
||||
* a
|
||||
* b {
|
||||
* c
|
||||
* d
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Becomes:
|
||||
*
|
||||
* query SomeQuery($foo:String!$bar:String){someField(foo:$foo bar:$bar){a b{c d}}}
|
||||
*
|
||||
* SDL example:
|
||||
*
|
||||
* """
|
||||
* Type description
|
||||
* """
|
||||
* type Foo {
|
||||
* """
|
||||
* Field description
|
||||
* """
|
||||
* bar: String
|
||||
* }
|
||||
*
|
||||
* Becomes:
|
||||
*
|
||||
* """Type description""" type Foo{"""Field description""" bar:String}
|
||||
*/
|
||||
export function stripIgnoredCharacters(source: string | Source): string {
|
||||
const sourceObj = typeof source === 'string' ? new Source(source) : source;
|
||||
if (!(sourceObj instanceof Source)) {
|
||||
throw new TypeError(
|
||||
`Must provide string or Source. Received: ${inspect(sourceObj)}`,
|
||||
);
|
||||
}
|
||||
|
||||
const body = sourceObj.body;
|
||||
const lexer = createLexer(sourceObj);
|
||||
let strippedBody = '';
|
||||
|
||||
let wasLastAddedTokenNonPunctuator = false;
|
||||
while (lexer.advance().kind !== TokenKind.EOF) {
|
||||
const currentToken = lexer.token;
|
||||
const tokenKind = currentToken.kind;
|
||||
|
||||
/**
|
||||
* Every two non-punctuator tokens should have space between them.
|
||||
* Also prevent case of non-punctuator token following by spread resulting
|
||||
* in invalid token (e.g. `1...` is invalid Float token).
|
||||
*/
|
||||
const isNonPunctuator = !isPunctuatorToken(currentToken);
|
||||
if (wasLastAddedTokenNonPunctuator) {
|
||||
if (isNonPunctuator || currentToken.kind === TokenKind.SPREAD) {
|
||||
strippedBody += ' ';
|
||||
}
|
||||
}
|
||||
|
||||
const tokenBody = body.slice(currentToken.start, currentToken.end);
|
||||
if (tokenKind === TokenKind.BLOCK_STRING) {
|
||||
strippedBody += dedentBlockString(tokenBody);
|
||||
} else {
|
||||
strippedBody += tokenBody;
|
||||
}
|
||||
|
||||
wasLastAddedTokenNonPunctuator = isNonPunctuator;
|
||||
}
|
||||
|
||||
return strippedBody;
|
||||
}
|
||||
|
||||
function dedentBlockString(blockStr) {
|
||||
// skip leading and trailing triple quotations
|
||||
const rawStr = blockStr.slice(3, -3);
|
||||
let body = dedentBlockStringValue(rawStr);
|
||||
|
||||
const lines = body.split(/\r\n|[\n\r]/g);
|
||||
if (getBlockStringIndentation(lines) > 0) {
|
||||
body = '\n' + body;
|
||||
}
|
||||
|
||||
const lastChar = body[body.length - 1];
|
||||
const hasTrailingQuote = lastChar === '"' && body.slice(-4) !== '\\"""';
|
||||
if (hasTrailingQuote || lastChar === '\\') {
|
||||
body += '\n';
|
||||
}
|
||||
|
||||
return '"""' + body + '"""';
|
||||
}
|
||||
120
node_modules/graphql/utilities/stripIgnoredCharacters.mjs
generated
vendored
Normal file
120
node_modules/graphql/utilities/stripIgnoredCharacters.mjs
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
import inspect from '../jsutils/inspect';
|
||||
import { Source } from '../language/source';
|
||||
import { TokenKind } from '../language/tokenKind';
|
||||
import { createLexer, isPunctuatorToken } from '../language/lexer';
|
||||
import { dedentBlockStringValue, getBlockStringIndentation } from '../language/blockString';
|
||||
/**
|
||||
* Strips characters that are not significant to the validity or execution
|
||||
* of a GraphQL document:
|
||||
* - UnicodeBOM
|
||||
* - WhiteSpace
|
||||
* - LineTerminator
|
||||
* - Comment
|
||||
* - Comma
|
||||
* - BlockString indentation
|
||||
*
|
||||
* Note: It is required to have a delimiter character between neighboring
|
||||
* non-punctuator tokens and this function always uses single space as delimiter.
|
||||
*
|
||||
* It is guaranteed that both input and output documents if parsed would result
|
||||
* in the exact same AST except for nodes location.
|
||||
*
|
||||
* Warning: It is guaranteed that this function will always produce stable results.
|
||||
* However, it's not guaranteed that it will stay the same between different
|
||||
* releases due to bugfixes or changes in the GraphQL specification.
|
||||
*
|
||||
* Query example:
|
||||
*
|
||||
* query SomeQuery($foo: String!, $bar: String) {
|
||||
* someField(foo: $foo, bar: $bar) {
|
||||
* a
|
||||
* b {
|
||||
* c
|
||||
* d
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Becomes:
|
||||
*
|
||||
* query SomeQuery($foo:String!$bar:String){someField(foo:$foo bar:$bar){a b{c d}}}
|
||||
*
|
||||
* SDL example:
|
||||
*
|
||||
* """
|
||||
* Type description
|
||||
* """
|
||||
* type Foo {
|
||||
* """
|
||||
* Field description
|
||||
* """
|
||||
* bar: String
|
||||
* }
|
||||
*
|
||||
* Becomes:
|
||||
*
|
||||
* """Type description""" type Foo{"""Field description""" bar:String}
|
||||
*/
|
||||
|
||||
export function stripIgnoredCharacters(source) {
|
||||
var sourceObj = typeof source === 'string' ? new Source(source) : source;
|
||||
|
||||
if (!(sourceObj instanceof Source)) {
|
||||
throw new TypeError("Must provide string or Source. Received: ".concat(inspect(sourceObj)));
|
||||
}
|
||||
|
||||
var body = sourceObj.body;
|
||||
var lexer = createLexer(sourceObj);
|
||||
var strippedBody = '';
|
||||
var wasLastAddedTokenNonPunctuator = false;
|
||||
|
||||
while (lexer.advance().kind !== TokenKind.EOF) {
|
||||
var currentToken = lexer.token;
|
||||
var tokenKind = currentToken.kind;
|
||||
/**
|
||||
* Every two non-punctuator tokens should have space between them.
|
||||
* Also prevent case of non-punctuator token following by spread resulting
|
||||
* in invalid token (e.g. `1...` is invalid Float token).
|
||||
*/
|
||||
|
||||
var isNonPunctuator = !isPunctuatorToken(currentToken);
|
||||
|
||||
if (wasLastAddedTokenNonPunctuator) {
|
||||
if (isNonPunctuator || currentToken.kind === TokenKind.SPREAD) {
|
||||
strippedBody += ' ';
|
||||
}
|
||||
}
|
||||
|
||||
var tokenBody = body.slice(currentToken.start, currentToken.end);
|
||||
|
||||
if (tokenKind === TokenKind.BLOCK_STRING) {
|
||||
strippedBody += dedentBlockString(tokenBody);
|
||||
} else {
|
||||
strippedBody += tokenBody;
|
||||
}
|
||||
|
||||
wasLastAddedTokenNonPunctuator = isNonPunctuator;
|
||||
}
|
||||
|
||||
return strippedBody;
|
||||
}
|
||||
|
||||
function dedentBlockString(blockStr) {
|
||||
// skip leading and trailing triple quotations
|
||||
var rawStr = blockStr.slice(3, -3);
|
||||
var body = dedentBlockStringValue(rawStr);
|
||||
var lines = body.split(/\r\n|[\n\r]/g);
|
||||
|
||||
if (getBlockStringIndentation(lines) > 0) {
|
||||
body = '\n' + body;
|
||||
}
|
||||
|
||||
var lastChar = body[body.length - 1];
|
||||
var hasTrailingQuote = lastChar === '"' && body.slice(-4) !== '\\"""';
|
||||
|
||||
if (hasTrailingQuote || lastChar === '\\') {
|
||||
body += '\n';
|
||||
}
|
||||
|
||||
return '"""' + body + '"""';
|
||||
}
|
||||
32
node_modules/graphql/utilities/typeComparators.d.ts
generated
vendored
Normal file
32
node_modules/graphql/utilities/typeComparators.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { GraphQLType, GraphQLCompositeType } from '../type/definition';
|
||||
|
||||
/**
|
||||
* Provided two types, return true if the types are equal (invariant).
|
||||
*/
|
||||
export function isEqualType(typeA: GraphQLType, typeB: GraphQLType): boolean;
|
||||
|
||||
/**
|
||||
* Provided a type and a super type, return true if the first type is either
|
||||
* equal or a subset of the second super type (covariant).
|
||||
*/
|
||||
export function isTypeSubTypeOf(
|
||||
schema: GraphQLSchema,
|
||||
maybeSubType: GraphQLType,
|
||||
superType: GraphQLType,
|
||||
): boolean;
|
||||
|
||||
/**
|
||||
* Provided two composite types, determine if they "overlap". Two composite
|
||||
* types overlap when the Sets of possible concrete types for each intersect.
|
||||
*
|
||||
* This is often used to determine if a fragment of a given type could possibly
|
||||
* be visited in a context of another type.
|
||||
*
|
||||
* This function is commutative.
|
||||
*/
|
||||
export function doTypesOverlap(
|
||||
schema: GraphQLSchema,
|
||||
typeA: GraphQLCompositeType,
|
||||
typeB: GraphQLCompositeType,
|
||||
): boolean;
|
||||
120
node_modules/graphql/utilities/typeComparators.js
generated
vendored
Normal file
120
node_modules/graphql/utilities/typeComparators.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isEqualType = isEqualType;
|
||||
exports.isTypeSubTypeOf = isTypeSubTypeOf;
|
||||
exports.doTypesOverlap = doTypesOverlap;
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
/**
|
||||
* Provided two types, return true if the types are equal (invariant).
|
||||
*/
|
||||
function isEqualType(typeA, typeB) {
|
||||
// Equivalent types are equal.
|
||||
if (typeA === typeB) {
|
||||
return true;
|
||||
} // If either type is non-null, the other must also be non-null.
|
||||
|
||||
|
||||
if ((0, _definition.isNonNullType)(typeA) && (0, _definition.isNonNullType)(typeB)) {
|
||||
return isEqualType(typeA.ofType, typeB.ofType);
|
||||
} // If either type is a list, the other must also be a list.
|
||||
|
||||
|
||||
if ((0, _definition.isListType)(typeA) && (0, _definition.isListType)(typeB)) {
|
||||
return isEqualType(typeA.ofType, typeB.ofType);
|
||||
} // Otherwise the types are not equal.
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Provided a type and a super type, return true if the first type is either
|
||||
* equal or a subset of the second super type (covariant).
|
||||
*/
|
||||
|
||||
|
||||
function isTypeSubTypeOf(schema, maybeSubType, superType) {
|
||||
// Equivalent type is a valid subtype
|
||||
if (maybeSubType === superType) {
|
||||
return true;
|
||||
} // If superType is non-null, maybeSubType must also be non-null.
|
||||
|
||||
|
||||
if ((0, _definition.isNonNullType)(superType)) {
|
||||
if ((0, _definition.isNonNullType)(maybeSubType)) {
|
||||
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((0, _definition.isNonNullType)(maybeSubType)) {
|
||||
// If superType is nullable, maybeSubType may be non-null or nullable.
|
||||
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);
|
||||
} // If superType type is a list, maybeSubType type must also be a list.
|
||||
|
||||
|
||||
if ((0, _definition.isListType)(superType)) {
|
||||
if ((0, _definition.isListType)(maybeSubType)) {
|
||||
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((0, _definition.isListType)(maybeSubType)) {
|
||||
// If superType is not a list, maybeSubType must also be not a list.
|
||||
return false;
|
||||
} // If superType type is an abstract type, maybeSubType type may be a currently
|
||||
// possible object type.
|
||||
|
||||
|
||||
if ((0, _definition.isAbstractType)(superType) && (0, _definition.isObjectType)(maybeSubType) && schema.isPossibleType(superType, maybeSubType)) {
|
||||
return true;
|
||||
} // Otherwise, the child type is not a valid subtype of the parent type.
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Provided two composite types, determine if they "overlap". Two composite
|
||||
* types overlap when the Sets of possible concrete types for each intersect.
|
||||
*
|
||||
* This is often used to determine if a fragment of a given type could possibly
|
||||
* be visited in a context of another type.
|
||||
*
|
||||
* This function is commutative.
|
||||
*/
|
||||
|
||||
|
||||
function doTypesOverlap(schema, typeA, typeB) {
|
||||
// Equivalent types overlap
|
||||
if (typeA === typeB) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((0, _definition.isAbstractType)(typeA)) {
|
||||
if ((0, _definition.isAbstractType)(typeB)) {
|
||||
// If both types are abstract, then determine if there is any intersection
|
||||
// between possible concrete types of each.
|
||||
return schema.getPossibleTypes(typeA).some(function (type) {
|
||||
return schema.isPossibleType(typeB, type);
|
||||
});
|
||||
} // Determine if the latter type is a possible concrete type of the former.
|
||||
|
||||
|
||||
return schema.isPossibleType(typeA, typeB);
|
||||
}
|
||||
|
||||
if ((0, _definition.isAbstractType)(typeB)) {
|
||||
// Determine if the former type is a possible concrete type of the latter.
|
||||
return schema.isPossibleType(typeB, typeA);
|
||||
} // Otherwise the types do not overlap.
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
126
node_modules/graphql/utilities/typeComparators.js.flow
generated
vendored
Normal file
126
node_modules/graphql/utilities/typeComparators.js.flow
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
// @flow strict
|
||||
|
||||
import { type GraphQLSchema } from '../type/schema';
|
||||
import {
|
||||
type GraphQLType,
|
||||
type GraphQLCompositeType,
|
||||
isObjectType,
|
||||
isListType,
|
||||
isNonNullType,
|
||||
isAbstractType,
|
||||
} from '../type/definition';
|
||||
|
||||
/**
|
||||
* Provided two types, return true if the types are equal (invariant).
|
||||
*/
|
||||
export function isEqualType(typeA: GraphQLType, typeB: GraphQLType): boolean {
|
||||
// Equivalent types are equal.
|
||||
if (typeA === typeB) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If either type is non-null, the other must also be non-null.
|
||||
if (isNonNullType(typeA) && isNonNullType(typeB)) {
|
||||
return isEqualType(typeA.ofType, typeB.ofType);
|
||||
}
|
||||
|
||||
// If either type is a list, the other must also be a list.
|
||||
if (isListType(typeA) && isListType(typeB)) {
|
||||
return isEqualType(typeA.ofType, typeB.ofType);
|
||||
}
|
||||
|
||||
// Otherwise the types are not equal.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provided a type and a super type, return true if the first type is either
|
||||
* equal or a subset of the second super type (covariant).
|
||||
*/
|
||||
export function isTypeSubTypeOf(
|
||||
schema: GraphQLSchema,
|
||||
maybeSubType: GraphQLType,
|
||||
superType: GraphQLType,
|
||||
): boolean {
|
||||
// Equivalent type is a valid subtype
|
||||
if (maybeSubType === superType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If superType is non-null, maybeSubType must also be non-null.
|
||||
if (isNonNullType(superType)) {
|
||||
if (isNonNullType(maybeSubType)) {
|
||||
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (isNonNullType(maybeSubType)) {
|
||||
// If superType is nullable, maybeSubType may be non-null or nullable.
|
||||
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);
|
||||
}
|
||||
|
||||
// If superType type is a list, maybeSubType type must also be a list.
|
||||
if (isListType(superType)) {
|
||||
if (isListType(maybeSubType)) {
|
||||
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (isListType(maybeSubType)) {
|
||||
// If superType is not a list, maybeSubType must also be not a list.
|
||||
return false;
|
||||
}
|
||||
|
||||
// If superType type is an abstract type, maybeSubType type may be a currently
|
||||
// possible object type.
|
||||
if (
|
||||
isAbstractType(superType) &&
|
||||
isObjectType(maybeSubType) &&
|
||||
schema.isPossibleType(superType, maybeSubType)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, the child type is not a valid subtype of the parent type.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provided two composite types, determine if they "overlap". Two composite
|
||||
* types overlap when the Sets of possible concrete types for each intersect.
|
||||
*
|
||||
* This is often used to determine if a fragment of a given type could possibly
|
||||
* be visited in a context of another type.
|
||||
*
|
||||
* This function is commutative.
|
||||
*/
|
||||
export function doTypesOverlap(
|
||||
schema: GraphQLSchema,
|
||||
typeA: GraphQLCompositeType,
|
||||
typeB: GraphQLCompositeType,
|
||||
): boolean {
|
||||
// Equivalent types overlap
|
||||
if (typeA === typeB) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isAbstractType(typeA)) {
|
||||
if (isAbstractType(typeB)) {
|
||||
// If both types are abstract, then determine if there is any intersection
|
||||
// between possible concrete types of each.
|
||||
return schema
|
||||
.getPossibleTypes(typeA)
|
||||
.some(type => schema.isPossibleType(typeB, type));
|
||||
}
|
||||
// Determine if the latter type is a possible concrete type of the former.
|
||||
return schema.isPossibleType(typeA, typeB);
|
||||
}
|
||||
|
||||
if (isAbstractType(typeB)) {
|
||||
// Determine if the former type is a possible concrete type of the latter.
|
||||
return schema.isPossibleType(typeB, typeA);
|
||||
}
|
||||
|
||||
// Otherwise the types do not overlap.
|
||||
return false;
|
||||
}
|
||||
109
node_modules/graphql/utilities/typeComparators.mjs
generated
vendored
Normal file
109
node_modules/graphql/utilities/typeComparators.mjs
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
import { isObjectType, isListType, isNonNullType, isAbstractType } from '../type/definition';
|
||||
/**
|
||||
* Provided two types, return true if the types are equal (invariant).
|
||||
*/
|
||||
|
||||
export function isEqualType(typeA, typeB) {
|
||||
// Equivalent types are equal.
|
||||
if (typeA === typeB) {
|
||||
return true;
|
||||
} // If either type is non-null, the other must also be non-null.
|
||||
|
||||
|
||||
if (isNonNullType(typeA) && isNonNullType(typeB)) {
|
||||
return isEqualType(typeA.ofType, typeB.ofType);
|
||||
} // If either type is a list, the other must also be a list.
|
||||
|
||||
|
||||
if (isListType(typeA) && isListType(typeB)) {
|
||||
return isEqualType(typeA.ofType, typeB.ofType);
|
||||
} // Otherwise the types are not equal.
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Provided a type and a super type, return true if the first type is either
|
||||
* equal or a subset of the second super type (covariant).
|
||||
*/
|
||||
|
||||
export function isTypeSubTypeOf(schema, maybeSubType, superType) {
|
||||
// Equivalent type is a valid subtype
|
||||
if (maybeSubType === superType) {
|
||||
return true;
|
||||
} // If superType is non-null, maybeSubType must also be non-null.
|
||||
|
||||
|
||||
if (isNonNullType(superType)) {
|
||||
if (isNonNullType(maybeSubType)) {
|
||||
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isNonNullType(maybeSubType)) {
|
||||
// If superType is nullable, maybeSubType may be non-null or nullable.
|
||||
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);
|
||||
} // If superType type is a list, maybeSubType type must also be a list.
|
||||
|
||||
|
||||
if (isListType(superType)) {
|
||||
if (isListType(maybeSubType)) {
|
||||
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isListType(maybeSubType)) {
|
||||
// If superType is not a list, maybeSubType must also be not a list.
|
||||
return false;
|
||||
} // If superType type is an abstract type, maybeSubType type may be a currently
|
||||
// possible object type.
|
||||
|
||||
|
||||
if (isAbstractType(superType) && isObjectType(maybeSubType) && schema.isPossibleType(superType, maybeSubType)) {
|
||||
return true;
|
||||
} // Otherwise, the child type is not a valid subtype of the parent type.
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Provided two composite types, determine if they "overlap". Two composite
|
||||
* types overlap when the Sets of possible concrete types for each intersect.
|
||||
*
|
||||
* This is often used to determine if a fragment of a given type could possibly
|
||||
* be visited in a context of another type.
|
||||
*
|
||||
* This function is commutative.
|
||||
*/
|
||||
|
||||
export function doTypesOverlap(schema, typeA, typeB) {
|
||||
// Equivalent types overlap
|
||||
if (typeA === typeB) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isAbstractType(typeA)) {
|
||||
if (isAbstractType(typeB)) {
|
||||
// If both types are abstract, then determine if there is any intersection
|
||||
// between possible concrete types of each.
|
||||
return schema.getPossibleTypes(typeA).some(function (type) {
|
||||
return schema.isPossibleType(typeB, type);
|
||||
});
|
||||
} // Determine if the latter type is a possible concrete type of the former.
|
||||
|
||||
|
||||
return schema.isPossibleType(typeA, typeB);
|
||||
}
|
||||
|
||||
if (isAbstractType(typeB)) {
|
||||
// Determine if the former type is a possible concrete type of the latter.
|
||||
return schema.isPossibleType(typeB, typeA);
|
||||
} // Otherwise the types do not overlap.
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
29
node_modules/graphql/utilities/typeFromAST.d.ts
generated
vendored
Normal file
29
node_modules/graphql/utilities/typeFromAST.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NamedTypeNode, ListTypeNode, NonNullTypeNode } from '../language/ast';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import {
|
||||
GraphQLNamedType,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
} from '../type/definition';
|
||||
|
||||
/**
|
||||
* Given a Schema and an AST node describing a type, return a GraphQLType
|
||||
* definition which applies to that type. For example, if provided the parsed
|
||||
* AST node for `[User]`, a GraphQLList instance will be returned, containing
|
||||
* the type called "User" found in the schema. If a type called "User" is not
|
||||
* found in the schema, then undefined will be returned.
|
||||
*/
|
||||
export function typeFromAST(
|
||||
schema: GraphQLSchema,
|
||||
typeNode: NamedTypeNode,
|
||||
): GraphQLNamedType | undefined;
|
||||
|
||||
export function typeFromAST(
|
||||
schema: GraphQLSchema,
|
||||
typeNode: ListTypeNode,
|
||||
): GraphQLList<any> | undefined;
|
||||
|
||||
export function typeFromAST(
|
||||
schema: GraphQLSchema,
|
||||
typeNode: NonNullTypeNode,
|
||||
): GraphQLNonNull<any> | undefined;
|
||||
40
node_modules/graphql/utilities/typeFromAST.js
generated
vendored
Normal file
40
node_modules/graphql/utilities/typeFromAST.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.typeFromAST = typeFromAST;
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _kinds = require("../language/kinds");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function typeFromAST(schema, typeNode) {
|
||||
/* eslint-enable no-redeclare */
|
||||
var innerType;
|
||||
|
||||
if (typeNode.kind === _kinds.Kind.LIST_TYPE) {
|
||||
innerType = typeFromAST(schema, typeNode.type);
|
||||
return innerType && (0, _definition.GraphQLList)(innerType);
|
||||
}
|
||||
|
||||
if (typeNode.kind === _kinds.Kind.NON_NULL_TYPE) {
|
||||
innerType = typeFromAST(schema, typeNode.type);
|
||||
return innerType && (0, _definition.GraphQLNonNull)(innerType);
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (typeNode.kind === _kinds.Kind.NAMED_TYPE) {
|
||||
return schema.getType(typeNode.name.value);
|
||||
} // Not reachable. All possible type nodes have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
(0, _invariant.default)(false, 'Unexpected type node: ' + (0, _inspect.default)(typeNode));
|
||||
}
|
||||
57
node_modules/graphql/utilities/typeFromAST.js.flow
generated
vendored
Normal file
57
node_modules/graphql/utilities/typeFromAST.js.flow
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
// @flow strict
|
||||
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
|
||||
import { Kind } from '../language/kinds';
|
||||
import {
|
||||
type NamedTypeNode,
|
||||
type ListTypeNode,
|
||||
type NonNullTypeNode,
|
||||
} from '../language/ast';
|
||||
|
||||
import { type GraphQLSchema } from '../type/schema';
|
||||
import {
|
||||
type GraphQLNamedType,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
} from '../type/definition';
|
||||
|
||||
/**
|
||||
* Given a Schema and an AST node describing a type, return a GraphQLType
|
||||
* definition which applies to that type. For example, if provided the parsed
|
||||
* AST node for `[User]`, a GraphQLList instance will be returned, containing
|
||||
* the type called "User" found in the schema. If a type called "User" is not
|
||||
* found in the schema, then undefined will be returned.
|
||||
*/
|
||||
/* eslint-disable no-redeclare */
|
||||
declare function typeFromAST(
|
||||
schema: GraphQLSchema,
|
||||
typeNode: NamedTypeNode,
|
||||
): GraphQLNamedType | void;
|
||||
declare function typeFromAST(
|
||||
schema: GraphQLSchema,
|
||||
typeNode: ListTypeNode,
|
||||
): GraphQLList<any> | void;
|
||||
declare function typeFromAST(
|
||||
schema: GraphQLSchema,
|
||||
typeNode: NonNullTypeNode,
|
||||
): GraphQLNonNull<any> | void;
|
||||
export function typeFromAST(schema, typeNode) {
|
||||
/* eslint-enable no-redeclare */
|
||||
let innerType;
|
||||
if (typeNode.kind === Kind.LIST_TYPE) {
|
||||
innerType = typeFromAST(schema, typeNode.type);
|
||||
return innerType && GraphQLList(innerType);
|
||||
}
|
||||
if (typeNode.kind === Kind.NON_NULL_TYPE) {
|
||||
innerType = typeFromAST(schema, typeNode.type);
|
||||
return innerType && GraphQLNonNull(innerType);
|
||||
}
|
||||
if (typeNode.kind === Kind.NAMED_TYPE) {
|
||||
return schema.getType(typeNode.name.value);
|
||||
}
|
||||
|
||||
// Not reachable. All possible type nodes have been considered.
|
||||
invariant(false, 'Unexpected type node: ' + inspect((typeNode: empty)));
|
||||
}
|
||||
37
node_modules/graphql/utilities/typeFromAST.mjs
generated
vendored
Normal file
37
node_modules/graphql/utilities/typeFromAST.mjs
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import { Kind } from '../language/kinds';
|
||||
import { GraphQLList, GraphQLNonNull } from '../type/definition';
|
||||
/**
|
||||
* Given a Schema and an AST node describing a type, return a GraphQLType
|
||||
* definition which applies to that type. For example, if provided the parsed
|
||||
* AST node for `[User]`, a GraphQLList instance will be returned, containing
|
||||
* the type called "User" found in the schema. If a type called "User" is not
|
||||
* found in the schema, then undefined will be returned.
|
||||
*/
|
||||
|
||||
/* eslint-disable no-redeclare */
|
||||
|
||||
export function typeFromAST(schema, typeNode) {
|
||||
/* eslint-enable no-redeclare */
|
||||
var innerType;
|
||||
|
||||
if (typeNode.kind === Kind.LIST_TYPE) {
|
||||
innerType = typeFromAST(schema, typeNode.type);
|
||||
return innerType && GraphQLList(innerType);
|
||||
}
|
||||
|
||||
if (typeNode.kind === Kind.NON_NULL_TYPE) {
|
||||
innerType = typeFromAST(schema, typeNode.type);
|
||||
return innerType && GraphQLNonNull(innerType);
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (typeNode.kind === Kind.NAMED_TYPE) {
|
||||
return schema.getType(typeNode.name.value);
|
||||
} // Not reachable. All possible type nodes have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
invariant(false, 'Unexpected type node: ' + inspect(typeNode));
|
||||
}
|
||||
29
node_modules/graphql/utilities/valueFromAST.d.ts
generated
vendored
Normal file
29
node_modules/graphql/utilities/valueFromAST.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import Maybe from '../tsutils/Maybe';
|
||||
import { ValueNode } from '../language/ast';
|
||||
import { GraphQLInputType } from '../type/definition';
|
||||
|
||||
/**
|
||||
* Produces a JavaScript value given a GraphQL Value AST.
|
||||
*
|
||||
* A GraphQL type must be provided, which will be used to interpret different
|
||||
* GraphQL Value literals.
|
||||
*
|
||||
* Returns `undefined` when the value could not be validly coerced according to
|
||||
* the provided type.
|
||||
*
|
||||
* | GraphQL Value | JSON Value |
|
||||
* | -------------------- | ------------- |
|
||||
* | Input Object | Object |
|
||||
* | List | Array |
|
||||
* | Boolean | Boolean |
|
||||
* | String | String |
|
||||
* | Int / Float | Number |
|
||||
* | Enum Value | Mixed |
|
||||
* | NullValue | null |
|
||||
*
|
||||
*/
|
||||
export function valueFromAST(
|
||||
valueNode: Maybe<ValueNode>,
|
||||
type: GraphQLInputType,
|
||||
variables?: Maybe<{ [key: string]: any }>,
|
||||
): any;
|
||||
203
node_modules/graphql/utilities/valueFromAST.js
generated
vendored
Normal file
203
node_modules/graphql/utilities/valueFromAST.js
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.valueFromAST = valueFromAST;
|
||||
|
||||
var _objectValues3 = _interopRequireDefault(require("../polyfills/objectValues"));
|
||||
|
||||
var _keyMap = _interopRequireDefault(require("../jsutils/keyMap"));
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
||||
|
||||
var _isInvalid = _interopRequireDefault(require("../jsutils/isInvalid"));
|
||||
|
||||
var _kinds = require("../language/kinds");
|
||||
|
||||
var _definition = require("../type/definition");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Produces a JavaScript value given a GraphQL Value AST.
|
||||
*
|
||||
* A GraphQL type must be provided, which will be used to interpret different
|
||||
* GraphQL Value literals.
|
||||
*
|
||||
* Returns `undefined` when the value could not be validly coerced according to
|
||||
* the provided type.
|
||||
*
|
||||
* | GraphQL Value | JSON Value |
|
||||
* | -------------------- | ------------- |
|
||||
* | Input Object | Object |
|
||||
* | List | Array |
|
||||
* | Boolean | Boolean |
|
||||
* | String | String |
|
||||
* | Int / Float | Number |
|
||||
* | Enum Value | Mixed |
|
||||
* | NullValue | null |
|
||||
*
|
||||
*/
|
||||
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 ((0, _definition.isNonNullType)(type)) {
|
||||
if (valueNode.kind === _kinds.Kind.NULL) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
return valueFromAST(valueNode, type.ofType, variables);
|
||||
}
|
||||
|
||||
if (valueNode.kind === _kinds.Kind.NULL) {
|
||||
// This is explicitly returning the value null.
|
||||
return null;
|
||||
}
|
||||
|
||||
if (valueNode.kind === _kinds.Kind.VARIABLE) {
|
||||
var variableName = valueNode.name.value;
|
||||
|
||||
if (!variables || (0, _isInvalid.default)(variables[variableName])) {
|
||||
// No valid return value.
|
||||
return;
|
||||
}
|
||||
|
||||
var variableValue = variables[variableName];
|
||||
|
||||
if (variableValue === null && (0, _definition.isNonNullType)(type)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
} // Note: This does no further checking that this variable is correct.
|
||||
// This assumes that this query has been validated and the variable
|
||||
// usage here is of the correct type.
|
||||
|
||||
|
||||
return variableValue;
|
||||
}
|
||||
|
||||
if ((0, _definition.isListType)(type)) {
|
||||
var itemType = type.ofType;
|
||||
|
||||
if (valueNode.kind === _kinds.Kind.LIST) {
|
||||
var coercedValues = [];
|
||||
|
||||
for (var _i2 = 0, _valueNode$values2 = valueNode.values; _i2 < _valueNode$values2.length; _i2++) {
|
||||
var itemNode = _valueNode$values2[_i2];
|
||||
|
||||
if (isMissingVariable(itemNode, 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 ((0, _definition.isNonNullType)(itemType)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
coercedValues.push(null);
|
||||
} else {
|
||||
var itemValue = valueFromAST(itemNode, itemType, variables);
|
||||
|
||||
if ((0, _isInvalid.default)(itemValue)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
coercedValues.push(itemValue);
|
||||
}
|
||||
}
|
||||
|
||||
return coercedValues;
|
||||
}
|
||||
|
||||
var coercedValue = valueFromAST(valueNode, itemType, variables);
|
||||
|
||||
if ((0, _isInvalid.default)(coercedValue)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
return [coercedValue];
|
||||
}
|
||||
|
||||
if ((0, _definition.isInputObjectType)(type)) {
|
||||
if (valueNode.kind !== _kinds.Kind.OBJECT) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
var coercedObj = Object.create(null);
|
||||
var fieldNodes = (0, _keyMap.default)(valueNode.fields, function (field) {
|
||||
return field.name.value;
|
||||
});
|
||||
|
||||
for (var _i4 = 0, _objectValues2 = (0, _objectValues3.default)(type.getFields()); _i4 < _objectValues2.length; _i4++) {
|
||||
var field = _objectValues2[_i4];
|
||||
var fieldNode = fieldNodes[field.name];
|
||||
|
||||
if (!fieldNode || isMissingVariable(fieldNode.value, variables)) {
|
||||
if (field.defaultValue !== undefined) {
|
||||
coercedObj[field.name] = field.defaultValue;
|
||||
} else if ((0, _definition.isNonNullType)(field.type)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
var fieldValue = valueFromAST(fieldNode.value, field.type, variables);
|
||||
|
||||
if ((0, _isInvalid.default)(fieldValue)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
coercedObj[field.name] = fieldValue;
|
||||
}
|
||||
|
||||
return coercedObj;
|
||||
}
|
||||
|
||||
if ((0, _definition.isEnumType)(type)) {
|
||||
if (valueNode.kind !== _kinds.Kind.ENUM) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
var enumValue = type.getValue(valueNode.value);
|
||||
|
||||
if (!enumValue) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
return enumValue.value;
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if ((0, _definition.isScalarType)(type)) {
|
||||
// Scalars fulfill parsing a literal value via parseLiteral().
|
||||
// Invalid values represent a failure to parse correctly, in which case
|
||||
// no value is returned.
|
||||
var result;
|
||||
|
||||
try {
|
||||
result = type.parseLiteral(valueNode, variables);
|
||||
} catch (_error) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
if ((0, _isInvalid.default)(result)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
return result;
|
||||
} // Not reachable. All possible input types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
(0, _invariant.default)(false, 'Unexpected input type: ' + (0, _inspect.default)(type));
|
||||
} // 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 === _kinds.Kind.VARIABLE && (!variables || (0, _isInvalid.default)(variables[valueNode.name.value]));
|
||||
}
|
||||
174
node_modules/graphql/utilities/valueFromAST.js.flow
generated
vendored
Normal file
174
node_modules/graphql/utilities/valueFromAST.js.flow
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
// @flow strict
|
||||
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
|
||||
import keyMap from '../jsutils/keyMap';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import isInvalid from '../jsutils/isInvalid';
|
||||
import { type ObjMap } from '../jsutils/ObjMap';
|
||||
|
||||
import { Kind } from '../language/kinds';
|
||||
import { type ValueNode } from '../language/ast';
|
||||
|
||||
import {
|
||||
type GraphQLInputType,
|
||||
isScalarType,
|
||||
isEnumType,
|
||||
isInputObjectType,
|
||||
isListType,
|
||||
isNonNullType,
|
||||
} from '../type/definition';
|
||||
|
||||
/**
|
||||
* Produces a JavaScript value given a GraphQL Value AST.
|
||||
*
|
||||
* A GraphQL type must be provided, which will be used to interpret different
|
||||
* GraphQL Value literals.
|
||||
*
|
||||
* Returns `undefined` when the value could not be validly coerced according to
|
||||
* the provided type.
|
||||
*
|
||||
* | GraphQL Value | JSON Value |
|
||||
* | -------------------- | ------------- |
|
||||
* | Input Object | Object |
|
||||
* | List | Array |
|
||||
* | Boolean | Boolean |
|
||||
* | String | String |
|
||||
* | Int / Float | Number |
|
||||
* | Enum Value | Mixed |
|
||||
* | NullValue | null |
|
||||
*
|
||||
*/
|
||||
export function valueFromAST(
|
||||
valueNode: ?ValueNode,
|
||||
type: GraphQLInputType,
|
||||
variables?: ?ObjMap<mixed>,
|
||||
): mixed | void {
|
||||
if (!valueNode) {
|
||||
// When there is no node, then there is also no value.
|
||||
// Importantly, this is different from returning the value null.
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNonNullType(type)) {
|
||||
if (valueNode.kind === Kind.NULL) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
return valueFromAST(valueNode, type.ofType, variables);
|
||||
}
|
||||
|
||||
if (valueNode.kind === Kind.NULL) {
|
||||
// This is explicitly returning the value null.
|
||||
return null;
|
||||
}
|
||||
|
||||
if (valueNode.kind === Kind.VARIABLE) {
|
||||
const variableName = valueNode.name.value;
|
||||
if (!variables || isInvalid(variables[variableName])) {
|
||||
// No valid return value.
|
||||
return;
|
||||
}
|
||||
const variableValue = variables[variableName];
|
||||
if (variableValue === null && isNonNullType(type)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
// Note: This does no further checking that this variable is correct.
|
||||
// This assumes that this query has been validated and the variable
|
||||
// usage here is of the correct type.
|
||||
return variableValue;
|
||||
}
|
||||
|
||||
if (isListType(type)) {
|
||||
const itemType = type.ofType;
|
||||
if (valueNode.kind === Kind.LIST) {
|
||||
const coercedValues = [];
|
||||
for (const itemNode of valueNode.values) {
|
||||
if (isMissingVariable(itemNode, 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 (isNonNullType(itemType)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
coercedValues.push(null);
|
||||
} else {
|
||||
const itemValue = valueFromAST(itemNode, itemType, variables);
|
||||
if (isInvalid(itemValue)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
coercedValues.push(itemValue);
|
||||
}
|
||||
}
|
||||
return coercedValues;
|
||||
}
|
||||
const coercedValue = valueFromAST(valueNode, itemType, variables);
|
||||
if (isInvalid(coercedValue)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
return [coercedValue];
|
||||
}
|
||||
|
||||
if (isInputObjectType(type)) {
|
||||
if (valueNode.kind !== Kind.OBJECT) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
const coercedObj = Object.create(null);
|
||||
const fieldNodes = keyMap(valueNode.fields, field => field.name.value);
|
||||
for (const field of objectValues(type.getFields())) {
|
||||
const fieldNode = fieldNodes[field.name];
|
||||
if (!fieldNode || isMissingVariable(fieldNode.value, variables)) {
|
||||
if (field.defaultValue !== undefined) {
|
||||
coercedObj[field.name] = field.defaultValue;
|
||||
} else if (isNonNullType(field.type)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const fieldValue = valueFromAST(fieldNode.value, field.type, variables);
|
||||
if (isInvalid(fieldValue)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
coercedObj[field.name] = fieldValue;
|
||||
}
|
||||
return coercedObj;
|
||||
}
|
||||
|
||||
if (isEnumType(type)) {
|
||||
if (valueNode.kind !== Kind.ENUM) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
const enumValue = type.getValue(valueNode.value);
|
||||
if (!enumValue) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
return enumValue.value;
|
||||
}
|
||||
|
||||
if (isScalarType(type)) {
|
||||
// Scalars fulfill parsing a literal value via parseLiteral().
|
||||
// Invalid values represent a failure to parse correctly, in which case
|
||||
// no value is returned.
|
||||
let result;
|
||||
try {
|
||||
result = type.parseLiteral(valueNode, variables);
|
||||
} catch (_error) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
if (isInvalid(result)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Not reachable. All possible input types have been considered.
|
||||
invariant(false, 'Unexpected input type: ' + inspect((type: empty)));
|
||||
}
|
||||
|
||||
// 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 || isInvalid(variables[valueNode.name.value]))
|
||||
);
|
||||
}
|
||||
187
node_modules/graphql/utilities/valueFromAST.mjs
generated
vendored
Normal file
187
node_modules/graphql/utilities/valueFromAST.mjs
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
import objectValues from '../polyfills/objectValues';
|
||||
import keyMap from '../jsutils/keyMap';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import invariant from '../jsutils/invariant';
|
||||
import isInvalid from '../jsutils/isInvalid';
|
||||
import { Kind } from '../language/kinds';
|
||||
import { isScalarType, isEnumType, isInputObjectType, isListType, isNonNullType } from '../type/definition';
|
||||
/**
|
||||
* Produces a JavaScript value given a GraphQL Value AST.
|
||||
*
|
||||
* A GraphQL type must be provided, which will be used to interpret different
|
||||
* GraphQL Value literals.
|
||||
*
|
||||
* Returns `undefined` when the value could not be validly coerced according to
|
||||
* the provided type.
|
||||
*
|
||||
* | GraphQL Value | JSON Value |
|
||||
* | -------------------- | ------------- |
|
||||
* | Input Object | Object |
|
||||
* | List | Array |
|
||||
* | Boolean | Boolean |
|
||||
* | String | String |
|
||||
* | Int / Float | Number |
|
||||
* | Enum Value | Mixed |
|
||||
* | NullValue | null |
|
||||
*
|
||||
*/
|
||||
|
||||
export 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 (isNonNullType(type)) {
|
||||
if (valueNode.kind === Kind.NULL) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
return valueFromAST(valueNode, type.ofType, variables);
|
||||
}
|
||||
|
||||
if (valueNode.kind === Kind.NULL) {
|
||||
// This is explicitly returning the value null.
|
||||
return null;
|
||||
}
|
||||
|
||||
if (valueNode.kind === Kind.VARIABLE) {
|
||||
var variableName = valueNode.name.value;
|
||||
|
||||
if (!variables || isInvalid(variables[variableName])) {
|
||||
// No valid return value.
|
||||
return;
|
||||
}
|
||||
|
||||
var variableValue = variables[variableName];
|
||||
|
||||
if (variableValue === null && isNonNullType(type)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
} // Note: This does no further checking that this variable is correct.
|
||||
// This assumes that this query has been validated and the variable
|
||||
// usage here is of the correct type.
|
||||
|
||||
|
||||
return variableValue;
|
||||
}
|
||||
|
||||
if (isListType(type)) {
|
||||
var itemType = type.ofType;
|
||||
|
||||
if (valueNode.kind === Kind.LIST) {
|
||||
var coercedValues = [];
|
||||
|
||||
for (var _i2 = 0, _valueNode$values2 = valueNode.values; _i2 < _valueNode$values2.length; _i2++) {
|
||||
var itemNode = _valueNode$values2[_i2];
|
||||
|
||||
if (isMissingVariable(itemNode, 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 (isNonNullType(itemType)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
coercedValues.push(null);
|
||||
} else {
|
||||
var itemValue = valueFromAST(itemNode, itemType, variables);
|
||||
|
||||
if (isInvalid(itemValue)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
coercedValues.push(itemValue);
|
||||
}
|
||||
}
|
||||
|
||||
return coercedValues;
|
||||
}
|
||||
|
||||
var coercedValue = valueFromAST(valueNode, itemType, variables);
|
||||
|
||||
if (isInvalid(coercedValue)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
return [coercedValue];
|
||||
}
|
||||
|
||||
if (isInputObjectType(type)) {
|
||||
if (valueNode.kind !== Kind.OBJECT) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
var coercedObj = Object.create(null);
|
||||
var fieldNodes = keyMap(valueNode.fields, function (field) {
|
||||
return field.name.value;
|
||||
});
|
||||
|
||||
for (var _i4 = 0, _objectValues2 = objectValues(type.getFields()); _i4 < _objectValues2.length; _i4++) {
|
||||
var field = _objectValues2[_i4];
|
||||
var fieldNode = fieldNodes[field.name];
|
||||
|
||||
if (!fieldNode || isMissingVariable(fieldNode.value, variables)) {
|
||||
if (field.defaultValue !== undefined) {
|
||||
coercedObj[field.name] = field.defaultValue;
|
||||
} else if (isNonNullType(field.type)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
var fieldValue = valueFromAST(fieldNode.value, field.type, variables);
|
||||
|
||||
if (isInvalid(fieldValue)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
coercedObj[field.name] = fieldValue;
|
||||
}
|
||||
|
||||
return coercedObj;
|
||||
}
|
||||
|
||||
if (isEnumType(type)) {
|
||||
if (valueNode.kind !== Kind.ENUM) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
var enumValue = type.getValue(valueNode.value);
|
||||
|
||||
if (!enumValue) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
return enumValue.value;
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (isScalarType(type)) {
|
||||
// Scalars fulfill parsing a literal value via parseLiteral().
|
||||
// Invalid values represent a failure to parse correctly, in which case
|
||||
// no value is returned.
|
||||
var result;
|
||||
|
||||
try {
|
||||
result = type.parseLiteral(valueNode, variables);
|
||||
} catch (_error) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
if (isInvalid(result)) {
|
||||
return; // Invalid: intentionally return no value.
|
||||
}
|
||||
|
||||
return result;
|
||||
} // Not reachable. All possible input types have been considered.
|
||||
|
||||
|
||||
/* istanbul ignore next */
|
||||
invariant(false, 'Unexpected input type: ' + inspect(type));
|
||||
} // 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 || isInvalid(variables[valueNode.name.value]));
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user