176 lines
6.5 KiB
JavaScript
176 lines
6.5 KiB
JavaScript
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
import objectEntries from "../polyfills/objectEntries.mjs";
|
|
import { SYMBOL_TO_STRING_TAG } from "../polyfills/symbols.mjs";
|
|
import inspect from "../jsutils/inspect.mjs";
|
|
import toObjMap from "../jsutils/toObjMap.mjs";
|
|
import devAssert from "../jsutils/devAssert.mjs";
|
|
import instanceOf from "../jsutils/instanceOf.mjs";
|
|
import isObjectLike from "../jsutils/isObjectLike.mjs";
|
|
import defineInspect from "../jsutils/defineInspect.mjs";
|
|
import { DirectiveLocation } from "../language/directiveLocation.mjs";
|
|
import { GraphQLString, GraphQLBoolean } from "./scalars.mjs";
|
|
import { argsToArgsConfig, GraphQLNonNull } from "./definition.mjs";
|
|
/**
|
|
* Test if the given value is a GraphQL directive.
|
|
*/
|
|
|
|
// eslint-disable-next-line no-redeclare
|
|
export function isDirective(directive) {
|
|
return instanceOf(directive, GraphQLDirective);
|
|
}
|
|
export function assertDirective(directive) {
|
|
if (!isDirective(directive)) {
|
|
throw new Error("Expected ".concat(inspect(directive), " to be a GraphQL directive."));
|
|
}
|
|
|
|
return directive;
|
|
}
|
|
/**
|
|
* Directives are used by the GraphQL runtime as a way of modifying execution
|
|
* behavior. Type system creators will usually not create these directly.
|
|
*/
|
|
|
|
export var GraphQLDirective = /*#__PURE__*/function () {
|
|
function GraphQLDirective(config) {
|
|
var _config$isRepeatable, _config$args;
|
|
|
|
this.name = config.name;
|
|
this.description = config.description;
|
|
this.locations = config.locations;
|
|
this.isRepeatable = (_config$isRepeatable = config.isRepeatable) !== null && _config$isRepeatable !== void 0 ? _config$isRepeatable : false;
|
|
this.extensions = config.extensions && toObjMap(config.extensions);
|
|
this.astNode = config.astNode;
|
|
config.name || devAssert(0, 'Directive must be named.');
|
|
Array.isArray(config.locations) || devAssert(0, "@".concat(config.name, " locations must be an Array."));
|
|
var args = (_config$args = config.args) !== null && _config$args !== void 0 ? _config$args : {};
|
|
isObjectLike(args) && !Array.isArray(args) || devAssert(0, "@".concat(config.name, " args must be an object with argument names as keys."));
|
|
this.args = objectEntries(args).map(function (_ref) {
|
|
var argName = _ref[0],
|
|
argConfig = _ref[1];
|
|
return {
|
|
name: argName,
|
|
description: argConfig.description,
|
|
type: argConfig.type,
|
|
defaultValue: argConfig.defaultValue,
|
|
deprecationReason: argConfig.deprecationReason,
|
|
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
|
|
astNode: argConfig.astNode
|
|
};
|
|
});
|
|
}
|
|
|
|
var _proto = GraphQLDirective.prototype;
|
|
|
|
_proto.toConfig = function toConfig() {
|
|
return {
|
|
name: this.name,
|
|
description: this.description,
|
|
locations: this.locations,
|
|
args: argsToArgsConfig(this.args),
|
|
isRepeatable: this.isRepeatable,
|
|
extensions: this.extensions,
|
|
astNode: this.astNode
|
|
};
|
|
};
|
|
|
|
_proto.toString = function toString() {
|
|
return '@' + this.name;
|
|
};
|
|
|
|
_proto.toJSON = function toJSON() {
|
|
return this.toString();
|
|
} // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
|
|
;
|
|
|
|
_createClass(GraphQLDirective, [{
|
|
key: SYMBOL_TO_STRING_TAG,
|
|
get: function get() {
|
|
return 'GraphQLDirective';
|
|
}
|
|
}]);
|
|
|
|
return GraphQLDirective;
|
|
}(); // Print a simplified form when appearing in `inspect` and `util.inspect`.
|
|
|
|
defineInspect(GraphQLDirective);
|
|
|
|
/**
|
|
* Used to conditionally include fields or fragments.
|
|
*/
|
|
export var GraphQLIncludeDirective = new GraphQLDirective({
|
|
name: 'include',
|
|
description: 'Directs the executor to include this field or fragment only when the `if` argument is true.',
|
|
locations: [DirectiveLocation.FIELD, DirectiveLocation.FRAGMENT_SPREAD, DirectiveLocation.INLINE_FRAGMENT],
|
|
args: {
|
|
if: {
|
|
type: new GraphQLNonNull(GraphQLBoolean),
|
|
description: 'Included when true.'
|
|
}
|
|
}
|
|
});
|
|
/**
|
|
* Used to conditionally skip (exclude) fields or fragments.
|
|
*/
|
|
|
|
export var GraphQLSkipDirective = new GraphQLDirective({
|
|
name: 'skip',
|
|
description: 'Directs the executor to skip this field or fragment when the `if` argument is true.',
|
|
locations: [DirectiveLocation.FIELD, DirectiveLocation.FRAGMENT_SPREAD, DirectiveLocation.INLINE_FRAGMENT],
|
|
args: {
|
|
if: {
|
|
type: new GraphQLNonNull(GraphQLBoolean),
|
|
description: 'Skipped when true.'
|
|
}
|
|
}
|
|
});
|
|
/**
|
|
* Constant string used for default reason for a deprecation.
|
|
*/
|
|
|
|
export var DEFAULT_DEPRECATION_REASON = 'No longer supported';
|
|
/**
|
|
* Used to declare element of a GraphQL schema as deprecated.
|
|
*/
|
|
|
|
export var GraphQLDeprecatedDirective = new GraphQLDirective({
|
|
name: 'deprecated',
|
|
description: 'Marks an element of a GraphQL schema as no longer supported.',
|
|
locations: [DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.ARGUMENT_DEFINITION, DirectiveLocation.INPUT_FIELD_DEFINITION, DirectiveLocation.ENUM_VALUE],
|
|
args: {
|
|
reason: {
|
|
type: GraphQLString,
|
|
description: 'Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).',
|
|
defaultValue: DEFAULT_DEPRECATION_REASON
|
|
}
|
|
}
|
|
});
|
|
/**
|
|
* Used to provide a URL for specifying the behaviour of custom scalar definitions.
|
|
*/
|
|
|
|
export var GraphQLSpecifiedByDirective = new GraphQLDirective({
|
|
name: 'specifiedBy',
|
|
description: 'Exposes a URL that specifies the behaviour of this scalar.',
|
|
locations: [DirectiveLocation.SCALAR],
|
|
args: {
|
|
url: {
|
|
type: new GraphQLNonNull(GraphQLString),
|
|
description: 'The URL that specifies the behaviour of this scalar.'
|
|
}
|
|
}
|
|
});
|
|
/**
|
|
* The full list of specified directives.
|
|
*/
|
|
|
|
export var specifiedDirectives = Object.freeze([GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDeprecatedDirective, GraphQLSpecifiedByDirective]);
|
|
export function isSpecifiedDirective(directive) {
|
|
return specifiedDirectives.some(function (_ref2) {
|
|
var name = _ref2.name;
|
|
return name === directive.name;
|
|
});
|
|
}
|