diff --git a/dist/vue-apollo.esm.js b/dist/vue-apollo.esm.js index 97afbdd6..b3eb6e16 100644 --- a/dist/vue-apollo.esm.js +++ b/dist/vue-apollo.esm.js @@ -1,3 +1,5 @@ +import gql from 'graphql-tag'; + function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { @@ -49,20 +51,35 @@ function _defineProperty(obj, key, value) { return obj; } -function _objectSpread(target) { +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 _objectSpread2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; - var ownKeys = Object.keys(source); - if (typeof Object.getOwnPropertySymbols === 'function') { - ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { - return Object.getOwnPropertyDescriptor(source, sym).enumerable; - })); + 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)); + }); } - - ownKeys.forEach(function (key) { - _defineProperty(target, key, source[key]); - }); } return target; @@ -170,6 +187,10 @@ function _iterableToArray(iter) { } function _iterableToArrayLimit(arr, i) { + if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { + return; + } + var _arr = []; var _n = true; var _d = false; @@ -207,10 +228,6 @@ function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } -function getCjsExportFromNamespace (n) { - return n && n['default'] || n; -} - /* eslint-disable no-undefined,no-param-reassign,no-shadow */ /** @@ -425,6 +442,7 @@ function () { this.initialOptions = options; this.options = Object.assign({}, options); this._skip = false; + this._pollInterval = null; this._watchers = []; this._destroyed = false; @@ -446,6 +464,25 @@ function () { } else { this._skip = true; } + + if (typeof this.options.pollInterval === 'function') { + this._pollWatcher = this.vm.$watch(this.options.pollInterval.bind(this.vm), this.pollIntervalChanged.bind(this), { + immediate: true + }); + } + } + }, { + key: "pollIntervalChanged", + value: function pollIntervalChanged(value, oldValue) { + if (value !== oldValue) { + this.pollInterval = value; + + if (value == null) { + this.stopPolling(); + } else { + this.startPolling(value); + } + } } }, { key: "skipChanged", @@ -671,6 +708,14 @@ function () { this._skipWatcher(); } } + }, { + key: "pollInterval", + get: function get() { + return this._pollInterval; + }, + set: function set(value) { + this._pollInterval = value; + } }, { key: "skip", get: function get() { @@ -1179,11 +1224,6 @@ function () { } _createClass(DollarApollo, [{ - key: "query", - value: function query(options) { - return this.getClient(options).query(options); - } - }, { key: "getClient", value: function getClient() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; @@ -1218,6 +1258,11 @@ function () { return client; } + }, { + key: "query", + value: function query(options) { + return this.getClient(options).query(options); + } }, { key: "watchQuery", value: function watchQuery(options) { @@ -1302,12 +1347,12 @@ function () { if (subs) { if (Array.isArray(subs)) { subs.forEach(function (sub, index) { - _this3.addSmartSubscription("".concat(key).concat(index), _objectSpread({}, sub, { + _this3.addSmartSubscription("".concat(key).concat(index), _objectSpread2({}, sub, { linkedQuery: smart })); }); } else { - this.addSmartSubscription(key, _objectSpread({}, subs, { + this.addSmartSubscription(key, _objectSpread2({}, subs, { linkedQuery: smart })); } @@ -1435,7 +1480,7 @@ function () { this.defaultOptions = options.defaultOptions; this.watchLoading = options.watchLoading; this.errorHandler = options.errorHandler; - this.prefetchQueries = []; + this.prefetch = options.prefetch; } _createClass(ApolloProvider, [{ @@ -1450,3120 +1495,6 @@ function () { return ApolloProvider; }(); -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ -var nodejsCustomInspectSymbol = typeof Symbol === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined; - -function _typeof$1(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); } -var MAX_ARRAY_LENGTH = 10; -var MAX_RECURSIVE_DEPTH = 2; -/** - * Used to print values in error messages. - */ - -function inspect(value) { - return formatValue(value, []); -} - -function formatValue(value, seenValues) { - switch (_typeof$1(value)) { - case 'string': - return JSON.stringify(value); - - case 'function': - return value.name ? "[function ".concat(value.name, "]") : '[function]'; - - case 'object': - return formatObjectValue(value, seenValues); - - default: - return String(value); - } -} - -function formatObjectValue(value, previouslySeenValues) { - if (previouslySeenValues.indexOf(value) !== -1) { - return '[Circular]'; - } - - var seenValues = [].concat(previouslySeenValues, [value]); - - if (value) { - var customInspectFn = getCustomFn(value); - - if (customInspectFn !== undefined) { - // $FlowFixMe(>=0.90.0) - var customValue = customInspectFn.call(value); // check for infinite recursion - - if (customValue !== value) { - return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues); - } - } else if (Array.isArray(value)) { - return formatArray(value, seenValues); - } - - return formatObject(value, seenValues); - } - - return String(value); -} - -function formatObject(object, seenValues) { - var keys = Object.keys(object); - - if (keys.length === 0) { - return '{}'; - } - - if (seenValues.length > MAX_RECURSIVE_DEPTH) { - return '[' + getObjectTag(object) + ']'; - } - - var properties = keys.map(function (key) { - var value = formatValue(object[key], seenValues); - return key + ': ' + value; - }); - return '{ ' + properties.join(', ') + ' }'; -} - -function formatArray(array, seenValues) { - if (array.length === 0) { - return '[]'; - } - - if (seenValues.length > MAX_RECURSIVE_DEPTH) { - return '[Array]'; - } - - var len = Math.min(MAX_ARRAY_LENGTH, array.length); - var remaining = array.length - len; - var items = []; - - for (var i = 0; i < len; ++i) { - items.push(formatValue(array[i], seenValues)); - } - - if (remaining === 1) { - items.push('... 1 more item'); - } else if (remaining > 1) { - items.push("... ".concat(remaining, " more items")); - } - - return '[' + items.join(', ') + ']'; -} - -function getCustomFn(object) { - var customInspectFn = object[String(nodejsCustomInspectSymbol)]; - - if (typeof customInspectFn === 'function') { - return customInspectFn; - } - - if (typeof object.inspect === 'function') { - return object.inspect; - } -} - -function getObjectTag(object) { - var tag = Object.prototype.toString.call(object).replace(/^\[object /, '').replace(/]$/, ''); - - if (tag === 'Object' && typeof object.constructor === 'function') { - var name = object.constructor.name; - - if (typeof name === 'string') { - return name; - } - } - - return tag; -} - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ -/** - * The `defineToJSON()` function defines toJSON() and inspect() prototype - * methods, if no function provided they become aliases for toString(). - */ - -function defineToJSON( // eslint-disable-next-line flowtype/no-weak-types -classObject) { - var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : classObject.prototype.toString; - classObject.prototype.toJSON = fn; - classObject.prototype.inspect = fn; - - if (nodejsCustomInspectSymbol) { - classObject.prototype[nodejsCustomInspectSymbol] = fn; - } -} - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ -function invariant(condition, message) { - var booleanCondition = Boolean(condition); - /* istanbul ignore else */ - - if (!booleanCondition) { - throw new Error(message); - } -} - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * The `defineToStringTag()` function checks first to see if the runtime - * supports the `Symbol` class and then if the `Symbol.toStringTag` constant - * is defined as a `Symbol` instance. If both conditions are met, the - * Symbol.toStringTag property is defined as a getter that returns the - * supplied class constructor's name. - * - * @method defineToStringTag - * - * @param {Class} classObject a class such as Object, String, Number but - * typically one of your own creation through the class keyword; `class A {}`, - * for example. - */ -function defineToStringTag(classObject) { - if (typeof Symbol === 'function' && Symbol.toStringTag) { - Object.defineProperty(classObject.prototype, Symbol.toStringTag, { - get: function get() { - return this.constructor.name; - } - }); - } -} - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * A representation of source input to GraphQL. - * `name` and `locationOffset` are optional. They are useful for clients who - * store GraphQL documents in source files; for example, if the GraphQL input - * starts at line 40 in a file named Foo.graphql, it might be useful for name to - * be "Foo.graphql" and location to be `{ line: 40, column: 0 }`. - * line and column in locationOffset are 1-indexed - */ -var Source = function Source(body, name, locationOffset) { - this.body = body; - this.name = name || 'GraphQL request'; - this.locationOffset = locationOffset || { - line: 1, - column: 1 - }; - !(this.locationOffset.line > 0) ? invariant(0, 'line in locationOffset is 1-indexed and must be positive') : void 0; - !(this.locationOffset.column > 0) ? invariant(0, 'column in locationOffset is 1-indexed and must be positive') : void 0; -}; // Conditionally apply `[Symbol.toStringTag]` if `Symbol`s are supported - -defineToStringTag(Source); - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * Represents a location in a Source. - */ - -/** - * Takes a Source and a UTF-8 character offset, and returns the corresponding - * line and column as a SourceLocation. - */ -function getLocation(source, position) { - var lineRegexp = /\r\n|[\n\r]/g; - var line = 1; - var column = position + 1; - var match; - - while ((match = lineRegexp.exec(source.body)) && match.index < position) { - line += 1; - column = position + 1 - (match.index + match[0].length); - } - - return { - line: line, - column: column - }; -} - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * Prints a GraphQLError to a string, representing useful location information - * about the error's position in the source. - */ -function printError(error) { - var printedLocations = []; - - if (error.nodes) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = error.nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var node = _step.value; - - if (node.loc) { - printedLocations.push(highlightSourceAtLocation(node.loc.source, getLocation(node.loc.source, node.loc.start))); - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - } else if (error.source && error.locations) { - var source = error.source; - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = error.locations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var location = _step2.value; - printedLocations.push(highlightSourceAtLocation(source, location)); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2.return != null) { - _iterator2.return(); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - } - - return printedLocations.length === 0 ? error.message : [error.message].concat(printedLocations).join('\n\n') + '\n'; -} -/** - * Render a helpful description of the location of the error in the GraphQL - * Source document. - */ - -function highlightSourceAtLocation(source, location) { - var firstLineColumnOffset = source.locationOffset.column - 1; - var body = whitespace(firstLineColumnOffset) + source.body; - var lineIndex = location.line - 1; - var lineOffset = source.locationOffset.line - 1; - var lineNum = location.line + lineOffset; - var columnOffset = location.line === 1 ? firstLineColumnOffset : 0; - var columnNum = location.column + columnOffset; - var lines = body.split(/\r\n|[\n\r]/g); - return "".concat(source.name, " (").concat(lineNum, ":").concat(columnNum, ")\n") + printPrefixedLines([// Lines specified like this: ["prefix", "string"], - ["".concat(lineNum - 1, ": "), lines[lineIndex - 1]], ["".concat(lineNum, ": "), lines[lineIndex]], ['', whitespace(columnNum - 1) + '^'], ["".concat(lineNum + 1, ": "), lines[lineIndex + 1]]]); -} - -function printPrefixedLines(lines) { - var existingLines = lines.filter(function (_ref) { - var _ = _ref[0], - line = _ref[1]; - return line !== undefined; - }); - var padLen = 0; - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = existingLines[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var _ref4 = _step3.value; - var prefix = _ref4[0]; - padLen = Math.max(padLen, prefix.length); - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3.return != null) { - _iterator3.return(); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - return existingLines.map(function (_ref3) { - var prefix = _ref3[0], - line = _ref3[1]; - return lpad(padLen, prefix) + line; - }).join('\n'); -} - -function whitespace(len) { - return Array(len + 1).join(' '); -} - -function lpad(len, str) { - return whitespace(len - str.length) + str; -} - -function _typeof$2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); } -/** - * A GraphQLError describes an Error found during the parse, validate, or - * execute phases of performing a GraphQL operation. In addition to a message - * and stack trace, it also includes information about the locations in a - * GraphQL document and/or execution result that correspond to the Error. - */ - -function GraphQLError( // eslint-disable-line no-redeclare -message, nodes, source, positions, path, originalError, extensions) { - // Compute list of blame nodes. - var _nodes = Array.isArray(nodes) ? nodes.length !== 0 ? nodes : undefined : nodes ? [nodes] : undefined; // Compute locations in the source for the given nodes/positions. - - - var _source = source; - - if (!_source && _nodes) { - var node = _nodes[0]; - _source = node && node.loc && node.loc.source; - } - - var _positions = positions; - - if (!_positions && _nodes) { - _positions = _nodes.reduce(function (list, node) { - if (node.loc) { - list.push(node.loc.start); - } - - return list; - }, []); - } - - if (_positions && _positions.length === 0) { - _positions = undefined; - } - - var _locations; - - if (positions && source) { - _locations = positions.map(function (pos) { - return getLocation(source, pos); - }); - } else if (_nodes) { - _locations = _nodes.reduce(function (list, node) { - if (node.loc) { - list.push(getLocation(node.loc.source, node.loc.start)); - } - - return list; - }, []); - } - - var _extensions = extensions; - - if (_extensions == null && originalError != null) { - var originalExtensions = originalError.extensions; - - if (originalExtensions != null && _typeof$2(originalExtensions) === 'object') { - _extensions = originalExtensions; - } - } - - Object.defineProperties(this, { - message: { - value: message, - // By being enumerable, JSON.stringify will include `message` in the - // resulting output. This ensures that the simplest possible GraphQL - // service adheres to the spec. - enumerable: true, - writable: true - }, - locations: { - // Coercing falsey values to undefined ensures they will not be included - // in JSON.stringify() when not provided. - value: _locations || undefined, - // By being enumerable, JSON.stringify will include `locations` in the - // resulting output. This ensures that the simplest possible GraphQL - // service adheres to the spec. - enumerable: Boolean(_locations) - }, - path: { - // Coercing falsey values to undefined ensures they will not be included - // in JSON.stringify() when not provided. - value: path || undefined, - // By being enumerable, JSON.stringify will include `path` in the - // resulting output. This ensures that the simplest possible GraphQL - // service adheres to the spec. - enumerable: Boolean(path) - }, - nodes: { - value: _nodes || undefined - }, - source: { - value: _source || undefined - }, - positions: { - value: _positions || undefined - }, - originalError: { - value: originalError - }, - extensions: { - // Coercing falsey values to undefined ensures they will not be included - // in JSON.stringify() when not provided. - value: _extensions || undefined, - // By being enumerable, JSON.stringify will include `path` in the - // resulting output. This ensures that the simplest possible GraphQL - // service adheres to the spec. - enumerable: Boolean(_extensions) - } - }); // Include (non-enumerable) stack trace. - - if (originalError && originalError.stack) { - Object.defineProperty(this, 'stack', { - value: originalError.stack, - writable: true, - configurable: true - }); - } else if (Error.captureStackTrace) { - Error.captureStackTrace(this, GraphQLError); - } else { - Object.defineProperty(this, 'stack', { - value: Error().stack, - writable: true, - configurable: true - }); - } -} -GraphQLError.prototype = Object.create(Error.prototype, { - constructor: { - value: GraphQLError - }, - name: { - value: 'GraphQLError' - }, - toString: { - value: function toString() { - return printError(this); - } - } -}); - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ -/** - * Produces a GraphQLError representing a syntax error, containing useful - * descriptive information about the syntax error's position in the source. - */ - -function syntaxError(source, position, description) { - return new GraphQLError("Syntax Error: ".concat(description), undefined, source, [position]); -} - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * Produces the value of a block string from its parsed raw value, similar to - * CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc. - * - * This implements the GraphQL spec's BlockStringValue() static algorithm. - */ -function dedentBlockStringValue(rawString) { - // Expand a block string's raw value into independent lines. - var lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first. - - var commonIndent = getBlockStringIndentation(lines); - - if (commonIndent !== 0) { - for (var i = 1; i < lines.length; i++) { - lines[i] = lines[i].slice(commonIndent); - } - } // Remove leading and trailing blank lines. - - - while (lines.length > 0 && isBlank(lines[0])) { - lines.shift(); - } - - while (lines.length > 0 && isBlank(lines[lines.length - 1])) { - lines.pop(); - } // Return a string of the lines joined with U+000A. - - - return lines.join('\n'); -} // @internal - -function getBlockStringIndentation(lines) { - var commonIndent = null; - - for (var i = 1; i < lines.length; i++) { - var line = lines[i]; - var indent = leadingWhitespace(line); - - if (indent === line.length) { - continue; // skip empty lines - } - - if (commonIndent === null || indent < commonIndent) { - commonIndent = indent; - - if (commonIndent === 0) { - break; - } - } - } - - return commonIndent === null ? 0 : commonIndent; -} - -function leadingWhitespace(str) { - var i = 0; - - while (i < str.length && (str[i] === ' ' || str[i] === '\t')) { - i++; - } - - return i; -} - -function isBlank(str) { - return leadingWhitespace(str) === str.length; -} - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ -/** - * Given a Source object, this returns a Lexer for that source. - * A Lexer is a stateful stream generator in that every time - * it is advanced, it returns the next token in the Source. Assuming the - * source lexes, the final Token emitted by the lexer will be of kind - * EOF, after which the lexer will repeatedly return the same EOF token - * whenever called. - */ - -function createLexer(source, options) { - var startOfFileToken = new Tok(TokenKind.SOF, 0, 0, 0, 0, null); - var lexer = { - source: source, - options: options, - lastToken: startOfFileToken, - token: startOfFileToken, - line: 1, - lineStart: 0, - advance: advanceLexer, - lookahead: lookahead - }; - return lexer; -} - -function advanceLexer() { - this.lastToken = this.token; - var token = this.token = this.lookahead(); - return token; -} - -function lookahead() { - var token = this.token; - - if (token.kind !== TokenKind.EOF) { - do { - // Note: next is only mutable during parsing, so we cast to allow this. - token = token.next || (token.next = readToken(this, token)); - } while (token.kind === TokenKind.COMMENT); - } - - return token; -} -/** - * The return type of createLexer. - */ - - -/** - * An exported enum describing the different kinds of tokens that the - * lexer emits. - */ -var TokenKind = Object.freeze({ - SOF: '', - EOF: '', - BANG: '!', - DOLLAR: '$', - AMP: '&', - PAREN_L: '(', - PAREN_R: ')', - SPREAD: '...', - COLON: ':', - EQUALS: '=', - AT: '@', - BRACKET_L: '[', - BRACKET_R: ']', - BRACE_L: '{', - PIPE: '|', - BRACE_R: '}', - NAME: 'Name', - INT: 'Int', - FLOAT: 'Float', - STRING: 'String', - BLOCK_STRING: 'BlockString', - COMMENT: 'Comment' -}); -/** - * A helper function to describe a token as a string for debugging - */ - -function getTokenDesc(token) { - var value = token.value; - return value ? "".concat(token.kind, " \"").concat(value, "\"") : token.kind; -} -/** - * Helper function for constructing the Token object. - */ - -function Tok(kind, start, end, line, column, prev, value) { - this.kind = kind; - this.start = start; - this.end = end; - this.line = line; - this.column = column; - this.value = value; - this.prev = prev; - this.next = null; -} // Print a simplified form when appearing in JSON/util.inspect. - - -defineToJSON(Tok, function () { - return { - kind: this.kind, - value: this.value, - line: this.line, - column: this.column - }; -}); - -function printCharCode(code) { - return (// NaN/undefined represents access beyond the end of the file. - isNaN(code) ? TokenKind.EOF : // Trust JSON for ASCII. - code < 0x007f ? JSON.stringify(String.fromCharCode(code)) : // Otherwise print the escaped form. - "\"\\u".concat(('00' + code.toString(16).toUpperCase()).slice(-4), "\"") - ); -} -/** - * Gets the next token from the source starting at the given position. - * - * This skips over whitespace until it finds the next lexable token, then lexes - * punctuators immediately or calls the appropriate helper function for more - * complicated tokens. - */ - - -function readToken(lexer, prev) { - var source = lexer.source; - var body = source.body; - var bodyLength = body.length; - var pos = positionAfterWhitespace(body, prev.end, lexer); - var line = lexer.line; - var col = 1 + pos - lexer.lineStart; - - if (pos >= bodyLength) { - return new Tok(TokenKind.EOF, bodyLength, bodyLength, line, col, prev); - } - - var code = body.charCodeAt(pos); // SourceCharacter - - switch (code) { - // ! - case 33: - return new Tok(TokenKind.BANG, pos, pos + 1, line, col, prev); - // # - - case 35: - return readComment(source, pos, line, col, prev); - // $ - - case 36: - return new Tok(TokenKind.DOLLAR, pos, pos + 1, line, col, prev); - // & - - case 38: - return new Tok(TokenKind.AMP, pos, pos + 1, line, col, prev); - // ( - - case 40: - return new Tok(TokenKind.PAREN_L, pos, pos + 1, line, col, prev); - // ) - - case 41: - return new Tok(TokenKind.PAREN_R, pos, pos + 1, line, col, prev); - // . - - case 46: - if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) { - return new Tok(TokenKind.SPREAD, pos, pos + 3, line, col, prev); - } - - break; - // : - - case 58: - return new Tok(TokenKind.COLON, pos, pos + 1, line, col, prev); - // = - - case 61: - return new Tok(TokenKind.EQUALS, pos, pos + 1, line, col, prev); - // @ - - case 64: - return new Tok(TokenKind.AT, pos, pos + 1, line, col, prev); - // [ - - case 91: - return new Tok(TokenKind.BRACKET_L, pos, pos + 1, line, col, prev); - // ] - - case 93: - return new Tok(TokenKind.BRACKET_R, pos, pos + 1, line, col, prev); - // { - - case 123: - return new Tok(TokenKind.BRACE_L, pos, pos + 1, line, col, prev); - // | - - case 124: - return new Tok(TokenKind.PIPE, pos, pos + 1, line, col, prev); - // } - - case 125: - return new Tok(TokenKind.BRACE_R, pos, pos + 1, line, col, prev); - // A-Z _ a-z - - case 65: - case 66: - case 67: - case 68: - case 69: - case 70: - case 71: - case 72: - case 73: - case 74: - case 75: - case 76: - case 77: - case 78: - case 79: - case 80: - case 81: - case 82: - case 83: - case 84: - case 85: - case 86: - case 87: - case 88: - case 89: - case 90: - case 95: - case 97: - case 98: - case 99: - case 100: - case 101: - case 102: - case 103: - case 104: - case 105: - case 106: - case 107: - case 108: - case 109: - case 110: - case 111: - case 112: - case 113: - case 114: - case 115: - case 116: - case 117: - case 118: - case 119: - case 120: - case 121: - case 122: - return readName(source, pos, line, col, prev); - // - 0-9 - - case 45: - case 48: - case 49: - case 50: - case 51: - case 52: - case 53: - case 54: - case 55: - case 56: - case 57: - return readNumber(source, pos, code, line, col, prev); - // " - - case 34: - if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) { - return readBlockString(source, pos, line, col, prev, lexer); - } - - return readString(source, pos, line, col, prev); - } - - throw syntaxError(source, pos, unexpectedCharacterMessage(code)); -} -/** - * Report a message that an unexpected character was encountered. - */ - - -function unexpectedCharacterMessage(code) { - if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) { - return "Cannot contain the invalid character ".concat(printCharCode(code), "."); - } - - if (code === 39) { - // ' - return "Unexpected single quote character ('), did you mean to use " + 'a double quote (")?'; - } - - return "Cannot parse the unexpected character ".concat(printCharCode(code), "."); -} -/** - * Reads from body starting at startPosition until it finds a non-whitespace - * character, then returns the position of that character for lexing. - */ - - -function positionAfterWhitespace(body, startPosition, lexer) { - var bodyLength = body.length; - var position = startPosition; - - while (position < bodyLength) { - var code = body.charCodeAt(position); // tab | space | comma | BOM - - if (code === 9 || code === 32 || code === 44 || code === 0xfeff) { - ++position; - } else if (code === 10) { - // new line - ++position; - ++lexer.line; - lexer.lineStart = position; - } else if (code === 13) { - // carriage return - if (body.charCodeAt(position + 1) === 10) { - position += 2; - } else { - ++position; - } - - ++lexer.line; - lexer.lineStart = position; - } else { - break; - } - } - - return position; -} -/** - * Reads a comment token from the source file. - * - * #[\u0009\u0020-\uFFFF]* - */ - - -function readComment(source, start, line, col, prev) { - var body = source.body; - var code; - var position = start; - - do { - code = body.charCodeAt(++position); - } while (!isNaN(code) && ( // SourceCharacter but not LineTerminator - code > 0x001f || code === 0x0009)); - - return new Tok(TokenKind.COMMENT, start, position, line, col, prev, body.slice(start + 1, position)); -} -/** - * Reads a number token from the source file, either a float - * or an int depending on whether a decimal point appears. - * - * Int: -?(0|[1-9][0-9]*) - * Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)? - */ - - -function readNumber(source, start, firstCode, line, col, prev) { - var body = source.body; - var code = firstCode; - var position = start; - var isFloat = false; - - if (code === 45) { - // - - code = body.charCodeAt(++position); - } - - if (code === 48) { - // 0 - code = body.charCodeAt(++position); - - if (code >= 48 && code <= 57) { - throw syntaxError(source, position, "Invalid number, unexpected digit after 0: ".concat(printCharCode(code), ".")); - } - } else { - position = readDigits(source, position, code); - code = body.charCodeAt(position); - } - - if (code === 46) { - // . - isFloat = true; - code = body.charCodeAt(++position); - position = readDigits(source, position, code); - code = body.charCodeAt(position); - } - - if (code === 69 || code === 101) { - // E e - isFloat = true; - code = body.charCodeAt(++position); - - if (code === 43 || code === 45) { - // + - - code = body.charCodeAt(++position); - } - - position = readDigits(source, position, code); - } - - return new Tok(isFloat ? TokenKind.FLOAT : TokenKind.INT, start, position, line, col, prev, body.slice(start, position)); -} -/** - * Returns the new position in the source after reading digits. - */ - - -function readDigits(source, start, firstCode) { - var body = source.body; - var position = start; - var code = firstCode; - - if (code >= 48 && code <= 57) { - // 0 - 9 - do { - code = body.charCodeAt(++position); - } while (code >= 48 && code <= 57); // 0 - 9 - - - return position; - } - - throw syntaxError(source, position, "Invalid number, expected digit but got: ".concat(printCharCode(code), ".")); -} -/** - * Reads a string token from the source file. - * - * "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*" - */ - - -function readString(source, start, line, col, prev) { - var body = source.body; - var position = start + 1; - var chunkStart = position; - var code = 0; - var value = ''; - - while (position < body.length && !isNaN(code = body.charCodeAt(position)) && // not LineTerminator - code !== 0x000a && code !== 0x000d) { - // Closing Quote (") - if (code === 34) { - value += body.slice(chunkStart, position); - return new Tok(TokenKind.STRING, start, position + 1, line, col, prev, value); - } // SourceCharacter - - - if (code < 0x0020 && code !== 0x0009) { - throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), ".")); - } - - ++position; - - if (code === 92) { - // \ - value += body.slice(chunkStart, position - 1); - code = body.charCodeAt(position); - - switch (code) { - case 34: - value += '"'; - break; - - case 47: - value += '/'; - break; - - case 92: - value += '\\'; - break; - - case 98: - value += '\b'; - break; - - case 102: - value += '\f'; - break; - - case 110: - value += '\n'; - break; - - case 114: - value += '\r'; - break; - - case 116: - value += '\t'; - break; - - case 117: - { - // uXXXX - var charCode = uniCharCode(body.charCodeAt(position + 1), body.charCodeAt(position + 2), body.charCodeAt(position + 3), body.charCodeAt(position + 4)); - - if (charCode < 0) { - throw syntaxError(source, position, 'Invalid character escape sequence: ' + "\\u".concat(body.slice(position + 1, position + 5), ".")); - } - - value += String.fromCharCode(charCode); - position += 4; - break; - } - - default: - throw syntaxError(source, position, "Invalid character escape sequence: \\".concat(String.fromCharCode(code), ".")); - } - - ++position; - chunkStart = position; - } - } - - throw syntaxError(source, position, 'Unterminated string.'); -} -/** - * Reads a block string token from the source file. - * - * """("?"?(\\"""|\\(?!=""")|[^"\\]))*""" - */ - - -function readBlockString(source, start, line, col, prev, lexer) { - var body = source.body; - var position = start + 3; - var chunkStart = position; - var code = 0; - var rawValue = ''; - - while (position < body.length && !isNaN(code = body.charCodeAt(position))) { - // Closing Triple-Quote (""") - if (code === 34 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34) { - rawValue += body.slice(chunkStart, position); - return new Tok(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, dedentBlockStringValue(rawValue)); - } // SourceCharacter - - - if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) { - throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), ".")); - } - - if (code === 10) { - // new line - ++position; - ++lexer.line; - lexer.lineStart = position; - } else if (code === 13) { - // carriage return - if (body.charCodeAt(position + 1) === 10) { - position += 2; - } else { - ++position; - } - - ++lexer.line; - lexer.lineStart = position; - } else if ( // Escape Triple-Quote (\""") - code === 92 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34 && body.charCodeAt(position + 3) === 34) { - rawValue += body.slice(chunkStart, position) + '"""'; - position += 4; - chunkStart = position; - } else { - ++position; - } - } - - throw syntaxError(source, position, 'Unterminated string.'); -} -/** - * Converts four hexadecimal chars to the integer that the - * string represents. For example, uniCharCode('0','0','0','f') - * will return 15, and uniCharCode('0','0','f','f') returns 255. - * - * Returns a negative number on error, if a char was invalid. - * - * This is implemented by noting that char2hex() returns -1 on error, - * which means the result of ORing the char2hex() will also be negative. - */ - - -function uniCharCode(a, b, c, d) { - return char2hex(a) << 12 | char2hex(b) << 8 | char2hex(c) << 4 | char2hex(d); -} -/** - * Converts a hex character to its integer value. - * '0' becomes 0, '9' becomes 9 - * 'A' becomes 10, 'F' becomes 15 - * 'a' becomes 10, 'f' becomes 15 - * - * Returns -1 on error. - */ - - -function char2hex(a) { - return a >= 48 && a <= 57 ? a - 48 // 0-9 - : a >= 65 && a <= 70 ? a - 55 // A-F - : a >= 97 && a <= 102 ? a - 87 // a-f - : -1; -} -/** - * Reads an alphanumeric + underscore name from the source. - * - * [_A-Za-z][_0-9A-Za-z]* - */ - - -function readName(source, start, line, col, prev) { - var body = source.body; - var bodyLength = body.length; - var position = start + 1; - var code = 0; - - while (position !== bodyLength && !isNaN(code = body.charCodeAt(position)) && (code === 95 || // _ - code >= 48 && code <= 57 || // 0-9 - code >= 65 && code <= 90 || // A-Z - code >= 97 && code <= 122) // a-z - ) { - ++position; - } - - return new Tok(TokenKind.NAME, start, position, line, col, prev, body.slice(start, position)); -} - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * The set of allowed kind values for AST nodes. - */ -var Kind = Object.freeze({ - // Name - NAME: 'Name', - // Document - DOCUMENT: 'Document', - OPERATION_DEFINITION: 'OperationDefinition', - VARIABLE_DEFINITION: 'VariableDefinition', - SELECTION_SET: 'SelectionSet', - FIELD: 'Field', - ARGUMENT: 'Argument', - // Fragments - FRAGMENT_SPREAD: 'FragmentSpread', - INLINE_FRAGMENT: 'InlineFragment', - FRAGMENT_DEFINITION: 'FragmentDefinition', - // Values - VARIABLE: 'Variable', - INT: 'IntValue', - FLOAT: 'FloatValue', - STRING: 'StringValue', - BOOLEAN: 'BooleanValue', - NULL: 'NullValue', - ENUM: 'EnumValue', - LIST: 'ListValue', - OBJECT: 'ObjectValue', - OBJECT_FIELD: 'ObjectField', - // Directives - DIRECTIVE: 'Directive', - // Types - NAMED_TYPE: 'NamedType', - LIST_TYPE: 'ListType', - NON_NULL_TYPE: 'NonNullType', - // Type System Definitions - SCHEMA_DEFINITION: 'SchemaDefinition', - OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition', - // Type Definitions - SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition', - OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition', - FIELD_DEFINITION: 'FieldDefinition', - INPUT_VALUE_DEFINITION: 'InputValueDefinition', - INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition', - UNION_TYPE_DEFINITION: 'UnionTypeDefinition', - ENUM_TYPE_DEFINITION: 'EnumTypeDefinition', - ENUM_VALUE_DEFINITION: 'EnumValueDefinition', - INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition', - // Directive Definitions - DIRECTIVE_DEFINITION: 'DirectiveDefinition', - // Type System Extensions - SCHEMA_EXTENSION: 'SchemaExtension', - // Type Extensions - SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension', - OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension', - INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension', - UNION_TYPE_EXTENSION: 'UnionTypeExtension', - ENUM_TYPE_EXTENSION: 'EnumTypeExtension', - INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension' -}); -/** - * The enum type representing the possible kind values of AST nodes. - */ - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -/** - * The set of allowed directive location values. - */ -var DirectiveLocation = Object.freeze({ - // Request Definitions - QUERY: 'QUERY', - MUTATION: 'MUTATION', - SUBSCRIPTION: 'SUBSCRIPTION', - FIELD: 'FIELD', - FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION', - FRAGMENT_SPREAD: 'FRAGMENT_SPREAD', - INLINE_FRAGMENT: 'INLINE_FRAGMENT', - VARIABLE_DEFINITION: 'VARIABLE_DEFINITION', - // Type System Definitions - SCHEMA: 'SCHEMA', - SCALAR: 'SCALAR', - OBJECT: 'OBJECT', - FIELD_DEFINITION: 'FIELD_DEFINITION', - ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION', - INTERFACE: 'INTERFACE', - UNION: 'UNION', - ENUM: 'ENUM', - ENUM_VALUE: 'ENUM_VALUE', - INPUT_OBJECT: 'INPUT_OBJECT', - INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION' -}); -/** - * The enum type representing the directive location values. - */ - -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ -/** - * Configuration options to control parser behavior - */ - -/** - * Given a GraphQL source, parses it into a Document. - * Throws GraphQLError if a syntax error is encountered. - */ -function parse(source, options) { - var sourceObj = typeof source === 'string' ? new Source(source) : source; - - if (!(sourceObj instanceof Source)) { - throw new TypeError("Must provide Source. Received: ".concat(inspect(sourceObj))); - } - - var lexer = createLexer(sourceObj, options || {}); - return parseDocument(lexer); -} -/** - * Given a string containing a GraphQL value (ex. `[42]`), parse the AST for - * that value. - * Throws GraphQLError if a syntax error is encountered. - * - * This is useful within tools that operate upon GraphQL Values directly and - * in isolation of complete GraphQL documents. - * - * Consider providing the results to the utility function: valueFromAST(). - */ - -function parseValue(source, options) { - var sourceObj = typeof source === 'string' ? new Source(source) : source; - var lexer = createLexer(sourceObj, options || {}); - expectToken(lexer, TokenKind.SOF); - var value = parseValueLiteral(lexer, false); - expectToken(lexer, TokenKind.EOF); - return value; -} -/** - * Given a string containing a GraphQL Type (ex. `[Int!]`), parse the AST for - * that type. - * Throws GraphQLError if a syntax error is encountered. - * - * This is useful within tools that operate upon GraphQL Types directly and - * in isolation of complete GraphQL documents. - * - * Consider providing the results to the utility function: typeFromAST(). - */ - -function parseType(source, options) { - var sourceObj = typeof source === 'string' ? new Source(source) : source; - var lexer = createLexer(sourceObj, options || {}); - expectToken(lexer, TokenKind.SOF); - var type = parseTypeReference(lexer); - expectToken(lexer, TokenKind.EOF); - return type; -} -/** - * Converts a name lex token into a name parse node. - */ - -function parseName(lexer) { - var token = expectToken(lexer, TokenKind.NAME); - return { - kind: Kind.NAME, - value: token.value, - loc: loc(lexer, token) - }; -} // Implements the parsing rules in the Document section. - -/** - * Document : Definition+ - */ - - -function parseDocument(lexer) { - var start = lexer.token; - return { - kind: Kind.DOCUMENT, - definitions: many(lexer, TokenKind.SOF, parseDefinition, TokenKind.EOF), - loc: loc(lexer, start) - }; -} -/** - * Definition : - * - ExecutableDefinition - * - TypeSystemDefinition - * - TypeSystemExtension - */ - - -function parseDefinition(lexer) { - if (peek(lexer, TokenKind.NAME)) { - switch (lexer.token.value) { - case 'query': - case 'mutation': - case 'subscription': - case 'fragment': - return parseExecutableDefinition(lexer); - - case 'schema': - case 'scalar': - case 'type': - case 'interface': - case 'union': - case 'enum': - case 'input': - case 'directive': - return parseTypeSystemDefinition(lexer); - - case 'extend': - return parseTypeSystemExtension(lexer); - } - } else if (peek(lexer, TokenKind.BRACE_L)) { - return parseExecutableDefinition(lexer); - } else if (peekDescription(lexer)) { - return parseTypeSystemDefinition(lexer); - } - - throw unexpected(lexer); -} -/** - * ExecutableDefinition : - * - OperationDefinition - * - FragmentDefinition - */ - - -function parseExecutableDefinition(lexer) { - if (peek(lexer, TokenKind.NAME)) { - switch (lexer.token.value) { - case 'query': - case 'mutation': - case 'subscription': - return parseOperationDefinition(lexer); - - case 'fragment': - return parseFragmentDefinition(lexer); - } - } else if (peek(lexer, TokenKind.BRACE_L)) { - return parseOperationDefinition(lexer); - } - - throw unexpected(lexer); -} // Implements the parsing rules in the Operations section. - -/** - * OperationDefinition : - * - SelectionSet - * - OperationType Name? VariableDefinitions? Directives? SelectionSet - */ - - -function parseOperationDefinition(lexer) { - var start = lexer.token; - - if (peek(lexer, TokenKind.BRACE_L)) { - return { - kind: Kind.OPERATION_DEFINITION, - operation: 'query', - name: undefined, - variableDefinitions: [], - directives: [], - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; - } - - var operation = parseOperationType(lexer); - var name; - - if (peek(lexer, TokenKind.NAME)) { - name = parseName(lexer); - } - - return { - kind: Kind.OPERATION_DEFINITION, - operation: operation, - name: name, - variableDefinitions: parseVariableDefinitions(lexer), - directives: parseDirectives(lexer, false), - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; -} -/** - * OperationType : one of query mutation subscription - */ - - -function parseOperationType(lexer) { - var operationToken = expectToken(lexer, TokenKind.NAME); - - switch (operationToken.value) { - case 'query': - return 'query'; - - case 'mutation': - return 'mutation'; - - case 'subscription': - return 'subscription'; - } - - throw unexpected(lexer, operationToken); -} -/** - * VariableDefinitions : ( VariableDefinition+ ) - */ - - -function parseVariableDefinitions(lexer) { - return peek(lexer, TokenKind.PAREN_L) ? many(lexer, TokenKind.PAREN_L, parseVariableDefinition, TokenKind.PAREN_R) : []; -} -/** - * VariableDefinition : Variable : Type DefaultValue? Directives[Const]? - */ - - -function parseVariableDefinition(lexer) { - var start = lexer.token; - return { - kind: Kind.VARIABLE_DEFINITION, - variable: parseVariable(lexer), - type: (expectToken(lexer, TokenKind.COLON), parseTypeReference(lexer)), - defaultValue: expectOptionalToken(lexer, TokenKind.EQUALS) ? parseValueLiteral(lexer, true) : undefined, - directives: parseDirectives(lexer, true), - loc: loc(lexer, start) - }; -} -/** - * Variable : $ Name - */ - - -function parseVariable(lexer) { - var start = lexer.token; - expectToken(lexer, TokenKind.DOLLAR); - return { - kind: Kind.VARIABLE, - name: parseName(lexer), - loc: loc(lexer, start) - }; -} -/** - * SelectionSet : { Selection+ } - */ - - -function parseSelectionSet(lexer) { - var start = lexer.token; - return { - kind: Kind.SELECTION_SET, - selections: many(lexer, TokenKind.BRACE_L, parseSelection, TokenKind.BRACE_R), - loc: loc(lexer, start) - }; -} -/** - * Selection : - * - Field - * - FragmentSpread - * - InlineFragment - */ - - -function parseSelection(lexer) { - return peek(lexer, TokenKind.SPREAD) ? parseFragment(lexer) : parseField(lexer); -} -/** - * Field : Alias? Name Arguments? Directives? SelectionSet? - * - * Alias : Name : - */ - - -function parseField(lexer) { - var start = lexer.token; - var nameOrAlias = parseName(lexer); - var alias; - var name; - - if (expectOptionalToken(lexer, TokenKind.COLON)) { - alias = nameOrAlias; - name = parseName(lexer); - } else { - name = nameOrAlias; - } - - return { - kind: Kind.FIELD, - alias: alias, - name: name, - arguments: parseArguments(lexer, false), - directives: parseDirectives(lexer, false), - selectionSet: peek(lexer, TokenKind.BRACE_L) ? parseSelectionSet(lexer) : undefined, - loc: loc(lexer, start) - }; -} -/** - * Arguments[Const] : ( Argument[?Const]+ ) - */ - - -function parseArguments(lexer, isConst) { - var item = isConst ? parseConstArgument : parseArgument; - return peek(lexer, TokenKind.PAREN_L) ? many(lexer, TokenKind.PAREN_L, item, TokenKind.PAREN_R) : []; -} -/** - * Argument[Const] : Name : Value[?Const] - */ - - -function parseArgument(lexer) { - var start = lexer.token; - var name = parseName(lexer); - expectToken(lexer, TokenKind.COLON); - return { - kind: Kind.ARGUMENT, - name: name, - value: parseValueLiteral(lexer, false), - loc: loc(lexer, start) - }; -} - -function parseConstArgument(lexer) { - var start = lexer.token; - return { - kind: Kind.ARGUMENT, - name: parseName(lexer), - value: (expectToken(lexer, TokenKind.COLON), parseConstValue(lexer)), - loc: loc(lexer, start) - }; -} // Implements the parsing rules in the Fragments section. - -/** - * Corresponds to both FragmentSpread and InlineFragment in the spec. - * - * FragmentSpread : ... FragmentName Directives? - * - * InlineFragment : ... TypeCondition? Directives? SelectionSet - */ - - -function parseFragment(lexer) { - var start = lexer.token; - expectToken(lexer, TokenKind.SPREAD); - var hasTypeCondition = expectOptionalKeyword(lexer, 'on'); - - if (!hasTypeCondition && peek(lexer, TokenKind.NAME)) { - return { - kind: Kind.FRAGMENT_SPREAD, - name: parseFragmentName(lexer), - directives: parseDirectives(lexer, false), - loc: loc(lexer, start) - }; - } - - return { - kind: Kind.INLINE_FRAGMENT, - typeCondition: hasTypeCondition ? parseNamedType(lexer) : undefined, - directives: parseDirectives(lexer, false), - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; -} -/** - * FragmentDefinition : - * - fragment FragmentName on TypeCondition Directives? SelectionSet - * - * TypeCondition : NamedType - */ - - -function parseFragmentDefinition(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'fragment'); // Experimental support for defining variables within fragments changes - // the grammar of FragmentDefinition: - // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet - - if (lexer.options.experimentalFragmentVariables) { - return { - kind: Kind.FRAGMENT_DEFINITION, - name: parseFragmentName(lexer), - variableDefinitions: parseVariableDefinitions(lexer), - typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)), - directives: parseDirectives(lexer, false), - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; - } - - return { - kind: Kind.FRAGMENT_DEFINITION, - name: parseFragmentName(lexer), - typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)), - directives: parseDirectives(lexer, false), - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; -} -/** - * FragmentName : Name but not `on` - */ - - -function parseFragmentName(lexer) { - if (lexer.token.value === 'on') { - throw unexpected(lexer); - } - - return parseName(lexer); -} // Implements the parsing rules in the Values section. - -/** - * Value[Const] : - * - [~Const] Variable - * - IntValue - * - FloatValue - * - StringValue - * - BooleanValue - * - NullValue - * - EnumValue - * - ListValue[?Const] - * - ObjectValue[?Const] - * - * BooleanValue : one of `true` `false` - * - * NullValue : `null` - * - * EnumValue : Name but not `true`, `false` or `null` - */ - - -function parseValueLiteral(lexer, isConst) { - var token = lexer.token; - - switch (token.kind) { - case TokenKind.BRACKET_L: - return parseList(lexer, isConst); - - case TokenKind.BRACE_L: - return parseObject(lexer, isConst); - - case TokenKind.INT: - lexer.advance(); - return { - kind: Kind.INT, - value: token.value, - loc: loc(lexer, token) - }; - - case TokenKind.FLOAT: - lexer.advance(); - return { - kind: Kind.FLOAT, - value: token.value, - loc: loc(lexer, token) - }; - - case TokenKind.STRING: - case TokenKind.BLOCK_STRING: - return parseStringLiteral(lexer); - - case TokenKind.NAME: - if (token.value === 'true' || token.value === 'false') { - lexer.advance(); - return { - kind: Kind.BOOLEAN, - value: token.value === 'true', - loc: loc(lexer, token) - }; - } else if (token.value === 'null') { - lexer.advance(); - return { - kind: Kind.NULL, - loc: loc(lexer, token) - }; - } - - lexer.advance(); - return { - kind: Kind.ENUM, - value: token.value, - loc: loc(lexer, token) - }; - - case TokenKind.DOLLAR: - if (!isConst) { - return parseVariable(lexer); - } - - break; - } - - throw unexpected(lexer); -} - -function parseStringLiteral(lexer) { - var token = lexer.token; - lexer.advance(); - return { - kind: Kind.STRING, - value: token.value, - block: token.kind === TokenKind.BLOCK_STRING, - loc: loc(lexer, token) - }; -} - -function parseConstValue(lexer) { - return parseValueLiteral(lexer, true); -} - -function parseValueValue(lexer) { - return parseValueLiteral(lexer, false); -} -/** - * ListValue[Const] : - * - [ ] - * - [ Value[?Const]+ ] - */ - - -function parseList(lexer, isConst) { - var start = lexer.token; - var item = isConst ? parseConstValue : parseValueValue; - return { - kind: Kind.LIST, - values: any(lexer, TokenKind.BRACKET_L, item, TokenKind.BRACKET_R), - loc: loc(lexer, start) - }; -} -/** - * ObjectValue[Const] : - * - { } - * - { ObjectField[?Const]+ } - */ - - -function parseObject(lexer, isConst) { - var start = lexer.token; - - var item = function item() { - return parseObjectField(lexer, isConst); - }; - - return { - kind: Kind.OBJECT, - fields: any(lexer, TokenKind.BRACE_L, item, TokenKind.BRACE_R), - loc: loc(lexer, start) - }; -} -/** - * ObjectField[Const] : Name : Value[?Const] - */ - - -function parseObjectField(lexer, isConst) { - var start = lexer.token; - var name = parseName(lexer); - expectToken(lexer, TokenKind.COLON); - return { - kind: Kind.OBJECT_FIELD, - name: name, - value: parseValueLiteral(lexer, isConst), - loc: loc(lexer, start) - }; -} // Implements the parsing rules in the Directives section. - -/** - * Directives[Const] : Directive[?Const]+ - */ - - -function parseDirectives(lexer, isConst) { - var directives = []; - - while (peek(lexer, TokenKind.AT)) { - directives.push(parseDirective(lexer, isConst)); - } - - return directives; -} -/** - * Directive[Const] : @ Name Arguments[?Const]? - */ - - -function parseDirective(lexer, isConst) { - var start = lexer.token; - expectToken(lexer, TokenKind.AT); - return { - kind: Kind.DIRECTIVE, - name: parseName(lexer), - arguments: parseArguments(lexer, isConst), - loc: loc(lexer, start) - }; -} // Implements the parsing rules in the Types section. - -/** - * Type : - * - NamedType - * - ListType - * - NonNullType - */ - - -function parseTypeReference(lexer) { - var start = lexer.token; - var type; - - if (expectOptionalToken(lexer, TokenKind.BRACKET_L)) { - type = parseTypeReference(lexer); - expectToken(lexer, TokenKind.BRACKET_R); - type = { - kind: Kind.LIST_TYPE, - type: type, - loc: loc(lexer, start) - }; - } else { - type = parseNamedType(lexer); - } - - if (expectOptionalToken(lexer, TokenKind.BANG)) { - return { - kind: Kind.NON_NULL_TYPE, - type: type, - loc: loc(lexer, start) - }; - } - - return type; -} -/** - * NamedType : Name - */ - -function parseNamedType(lexer) { - var start = lexer.token; - return { - kind: Kind.NAMED_TYPE, - name: parseName(lexer), - loc: loc(lexer, start) - }; -} // Implements the parsing rules in the Type Definition section. - -/** - * TypeSystemDefinition : - * - SchemaDefinition - * - TypeDefinition - * - DirectiveDefinition - * - * TypeDefinition : - * - ScalarTypeDefinition - * - ObjectTypeDefinition - * - InterfaceTypeDefinition - * - UnionTypeDefinition - * - EnumTypeDefinition - * - InputObjectTypeDefinition - */ - -function parseTypeSystemDefinition(lexer) { - // Many definitions begin with a description and require a lookahead. - var keywordToken = peekDescription(lexer) ? lexer.lookahead() : lexer.token; - - if (keywordToken.kind === TokenKind.NAME) { - switch (keywordToken.value) { - case 'schema': - return parseSchemaDefinition(lexer); - - case 'scalar': - return parseScalarTypeDefinition(lexer); - - case 'type': - return parseObjectTypeDefinition(lexer); - - case 'interface': - return parseInterfaceTypeDefinition(lexer); - - case 'union': - return parseUnionTypeDefinition(lexer); - - case 'enum': - return parseEnumTypeDefinition(lexer); - - case 'input': - return parseInputObjectTypeDefinition(lexer); - - case 'directive': - return parseDirectiveDefinition(lexer); - } - } - - throw unexpected(lexer, keywordToken); -} - -function peekDescription(lexer) { - return peek(lexer, TokenKind.STRING) || peek(lexer, TokenKind.BLOCK_STRING); -} -/** - * Description : StringValue - */ - - -function parseDescription(lexer) { - if (peekDescription(lexer)) { - return parseStringLiteral(lexer); - } -} -/** - * SchemaDefinition : schema Directives[Const]? { OperationTypeDefinition+ } - */ - - -function parseSchemaDefinition(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'schema'); - var directives = parseDirectives(lexer, true); - var operationTypes = many(lexer, TokenKind.BRACE_L, parseOperationTypeDefinition, TokenKind.BRACE_R); - return { - kind: Kind.SCHEMA_DEFINITION, - directives: directives, - operationTypes: operationTypes, - loc: loc(lexer, start) - }; -} -/** - * OperationTypeDefinition : OperationType : NamedType - */ - - -function parseOperationTypeDefinition(lexer) { - var start = lexer.token; - var operation = parseOperationType(lexer); - expectToken(lexer, TokenKind.COLON); - var type = parseNamedType(lexer); - return { - kind: Kind.OPERATION_TYPE_DEFINITION, - operation: operation, - type: type, - loc: loc(lexer, start) - }; -} -/** - * ScalarTypeDefinition : Description? scalar Name Directives[Const]? - */ - - -function parseScalarTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'scalar'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - return { - kind: Kind.SCALAR_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - loc: loc(lexer, start) - }; -} -/** - * ObjectTypeDefinition : - * Description? - * type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition? - */ - - -function parseObjectTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'type'); - var name = parseName(lexer); - var interfaces = parseImplementsInterfaces(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseFieldsDefinition(lexer); - return { - kind: Kind.OBJECT_TYPE_DEFINITION, - description: description, - name: name, - interfaces: interfaces, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; -} -/** - * ImplementsInterfaces : - * - implements `&`? NamedType - * - ImplementsInterfaces & NamedType - */ - - -function parseImplementsInterfaces(lexer) { - var types = []; - - if (expectOptionalKeyword(lexer, 'implements')) { - // Optional leading ampersand - expectOptionalToken(lexer, TokenKind.AMP); - - do { - types.push(parseNamedType(lexer)); - } while (expectOptionalToken(lexer, TokenKind.AMP) || // Legacy support for the SDL? - lexer.options.allowLegacySDLImplementsInterfaces && peek(lexer, TokenKind.NAME)); - } - - return types; -} -/** - * FieldsDefinition : { FieldDefinition+ } - */ - - -function parseFieldsDefinition(lexer) { - // Legacy support for the SDL? - if (lexer.options.allowLegacySDLEmptyFields && peek(lexer, TokenKind.BRACE_L) && lexer.lookahead().kind === TokenKind.BRACE_R) { - lexer.advance(); - lexer.advance(); - return []; - } - - return peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseFieldDefinition, TokenKind.BRACE_R) : []; -} -/** - * FieldDefinition : - * - Description? Name ArgumentsDefinition? : Type Directives[Const]? - */ - - -function parseFieldDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - var name = parseName(lexer); - var args = parseArgumentDefs(lexer); - expectToken(lexer, TokenKind.COLON); - var type = parseTypeReference(lexer); - var directives = parseDirectives(lexer, true); - return { - kind: Kind.FIELD_DEFINITION, - description: description, - name: name, - arguments: args, - type: type, - directives: directives, - loc: loc(lexer, start) - }; -} -/** - * ArgumentsDefinition : ( InputValueDefinition+ ) - */ - - -function parseArgumentDefs(lexer) { - if (!peek(lexer, TokenKind.PAREN_L)) { - return []; - } - - return many(lexer, TokenKind.PAREN_L, parseInputValueDef, TokenKind.PAREN_R); -} -/** - * InputValueDefinition : - * - Description? Name : Type DefaultValue? Directives[Const]? - */ - - -function parseInputValueDef(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - var name = parseName(lexer); - expectToken(lexer, TokenKind.COLON); - var type = parseTypeReference(lexer); - var defaultValue; - - if (expectOptionalToken(lexer, TokenKind.EQUALS)) { - defaultValue = parseConstValue(lexer); - } - - var directives = parseDirectives(lexer, true); - return { - kind: Kind.INPUT_VALUE_DEFINITION, - description: description, - name: name, - type: type, - defaultValue: defaultValue, - directives: directives, - loc: loc(lexer, start) - }; -} -/** - * InterfaceTypeDefinition : - * - Description? interface Name Directives[Const]? FieldsDefinition? - */ - - -function parseInterfaceTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'interface'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseFieldsDefinition(lexer); - return { - kind: Kind.INTERFACE_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; -} -/** - * UnionTypeDefinition : - * - Description? union Name Directives[Const]? UnionMemberTypes? - */ - - -function parseUnionTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'union'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var types = parseUnionMemberTypes(lexer); - return { - kind: Kind.UNION_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - types: types, - loc: loc(lexer, start) - }; -} -/** - * UnionMemberTypes : - * - = `|`? NamedType - * - UnionMemberTypes | NamedType - */ - - -function parseUnionMemberTypes(lexer) { - var types = []; - - if (expectOptionalToken(lexer, TokenKind.EQUALS)) { - // Optional leading pipe - expectOptionalToken(lexer, TokenKind.PIPE); - - do { - types.push(parseNamedType(lexer)); - } while (expectOptionalToken(lexer, TokenKind.PIPE)); - } - - return types; -} -/** - * EnumTypeDefinition : - * - Description? enum Name Directives[Const]? EnumValuesDefinition? - */ - - -function parseEnumTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'enum'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var values = parseEnumValuesDefinition(lexer); - return { - kind: Kind.ENUM_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - values: values, - loc: loc(lexer, start) - }; -} -/** - * EnumValuesDefinition : { EnumValueDefinition+ } - */ - - -function parseEnumValuesDefinition(lexer) { - return peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseEnumValueDefinition, TokenKind.BRACE_R) : []; -} -/** - * EnumValueDefinition : Description? EnumValue Directives[Const]? - * - * EnumValue : Name - */ - - -function parseEnumValueDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - return { - kind: Kind.ENUM_VALUE_DEFINITION, - description: description, - name: name, - directives: directives, - loc: loc(lexer, start) - }; -} -/** - * InputObjectTypeDefinition : - * - Description? input Name Directives[Const]? InputFieldsDefinition? - */ - - -function parseInputObjectTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'input'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseInputFieldsDefinition(lexer); - return { - kind: Kind.INPUT_OBJECT_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; -} -/** - * InputFieldsDefinition : { InputValueDefinition+ } - */ - - -function parseInputFieldsDefinition(lexer) { - return peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseInputValueDef, TokenKind.BRACE_R) : []; -} -/** - * TypeSystemExtension : - * - SchemaExtension - * - TypeExtension - * - * TypeExtension : - * - ScalarTypeExtension - * - ObjectTypeExtension - * - InterfaceTypeExtension - * - UnionTypeExtension - * - EnumTypeExtension - * - InputObjectTypeDefinition - */ - - -function parseTypeSystemExtension(lexer) { - var keywordToken = lexer.lookahead(); - - if (keywordToken.kind === TokenKind.NAME) { - switch (keywordToken.value) { - case 'schema': - return parseSchemaExtension(lexer); - - case 'scalar': - return parseScalarTypeExtension(lexer); - - case 'type': - return parseObjectTypeExtension(lexer); - - case 'interface': - return parseInterfaceTypeExtension(lexer); - - case 'union': - return parseUnionTypeExtension(lexer); - - case 'enum': - return parseEnumTypeExtension(lexer); - - case 'input': - return parseInputObjectTypeExtension(lexer); - } - } - - throw unexpected(lexer, keywordToken); -} -/** - * SchemaExtension : - * - extend schema Directives[Const]? { OperationTypeDefinition+ } - * - extend schema Directives[Const] - */ - - -function parseSchemaExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'schema'); - var directives = parseDirectives(lexer, true); - var operationTypes = peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseOperationTypeDefinition, TokenKind.BRACE_R) : []; - - if (directives.length === 0 && operationTypes.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.SCHEMA_EXTENSION, - directives: directives, - operationTypes: operationTypes, - loc: loc(lexer, start) - }; -} -/** - * ScalarTypeExtension : - * - extend scalar Name Directives[Const] - */ - - -function parseScalarTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'scalar'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - - if (directives.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.SCALAR_TYPE_EXTENSION, - name: name, - directives: directives, - loc: loc(lexer, start) - }; -} -/** - * ObjectTypeExtension : - * - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition - * - extend type Name ImplementsInterfaces? Directives[Const] - * - extend type Name ImplementsInterfaces - */ - - -function parseObjectTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'type'); - var name = parseName(lexer); - var interfaces = parseImplementsInterfaces(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseFieldsDefinition(lexer); - - if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.OBJECT_TYPE_EXTENSION, - name: name, - interfaces: interfaces, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; -} -/** - * InterfaceTypeExtension : - * - extend interface Name Directives[Const]? FieldsDefinition - * - extend interface Name Directives[Const] - */ - - -function parseInterfaceTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'interface'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseFieldsDefinition(lexer); - - if (directives.length === 0 && fields.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.INTERFACE_TYPE_EXTENSION, - name: name, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; -} -/** - * UnionTypeExtension : - * - extend union Name Directives[Const]? UnionMemberTypes - * - extend union Name Directives[Const] - */ - - -function parseUnionTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'union'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var types = parseUnionMemberTypes(lexer); - - if (directives.length === 0 && types.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.UNION_TYPE_EXTENSION, - name: name, - directives: directives, - types: types, - loc: loc(lexer, start) - }; -} -/** - * EnumTypeExtension : - * - extend enum Name Directives[Const]? EnumValuesDefinition - * - extend enum Name Directives[Const] - */ - - -function parseEnumTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'enum'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var values = parseEnumValuesDefinition(lexer); - - if (directives.length === 0 && values.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.ENUM_TYPE_EXTENSION, - name: name, - directives: directives, - values: values, - loc: loc(lexer, start) - }; -} -/** - * InputObjectTypeExtension : - * - extend input Name Directives[Const]? InputFieldsDefinition - * - extend input Name Directives[Const] - */ - - -function parseInputObjectTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'input'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseInputFieldsDefinition(lexer); - - if (directives.length === 0 && fields.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.INPUT_OBJECT_TYPE_EXTENSION, - name: name, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; -} -/** - * DirectiveDefinition : - * - Description? directive @ Name ArgumentsDefinition? on DirectiveLocations - */ - - -function parseDirectiveDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'directive'); - expectToken(lexer, TokenKind.AT); - var name = parseName(lexer); - var args = parseArgumentDefs(lexer); - expectKeyword(lexer, 'on'); - var locations = parseDirectiveLocations(lexer); - return { - kind: Kind.DIRECTIVE_DEFINITION, - description: description, - name: name, - arguments: args, - locations: locations, - loc: loc(lexer, start) - }; -} -/** - * DirectiveLocations : - * - `|`? DirectiveLocation - * - DirectiveLocations | DirectiveLocation - */ - - -function parseDirectiveLocations(lexer) { - // Optional leading pipe - expectOptionalToken(lexer, TokenKind.PIPE); - var locations = []; - - do { - locations.push(parseDirectiveLocation(lexer)); - } while (expectOptionalToken(lexer, TokenKind.PIPE)); - - return locations; -} -/* - * DirectiveLocation : - * - ExecutableDirectiveLocation - * - TypeSystemDirectiveLocation - * - * ExecutableDirectiveLocation : one of - * `QUERY` - * `MUTATION` - * `SUBSCRIPTION` - * `FIELD` - * `FRAGMENT_DEFINITION` - * `FRAGMENT_SPREAD` - * `INLINE_FRAGMENT` - * - * TypeSystemDirectiveLocation : one of - * `SCHEMA` - * `SCALAR` - * `OBJECT` - * `FIELD_DEFINITION` - * `ARGUMENT_DEFINITION` - * `INTERFACE` - * `UNION` - * `ENUM` - * `ENUM_VALUE` - * `INPUT_OBJECT` - * `INPUT_FIELD_DEFINITION` - */ - - -function parseDirectiveLocation(lexer) { - var start = lexer.token; - var name = parseName(lexer); - - if (DirectiveLocation[name.value] !== undefined) { - return name; - } - - throw unexpected(lexer, start); -} // Core parsing utility functions - -/** - * Returns a location object, used to identify the place in - * the source that created a given parsed object. - */ - - -function loc(lexer, startToken) { - if (!lexer.options.noLocation) { - return new Loc(startToken, lexer.lastToken, lexer.source); - } -} - -function Loc(startToken, endToken, source) { - this.start = startToken.start; - this.end = endToken.end; - this.startToken = startToken; - this.endToken = endToken; - this.source = source; -} // Print a simplified form when appearing in JSON/util.inspect. - - -defineToJSON(Loc, function () { - return { - start: this.start, - end: this.end - }; -}); -/** - * Determines if the next token is of a given kind - */ - -function peek(lexer, kind) { - return lexer.token.kind === kind; -} -/** - * If the next token is of the given kind, return that token after advancing - * the lexer. Otherwise, do not change the parser state and throw an error. - */ - - -function expectToken(lexer, kind) { - var token = lexer.token; - - if (token.kind === kind) { - lexer.advance(); - return token; - } - - throw syntaxError(lexer.source, token.start, "Expected ".concat(kind, ", found ").concat(getTokenDesc(token))); -} -/** - * If the next token is of the given kind, return that token after advancing - * the lexer. Otherwise, do not change the parser state and return undefined. - */ - - -function expectOptionalToken(lexer, kind) { - var token = lexer.token; - - if (token.kind === kind) { - lexer.advance(); - return token; - } - - return undefined; -} -/** - * If the next token is a given keyword, return that token after advancing - * the lexer. Otherwise, do not change the parser state and throw an error. - */ - - -function expectKeyword(lexer, value) { - var token = lexer.token; - - if (token.kind === TokenKind.NAME && token.value === value) { - lexer.advance(); - return token; - } - - throw syntaxError(lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(token))); -} -/** - * If the next token is a given keyword, return that token after advancing - * the lexer. Otherwise, do not change the parser state and return undefined. - */ - - -function expectOptionalKeyword(lexer, value) { - var token = lexer.token; - - if (token.kind === TokenKind.NAME && token.value === value) { - lexer.advance(); - return token; - } - - return undefined; -} -/** - * Helper function for creating an error when an unexpected lexed token - * is encountered. - */ - - -function unexpected(lexer, atToken) { - var token = atToken || lexer.token; - return syntaxError(lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token))); -} -/** - * Returns a possibly empty list of parse nodes, determined by - * the parseFn. This list begins with a lex token of openKind - * and ends with a lex token of closeKind. Advances the parser - * to the next lex token after the closing token. - */ - - -function any(lexer, openKind, parseFn, closeKind) { - expectToken(lexer, openKind); - var nodes = []; - - while (!expectOptionalToken(lexer, closeKind)) { - nodes.push(parseFn(lexer)); - } - - return nodes; -} -/** - * Returns a non-empty list of parse nodes, determined by - * the parseFn. This list begins with a lex token of openKind - * and ends with a lex token of closeKind. Advances the parser - * to the next lex token after the closing token. - */ - - -function many(lexer, openKind, parseFn, closeKind) { - expectToken(lexer, openKind); - var nodes = [parseFn(lexer)]; - - while (!expectOptionalToken(lexer, closeKind)) { - nodes.push(parseFn(lexer)); - } - - return nodes; -} - -var parser = /*#__PURE__*/Object.freeze({ - parse: parse, - parseValue: parseValue, - parseType: parseType, - parseConstValue: parseConstValue, - parseTypeReference: parseTypeReference, - parseNamedType: parseNamedType -}); - -var parser$1 = getCjsExportFromNamespace(parser); - -var parse$1 = parser$1.parse; - -// Strip insignificant whitespace -// Note that this could do a lot more, such as reorder fields etc. -function normalize(string) { - return string.replace(/[\s,]+/g, ' ').trim(); -} - -// A map docString -> graphql document -var docCache = {}; - -// A map fragmentName -> [normalized source] -var fragmentSourceMap = {}; - -function cacheKeyFromLoc(loc) { - return normalize(loc.source.body.substring(loc.start, loc.end)); -} - -// For testing. -function resetCaches() { - docCache = {}; - fragmentSourceMap = {}; -} - -// Take a unstripped parsed document (query/mutation or even fragment), and -// check all fragment definitions, checking for name->source uniqueness. -// We also want to make sure only unique fragments exist in the document. -var printFragmentWarnings = true; -function processFragments(ast) { - var astFragmentMap = {}; - var definitions = []; - - for (var i = 0; i < ast.definitions.length; i++) { - var fragmentDefinition = ast.definitions[i]; - - if (fragmentDefinition.kind === 'FragmentDefinition') { - var fragmentName = fragmentDefinition.name.value; - var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc); - - // We know something about this fragment - if (fragmentSourceMap.hasOwnProperty(fragmentName) && !fragmentSourceMap[fragmentName][sourceKey]) { - - // this is a problem because the app developer is trying to register another fragment with - // the same name as one previously registered. So, we tell them about it. - if (printFragmentWarnings) { - console.warn("Warning: fragment with name " + fragmentName + " already exists.\n" - + "graphql-tag enforces all fragment names across your application to be unique; read more about\n" - + "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names"); - } - - fragmentSourceMap[fragmentName][sourceKey] = true; - - } else if (!fragmentSourceMap.hasOwnProperty(fragmentName)) { - fragmentSourceMap[fragmentName] = {}; - fragmentSourceMap[fragmentName][sourceKey] = true; - } - - if (!astFragmentMap[sourceKey]) { - astFragmentMap[sourceKey] = true; - definitions.push(fragmentDefinition); - } - } else { - definitions.push(fragmentDefinition); - } - } - - ast.definitions = definitions; - return ast; -} - -function disableFragmentWarnings() { - printFragmentWarnings = false; -} - -function stripLoc(doc, removeLocAtThisLevel) { - var docType = Object.prototype.toString.call(doc); - - if (docType === '[object Array]') { - return doc.map(function (d) { - return stripLoc(d, removeLocAtThisLevel); - }); - } - - if (docType !== '[object Object]') { - throw new Error('Unexpected input.'); - } - - // We don't want to remove the root loc field so we can use it - // for fragment substitution (see below) - if (removeLocAtThisLevel && doc.loc) { - delete doc.loc; - } - - // https://github.com/apollographql/graphql-tag/issues/40 - if (doc.loc) { - delete doc.loc.startToken; - delete doc.loc.endToken; - } - - var keys = Object.keys(doc); - var key; - var value; - var valueType; - - for (key in keys) { - if (keys.hasOwnProperty(key)) { - value = doc[keys[key]]; - valueType = Object.prototype.toString.call(value); - - if (valueType === '[object Object]' || valueType === '[object Array]') { - doc[keys[key]] = stripLoc(value, true); - } - } - } - - return doc; -} - -var experimentalFragmentVariables = false; -function parseDocument$1(doc) { - var cacheKey = normalize(doc); - - if (docCache[cacheKey]) { - return docCache[cacheKey]; - } - - var parsed = parse$1(doc, { experimentalFragmentVariables: experimentalFragmentVariables }); - if (!parsed || parsed.kind !== 'Document') { - throw new Error('Not a valid GraphQL document.'); - } - - // check that all "new" fragments inside the documents are consistent with - // existing fragments of the same name - parsed = processFragments(parsed); - parsed = stripLoc(parsed, false); - docCache[cacheKey] = parsed; - - return parsed; -} - -function enableExperimentalFragmentVariables() { - experimentalFragmentVariables = true; -} - -function disableExperimentalFragmentVariables() { - experimentalFragmentVariables = false; -} - -// XXX This should eventually disallow arbitrary string interpolation, like Relay does -function gql(/* arguments */) { - var args = Array.prototype.slice.call(arguments); - - var literals = args[0]; - - // We always get literals[0] and then matching post literals for each arg given - var result = (typeof(literals) === "string") ? literals : literals[0]; - - for (var i = 1; i < args.length; i++) { - if (args[i] && args[i].kind && args[i].kind === 'Document') { - result += args[i].loc.source.body; - } else { - result += args[i]; - } - - result += literals[i]; - } - - return parseDocument$1(result); -} - -// Support typescript, which isn't as nice as Babel about default exports -gql.default = gql; -gql.resetCaches = resetCaches; -gql.disableFragmentWarnings = disableFragmentWarnings; -gql.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables; -gql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables; - -var src = gql; - function isDataFilled(data) { return Object.keys(data).length > 0; } @@ -4678,10 +1609,10 @@ var CApolloQuery = { return this.clientId; }, query: function query() { - return _objectSpread({ + return _objectSpread2({ query: function query() { if (typeof this.query === 'function') { - return this.query(src); + return this.query(gql); } return this.query; @@ -4820,7 +1751,7 @@ var CApolloSubscribeToMore = { var document = this.document; if (typeof document === 'function') { - document = document(src); + document = document(gql); } this.$_sub = this.getDollarApollo().addSmartSubscription(this.$_key, { @@ -4887,10 +1818,10 @@ var CApolloMutation = { var mutation = this.mutation; if (typeof mutation === 'function') { - mutation = mutation(src); + mutation = mutation(gql); } - this.$apollo.mutate(_objectSpread({ + this.$apollo.mutate(_objectSpread2({ mutation: mutation, client: this.clientId, variables: this.variables, @@ -5031,7 +1962,7 @@ function launch() { if (this.$isServer) { options = utils_5(options, this); - if (options.prefetch !== false && apollo.$prefetch !== false && !smart.skip) { + if (apolloProvider.prefetch !== false && options.prefetch !== false && apollo.$prefetch !== false && !smart.skip) { this.$_apolloPromises.push(smart.firstRun); } } @@ -5068,9 +1999,9 @@ function destroy() { } function installMixin(Vue, vueVersion) { - Vue.mixin(_objectSpread({}, vueVersion === '1' ? { + Vue.mixin(_objectSpread2({}, vueVersion === '1' ? { init: initProvider - } : {}, vueVersion === '2' ? { + } : {}, {}, vueVersion === '2' ? { data: function data() { return { '$apolloData': { @@ -5142,7 +2073,7 @@ function install(Vue, options) { } ApolloProvider.install = install; // eslint-disable-next-line no-undef -ApolloProvider.version = "3.0.0-rc.2"; // Apollo provider +ApolloProvider.version = "3.0.0-rc.3"; // Apollo provider var ApolloProvider$1 = ApolloProvider; // Components diff --git a/dist/vue-apollo.min.js b/dist/vue-apollo.min.js index f070addd..db641f5c 100644 --- a/dist/vue-apollo.min.js +++ b/dist/vue-apollo.min.js @@ -1 +1 @@ -var VueApollo=function(t){"use strict";function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n.provide() is deprecated. Use the 'apolloProvider' option instead with the provider object directly."),s({},e,this)}}]),e}(),C="function"==typeof Symbol?Symbol.for("nodejs.util.inspect.custom"):void 0;function $(t){return($="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var L=10,D=2;function P(t,e){switch($(t)){case"string":return JSON.stringify(t);case"function":return t.name?"[function ".concat(t.name,"]"):"[function]";case"object":return function(t,e){if(-1!==e.indexOf(t))return"[Circular]";var n=[].concat(e,[t]);if(t){var r=function(t){var e=t[String(C)];if("function"==typeof e)return e;if("function"==typeof t.inspect)return t.inspect}(t);if(void 0!==r){var i=r.call(t);if(i!==t)return"string"==typeof i?i:P(i,n)}else if(Array.isArray(t))return function(t,e){if(0===t.length)return"[]";if(e.length>D)return"[Array]";for(var n=Math.min(L,t.length),r=t.length-n,i=[],o=0;oD)return"["+function(t){var e=Object.prototype.toString.call(t).replace(/^\[object /,"").replace(/]$/,"");if("Object"===e&&"function"==typeof t.constructor){var n=t.constructor.name;if("string"==typeof n)return n}return e}(e)+"]";return"{ "+t.map(function(t){return t+": "+P(e[t],n)}).join(", ")+" }"}(t,n)}return String(t)}(t,e);default:return String(t)}}function F(t,e){var n=1",EOF:"",BANG:"!",DOLLAR:"$",AMP:"&",PAREN_L:"(",PAREN_R:")",SPREAD:"...",COLON:":",EQUALS:"=",AT:"@",BRACKET_L:"[",BRACKET_R:"]",BRACE_L:"{",PIPE:"|",BRACE_R:"}",NAME:"Name",INT:"Int",FLOAT:"Float",STRING:"String",BLOCK_STRING:"BlockString",COMMENT:"Comment"});function Z(t){var e=t.value;return e?"".concat(t.kind,' "').concat(e,'"'):t.kind}function tt(t,e,n,r,i,o,a){this.kind=t,this.start=e,this.end=n,this.line=r,this.column=i,this.value=a,this.prev=o,this.next=null}function et(t){return isNaN(t)?W.EOF:t<127?JSON.stringify(String.fromCharCode(t)):'"\\u'.concat(("00"+t.toString(16).toUpperCase()).slice(-4),'"')}function nt(t,e){var n=t.source,r=n.body,i=r.length,o=function(t,e,n){var r=t.length,i=e;for(;i `subscribe` option is deprecated. Use the `$subscribe` option instead."),n.$subscribe)for(var a in n.$subscribe)this.$apollo.addSmartSubscription(a,n.$subscribe[a])}}}function ye(t,e,n,r){void 0!==n&&("function"==typeof n?t.defineReactiveSetter(e,n,r):t[e]=n)}function be(){this.$_apollo&&(this.$_apollo.destroy(),this.$_apollo=null)}function Ee(t,e){t.mixin(l({},"1"===e?{init:de}:{},"2"===e?{data:function(){return{$apolloData:{queries:{},loading:0,data:this.$_apolloInitData}}},beforeCreate:function(){de.call(this),function(){var n=this;this.$_apolloInitData={};var t=this.$options.apollo;if(t){var e=function(e){"$"!==e.charAt(0)&&(t[e].manual||pe(n.$options.props,e)||pe(n.$options.computed,e)||pe(n.$options.methods,e)||Object.defineProperty(n,e,{get:function(){return n.$data.$apolloData.data[e]},set:function(t){return n.$_apolloInitData[e]=t},enumerable:!0,configurable:!0}))};for(var r in t)e(r)}}.call(this)},serverPrefetch:function(){if(this.$_apolloPromises)return Promise.all(this.$_apolloPromises)}}:{},{created:ve,destroyed:be}))}var ge=["$subscribe"];function me(t,e){if(!me.installed){me.installed=!0;var n=(g.Vue=t).version.substr(0,t.version.indexOf(".")),u=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,n){if(!t)return e;if(!e)return t;for(var r=Object.assign({},A(t,ge),t.data),i=Object.assign({},A(e,ge),e.data),o={},a=0;a.provide() is deprecated. Use the 'apolloProvider' option instead with the provider object directly."),a({},e,this)}}]),e}();var E={name:"ApolloQuery",provide:function(){return{getDollarApollo:this.getDollarApollo,getApolloQuery:this.getApolloQuery}},props:{query:{type:[Function,Object],required:!0},variables:{type:Object,default:void 0},fetchPolicy:{type:String,default:void 0},pollInterval:{type:Number,default:void 0},notifyOnNetworkStatusChange:{type:Boolean,default:void 0},context:{type:Object,default:void 0},update:{type:Function,default:function(t){return t}},skip:{type:Boolean,default:!1},debounce:{type:Number,default:0},throttle:{type:Number,default:0},clientId:{type:String,default:void 0},deep:{type:Boolean,default:void 0},tag:{type:String,default:"div"},prefetch:{type:Boolean,default:!0},options:{type:Object,default:function(){return{}}}},data:function(){return{result:{data:null,loading:!1,networkStatus:7,error:null},times:0}},watch:{fetchPolicy:function(t){this.$apollo.queries.query.setOptions({fetchPolicy:t})},pollInterval:function(t){this.$apollo.queries.query.setOptions({pollInterval:t})},notifyOnNetworkStatusChange:function(t){this.$apollo.queries.query.setOptions({notifyOnNetworkStatusChange:t})},"$data.$apolloData.loading":function(t){this.$emit("loading",!!t)}},apollo:{$client:function(){return this.clientId},query:function(){return c({query:function(){return"function"==typeof this.query?this.query(o):this.query},variables:function(){return this.variables},fetchPolicy:this.fetchPolicy,pollInterval:this.pollInterval,debounce:this.debounce,throttle:this.throttle,notifyOnNetworkStatusChange:this.notifyOnNetworkStatusChange,context:function(){return this.context},skip:function(){return this.skip},deep:this.deep,prefetch:this.prefetch},this.options,{manual:!0,result:function(t){var e=t,i=e.errors,o=e.loading,r=e.networkStatus,n=t.error;t=Object.assign({},t),i&&i.length&&((n=new Error("Apollo errors occurred (".concat(i.length,")"))).graphQLErrors=i);var s={};o?Object.assign(s,this.$_previousData,t.data):n?Object.assign(s,this.$apollo.queries.query.observer.getLastResult()||{},t.data):(s=t.data,this.$_previousData=t.data);var a=function(t){return 0 `subscribe` option is deprecated. Use the `$subscribe` option instead."),i.$subscribe)for(var s in i.$subscribe)this.$apollo.addSmartSubscription(s,i.$subscribe[s])}}}function K(t,e,i,o){void 0!==i&&("function"==typeof i?t.defineReactiveSetter(e,i,o):t[e]=i)}function N(){this.$_apollo&&(this.$_apollo.destroy(),this.$_apollo=null)}function V(t,e){t.mixin(c({},"1"===e?{init:M}:{},{},"2"===e?{data:function(){return{$apolloData:{queries:{},loading:0,data:this.$_apolloInitData}}},beforeCreate:function(){M.call(this),function(){var i=this;this.$_apolloInitData={};var t=this.$options.apollo;if(t){var e=function(e){"$"!==e.charAt(0)&&(t[e].manual||I(i.$options.props,e)||I(i.$options.computed,e)||I(i.$options.methods,e)||Object.defineProperty(i,e,{get:function(){return i.$data.$apolloData.data[e]},set:function(t){return i.$_apolloInitData[e]=t},enumerable:!0,configurable:!0}))};for(var o in t)e(o)}}.call(this)},serverPrefetch:function(){if(this.$_apolloPromises)return Promise.all(this.$_apolloPromises)}}:{},{created:T,destroyed:N}))}var F=["$subscribe"];function H(t,e){if(!H.installed){H.installed=!0;var i=(k.Vue=t).version.substr(0,t.version.indexOf(".")),l=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,i){if(!t)return e;if(!e)return t;for(var o=Object.assign({},_(t,F),t.data),r=Object.assign({},_(e,F),e.data),n={},s=0;s 0 && arguments[0] !== undefined ? arguments[0] : null; @@ -1224,6 +1264,11 @@ return client; } + }, { + key: "query", + value: function query(options) { + return this.getClient(options).query(options); + } }, { key: "watchQuery", value: function watchQuery(options) { @@ -1308,12 +1353,12 @@ if (subs) { if (Array.isArray(subs)) { subs.forEach(function (sub, index) { - _this3.addSmartSubscription("".concat(key).concat(index), _objectSpread({}, sub, { + _this3.addSmartSubscription("".concat(key).concat(index), _objectSpread2({}, sub, { linkedQuery: smart })); }); } else { - this.addSmartSubscription(key, _objectSpread({}, subs, { + this.addSmartSubscription(key, _objectSpread2({}, subs, { linkedQuery: smart })); } @@ -1441,7 +1486,7 @@ this.defaultOptions = options.defaultOptions; this.watchLoading = options.watchLoading; this.errorHandler = options.errorHandler; - this.prefetchQueries = []; + this.prefetch = options.prefetch; } _createClass(ApolloProvider, [{ @@ -1456,3120 +1501,6 @@ return ApolloProvider; }(); - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - var nodejsCustomInspectSymbol = typeof Symbol === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined; - - function _typeof$1(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); } - var MAX_ARRAY_LENGTH = 10; - var MAX_RECURSIVE_DEPTH = 2; - /** - * Used to print values in error messages. - */ - - function inspect(value) { - return formatValue(value, []); - } - - function formatValue(value, seenValues) { - switch (_typeof$1(value)) { - case 'string': - return JSON.stringify(value); - - case 'function': - return value.name ? "[function ".concat(value.name, "]") : '[function]'; - - case 'object': - return formatObjectValue(value, seenValues); - - default: - return String(value); - } - } - - function formatObjectValue(value, previouslySeenValues) { - if (previouslySeenValues.indexOf(value) !== -1) { - return '[Circular]'; - } - - var seenValues = [].concat(previouslySeenValues, [value]); - - if (value) { - var customInspectFn = getCustomFn(value); - - if (customInspectFn !== undefined) { - // $FlowFixMe(>=0.90.0) - var customValue = customInspectFn.call(value); // check for infinite recursion - - if (customValue !== value) { - return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues); - } - } else if (Array.isArray(value)) { - return formatArray(value, seenValues); - } - - return formatObject(value, seenValues); - } - - return String(value); - } - - function formatObject(object, seenValues) { - var keys = Object.keys(object); - - if (keys.length === 0) { - return '{}'; - } - - if (seenValues.length > MAX_RECURSIVE_DEPTH) { - return '[' + getObjectTag(object) + ']'; - } - - var properties = keys.map(function (key) { - var value = formatValue(object[key], seenValues); - return key + ': ' + value; - }); - return '{ ' + properties.join(', ') + ' }'; - } - - function formatArray(array, seenValues) { - if (array.length === 0) { - return '[]'; - } - - if (seenValues.length > MAX_RECURSIVE_DEPTH) { - return '[Array]'; - } - - var len = Math.min(MAX_ARRAY_LENGTH, array.length); - var remaining = array.length - len; - var items = []; - - for (var i = 0; i < len; ++i) { - items.push(formatValue(array[i], seenValues)); - } - - if (remaining === 1) { - items.push('... 1 more item'); - } else if (remaining > 1) { - items.push("... ".concat(remaining, " more items")); - } - - return '[' + items.join(', ') + ']'; - } - - function getCustomFn(object) { - var customInspectFn = object[String(nodejsCustomInspectSymbol)]; - - if (typeof customInspectFn === 'function') { - return customInspectFn; - } - - if (typeof object.inspect === 'function') { - return object.inspect; - } - } - - function getObjectTag(object) { - var tag = Object.prototype.toString.call(object).replace(/^\[object /, '').replace(/]$/, ''); - - if (tag === 'Object' && typeof object.constructor === 'function') { - var name = object.constructor.name; - - if (typeof name === 'string') { - return name; - } - } - - return tag; - } - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - /** - * The `defineToJSON()` function defines toJSON() and inspect() prototype - * methods, if no function provided they become aliases for toString(). - */ - - function defineToJSON( // eslint-disable-next-line flowtype/no-weak-types - classObject) { - var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : classObject.prototype.toString; - classObject.prototype.toJSON = fn; - classObject.prototype.inspect = fn; - - if (nodejsCustomInspectSymbol) { - classObject.prototype[nodejsCustomInspectSymbol] = fn; - } - } - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - function invariant(condition, message) { - var booleanCondition = Boolean(condition); - /* istanbul ignore else */ - - if (!booleanCondition) { - throw new Error(message); - } - } - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * The `defineToStringTag()` function checks first to see if the runtime - * supports the `Symbol` class and then if the `Symbol.toStringTag` constant - * is defined as a `Symbol` instance. If both conditions are met, the - * Symbol.toStringTag property is defined as a getter that returns the - * supplied class constructor's name. - * - * @method defineToStringTag - * - * @param {Class} classObject a class such as Object, String, Number but - * typically one of your own creation through the class keyword; `class A {}`, - * for example. - */ - function defineToStringTag(classObject) { - if (typeof Symbol === 'function' && Symbol.toStringTag) { - Object.defineProperty(classObject.prototype, Symbol.toStringTag, { - get: function get() { - return this.constructor.name; - } - }); - } - } - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * A representation of source input to GraphQL. - * `name` and `locationOffset` are optional. They are useful for clients who - * store GraphQL documents in source files; for example, if the GraphQL input - * starts at line 40 in a file named Foo.graphql, it might be useful for name to - * be "Foo.graphql" and location to be `{ line: 40, column: 0 }`. - * line and column in locationOffset are 1-indexed - */ - var Source = function Source(body, name, locationOffset) { - this.body = body; - this.name = name || 'GraphQL request'; - this.locationOffset = locationOffset || { - line: 1, - column: 1 - }; - !(this.locationOffset.line > 0) ? invariant(0, 'line in locationOffset is 1-indexed and must be positive') : void 0; - !(this.locationOffset.column > 0) ? invariant(0, 'column in locationOffset is 1-indexed and must be positive') : void 0; - }; // Conditionally apply `[Symbol.toStringTag]` if `Symbol`s are supported - - defineToStringTag(Source); - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * Represents a location in a Source. - */ - - /** - * Takes a Source and a UTF-8 character offset, and returns the corresponding - * line and column as a SourceLocation. - */ - function getLocation(source, position) { - var lineRegexp = /\r\n|[\n\r]/g; - var line = 1; - var column = position + 1; - var match; - - while ((match = lineRegexp.exec(source.body)) && match.index < position) { - line += 1; - column = position + 1 - (match.index + match[0].length); - } - - return { - line: line, - column: column - }; - } - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * Prints a GraphQLError to a string, representing useful location information - * about the error's position in the source. - */ - function printError(error) { - var printedLocations = []; - - if (error.nodes) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = error.nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var node = _step.value; - - if (node.loc) { - printedLocations.push(highlightSourceAtLocation(node.loc.source, getLocation(node.loc.source, node.loc.start))); - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - } else if (error.source && error.locations) { - var source = error.source; - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = error.locations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var location = _step2.value; - printedLocations.push(highlightSourceAtLocation(source, location)); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2.return != null) { - _iterator2.return(); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - } - - return printedLocations.length === 0 ? error.message : [error.message].concat(printedLocations).join('\n\n') + '\n'; - } - /** - * Render a helpful description of the location of the error in the GraphQL - * Source document. - */ - - function highlightSourceAtLocation(source, location) { - var firstLineColumnOffset = source.locationOffset.column - 1; - var body = whitespace(firstLineColumnOffset) + source.body; - var lineIndex = location.line - 1; - var lineOffset = source.locationOffset.line - 1; - var lineNum = location.line + lineOffset; - var columnOffset = location.line === 1 ? firstLineColumnOffset : 0; - var columnNum = location.column + columnOffset; - var lines = body.split(/\r\n|[\n\r]/g); - return "".concat(source.name, " (").concat(lineNum, ":").concat(columnNum, ")\n") + printPrefixedLines([// Lines specified like this: ["prefix", "string"], - ["".concat(lineNum - 1, ": "), lines[lineIndex - 1]], ["".concat(lineNum, ": "), lines[lineIndex]], ['', whitespace(columnNum - 1) + '^'], ["".concat(lineNum + 1, ": "), lines[lineIndex + 1]]]); - } - - function printPrefixedLines(lines) { - var existingLines = lines.filter(function (_ref) { - var _ = _ref[0], - line = _ref[1]; - return line !== undefined; - }); - var padLen = 0; - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = existingLines[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var _ref4 = _step3.value; - var prefix = _ref4[0]; - padLen = Math.max(padLen, prefix.length); - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3.return != null) { - _iterator3.return(); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - return existingLines.map(function (_ref3) { - var prefix = _ref3[0], - line = _ref3[1]; - return lpad(padLen, prefix) + line; - }).join('\n'); - } - - function whitespace(len) { - return Array(len + 1).join(' '); - } - - function lpad(len, str) { - return whitespace(len - str.length) + str; - } - - function _typeof$2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); } - /** - * A GraphQLError describes an Error found during the parse, validate, or - * execute phases of performing a GraphQL operation. In addition to a message - * and stack trace, it also includes information about the locations in a - * GraphQL document and/or execution result that correspond to the Error. - */ - - function GraphQLError( // eslint-disable-line no-redeclare - message, nodes, source, positions, path, originalError, extensions) { - // Compute list of blame nodes. - var _nodes = Array.isArray(nodes) ? nodes.length !== 0 ? nodes : undefined : nodes ? [nodes] : undefined; // Compute locations in the source for the given nodes/positions. - - - var _source = source; - - if (!_source && _nodes) { - var node = _nodes[0]; - _source = node && node.loc && node.loc.source; - } - - var _positions = positions; - - if (!_positions && _nodes) { - _positions = _nodes.reduce(function (list, node) { - if (node.loc) { - list.push(node.loc.start); - } - - return list; - }, []); - } - - if (_positions && _positions.length === 0) { - _positions = undefined; - } - - var _locations; - - if (positions && source) { - _locations = positions.map(function (pos) { - return getLocation(source, pos); - }); - } else if (_nodes) { - _locations = _nodes.reduce(function (list, node) { - if (node.loc) { - list.push(getLocation(node.loc.source, node.loc.start)); - } - - return list; - }, []); - } - - var _extensions = extensions; - - if (_extensions == null && originalError != null) { - var originalExtensions = originalError.extensions; - - if (originalExtensions != null && _typeof$2(originalExtensions) === 'object') { - _extensions = originalExtensions; - } - } - - Object.defineProperties(this, { - message: { - value: message, - // By being enumerable, JSON.stringify will include `message` in the - // resulting output. This ensures that the simplest possible GraphQL - // service adheres to the spec. - enumerable: true, - writable: true - }, - locations: { - // Coercing falsey values to undefined ensures they will not be included - // in JSON.stringify() when not provided. - value: _locations || undefined, - // By being enumerable, JSON.stringify will include `locations` in the - // resulting output. This ensures that the simplest possible GraphQL - // service adheres to the spec. - enumerable: Boolean(_locations) - }, - path: { - // Coercing falsey values to undefined ensures they will not be included - // in JSON.stringify() when not provided. - value: path || undefined, - // By being enumerable, JSON.stringify will include `path` in the - // resulting output. This ensures that the simplest possible GraphQL - // service adheres to the spec. - enumerable: Boolean(path) - }, - nodes: { - value: _nodes || undefined - }, - source: { - value: _source || undefined - }, - positions: { - value: _positions || undefined - }, - originalError: { - value: originalError - }, - extensions: { - // Coercing falsey values to undefined ensures they will not be included - // in JSON.stringify() when not provided. - value: _extensions || undefined, - // By being enumerable, JSON.stringify will include `path` in the - // resulting output. This ensures that the simplest possible GraphQL - // service adheres to the spec. - enumerable: Boolean(_extensions) - } - }); // Include (non-enumerable) stack trace. - - if (originalError && originalError.stack) { - Object.defineProperty(this, 'stack', { - value: originalError.stack, - writable: true, - configurable: true - }); - } else if (Error.captureStackTrace) { - Error.captureStackTrace(this, GraphQLError); - } else { - Object.defineProperty(this, 'stack', { - value: Error().stack, - writable: true, - configurable: true - }); - } - } - GraphQLError.prototype = Object.create(Error.prototype, { - constructor: { - value: GraphQLError - }, - name: { - value: 'GraphQLError' - }, - toString: { - value: function toString() { - return printError(this); - } - } - }); - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - /** - * Produces a GraphQLError representing a syntax error, containing useful - * descriptive information about the syntax error's position in the source. - */ - - function syntaxError(source, position, description) { - return new GraphQLError("Syntax Error: ".concat(description), undefined, source, [position]); - } - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * Produces the value of a block string from its parsed raw value, similar to - * CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc. - * - * This implements the GraphQL spec's BlockStringValue() static algorithm. - */ - function dedentBlockStringValue(rawString) { - // Expand a block string's raw value into independent lines. - var lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first. - - var commonIndent = getBlockStringIndentation(lines); - - if (commonIndent !== 0) { - for (var i = 1; i < lines.length; i++) { - lines[i] = lines[i].slice(commonIndent); - } - } // Remove leading and trailing blank lines. - - - while (lines.length > 0 && isBlank(lines[0])) { - lines.shift(); - } - - while (lines.length > 0 && isBlank(lines[lines.length - 1])) { - lines.pop(); - } // Return a string of the lines joined with U+000A. - - - return lines.join('\n'); - } // @internal - - function getBlockStringIndentation(lines) { - var commonIndent = null; - - for (var i = 1; i < lines.length; i++) { - var line = lines[i]; - var indent = leadingWhitespace(line); - - if (indent === line.length) { - continue; // skip empty lines - } - - if (commonIndent === null || indent < commonIndent) { - commonIndent = indent; - - if (commonIndent === 0) { - break; - } - } - } - - return commonIndent === null ? 0 : commonIndent; - } - - function leadingWhitespace(str) { - var i = 0; - - while (i < str.length && (str[i] === ' ' || str[i] === '\t')) { - i++; - } - - return i; - } - - function isBlank(str) { - return leadingWhitespace(str) === str.length; - } - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - /** - * Given a Source object, this returns a Lexer for that source. - * A Lexer is a stateful stream generator in that every time - * it is advanced, it returns the next token in the Source. Assuming the - * source lexes, the final Token emitted by the lexer will be of kind - * EOF, after which the lexer will repeatedly return the same EOF token - * whenever called. - */ - - function createLexer(source, options) { - var startOfFileToken = new Tok(TokenKind.SOF, 0, 0, 0, 0, null); - var lexer = { - source: source, - options: options, - lastToken: startOfFileToken, - token: startOfFileToken, - line: 1, - lineStart: 0, - advance: advanceLexer, - lookahead: lookahead - }; - return lexer; - } - - function advanceLexer() { - this.lastToken = this.token; - var token = this.token = this.lookahead(); - return token; - } - - function lookahead() { - var token = this.token; - - if (token.kind !== TokenKind.EOF) { - do { - // Note: next is only mutable during parsing, so we cast to allow this. - token = token.next || (token.next = readToken(this, token)); - } while (token.kind === TokenKind.COMMENT); - } - - return token; - } - /** - * The return type of createLexer. - */ - - - /** - * An exported enum describing the different kinds of tokens that the - * lexer emits. - */ - var TokenKind = Object.freeze({ - SOF: '', - EOF: '', - BANG: '!', - DOLLAR: '$', - AMP: '&', - PAREN_L: '(', - PAREN_R: ')', - SPREAD: '...', - COLON: ':', - EQUALS: '=', - AT: '@', - BRACKET_L: '[', - BRACKET_R: ']', - BRACE_L: '{', - PIPE: '|', - BRACE_R: '}', - NAME: 'Name', - INT: 'Int', - FLOAT: 'Float', - STRING: 'String', - BLOCK_STRING: 'BlockString', - COMMENT: 'Comment' - }); - /** - * A helper function to describe a token as a string for debugging - */ - - function getTokenDesc(token) { - var value = token.value; - return value ? "".concat(token.kind, " \"").concat(value, "\"") : token.kind; - } - /** - * Helper function for constructing the Token object. - */ - - function Tok(kind, start, end, line, column, prev, value) { - this.kind = kind; - this.start = start; - this.end = end; - this.line = line; - this.column = column; - this.value = value; - this.prev = prev; - this.next = null; - } // Print a simplified form when appearing in JSON/util.inspect. - - - defineToJSON(Tok, function () { - return { - kind: this.kind, - value: this.value, - line: this.line, - column: this.column - }; - }); - - function printCharCode(code) { - return (// NaN/undefined represents access beyond the end of the file. - isNaN(code) ? TokenKind.EOF : // Trust JSON for ASCII. - code < 0x007f ? JSON.stringify(String.fromCharCode(code)) : // Otherwise print the escaped form. - "\"\\u".concat(('00' + code.toString(16).toUpperCase()).slice(-4), "\"") - ); - } - /** - * Gets the next token from the source starting at the given position. - * - * This skips over whitespace until it finds the next lexable token, then lexes - * punctuators immediately or calls the appropriate helper function for more - * complicated tokens. - */ - - - function readToken(lexer, prev) { - var source = lexer.source; - var body = source.body; - var bodyLength = body.length; - var pos = positionAfterWhitespace(body, prev.end, lexer); - var line = lexer.line; - var col = 1 + pos - lexer.lineStart; - - if (pos >= bodyLength) { - return new Tok(TokenKind.EOF, bodyLength, bodyLength, line, col, prev); - } - - var code = body.charCodeAt(pos); // SourceCharacter - - switch (code) { - // ! - case 33: - return new Tok(TokenKind.BANG, pos, pos + 1, line, col, prev); - // # - - case 35: - return readComment(source, pos, line, col, prev); - // $ - - case 36: - return new Tok(TokenKind.DOLLAR, pos, pos + 1, line, col, prev); - // & - - case 38: - return new Tok(TokenKind.AMP, pos, pos + 1, line, col, prev); - // ( - - case 40: - return new Tok(TokenKind.PAREN_L, pos, pos + 1, line, col, prev); - // ) - - case 41: - return new Tok(TokenKind.PAREN_R, pos, pos + 1, line, col, prev); - // . - - case 46: - if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) { - return new Tok(TokenKind.SPREAD, pos, pos + 3, line, col, prev); - } - - break; - // : - - case 58: - return new Tok(TokenKind.COLON, pos, pos + 1, line, col, prev); - // = - - case 61: - return new Tok(TokenKind.EQUALS, pos, pos + 1, line, col, prev); - // @ - - case 64: - return new Tok(TokenKind.AT, pos, pos + 1, line, col, prev); - // [ - - case 91: - return new Tok(TokenKind.BRACKET_L, pos, pos + 1, line, col, prev); - // ] - - case 93: - return new Tok(TokenKind.BRACKET_R, pos, pos + 1, line, col, prev); - // { - - case 123: - return new Tok(TokenKind.BRACE_L, pos, pos + 1, line, col, prev); - // | - - case 124: - return new Tok(TokenKind.PIPE, pos, pos + 1, line, col, prev); - // } - - case 125: - return new Tok(TokenKind.BRACE_R, pos, pos + 1, line, col, prev); - // A-Z _ a-z - - case 65: - case 66: - case 67: - case 68: - case 69: - case 70: - case 71: - case 72: - case 73: - case 74: - case 75: - case 76: - case 77: - case 78: - case 79: - case 80: - case 81: - case 82: - case 83: - case 84: - case 85: - case 86: - case 87: - case 88: - case 89: - case 90: - case 95: - case 97: - case 98: - case 99: - case 100: - case 101: - case 102: - case 103: - case 104: - case 105: - case 106: - case 107: - case 108: - case 109: - case 110: - case 111: - case 112: - case 113: - case 114: - case 115: - case 116: - case 117: - case 118: - case 119: - case 120: - case 121: - case 122: - return readName(source, pos, line, col, prev); - // - 0-9 - - case 45: - case 48: - case 49: - case 50: - case 51: - case 52: - case 53: - case 54: - case 55: - case 56: - case 57: - return readNumber(source, pos, code, line, col, prev); - // " - - case 34: - if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) { - return readBlockString(source, pos, line, col, prev, lexer); - } - - return readString(source, pos, line, col, prev); - } - - throw syntaxError(source, pos, unexpectedCharacterMessage(code)); - } - /** - * Report a message that an unexpected character was encountered. - */ - - - function unexpectedCharacterMessage(code) { - if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) { - return "Cannot contain the invalid character ".concat(printCharCode(code), "."); - } - - if (code === 39) { - // ' - return "Unexpected single quote character ('), did you mean to use " + 'a double quote (")?'; - } - - return "Cannot parse the unexpected character ".concat(printCharCode(code), "."); - } - /** - * Reads from body starting at startPosition until it finds a non-whitespace - * character, then returns the position of that character for lexing. - */ - - - function positionAfterWhitespace(body, startPosition, lexer) { - var bodyLength = body.length; - var position = startPosition; - - while (position < bodyLength) { - var code = body.charCodeAt(position); // tab | space | comma | BOM - - if (code === 9 || code === 32 || code === 44 || code === 0xfeff) { - ++position; - } else if (code === 10) { - // new line - ++position; - ++lexer.line; - lexer.lineStart = position; - } else if (code === 13) { - // carriage return - if (body.charCodeAt(position + 1) === 10) { - position += 2; - } else { - ++position; - } - - ++lexer.line; - lexer.lineStart = position; - } else { - break; - } - } - - return position; - } - /** - * Reads a comment token from the source file. - * - * #[\u0009\u0020-\uFFFF]* - */ - - - function readComment(source, start, line, col, prev) { - var body = source.body; - var code; - var position = start; - - do { - code = body.charCodeAt(++position); - } while (!isNaN(code) && ( // SourceCharacter but not LineTerminator - code > 0x001f || code === 0x0009)); - - return new Tok(TokenKind.COMMENT, start, position, line, col, prev, body.slice(start + 1, position)); - } - /** - * Reads a number token from the source file, either a float - * or an int depending on whether a decimal point appears. - * - * Int: -?(0|[1-9][0-9]*) - * Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)? - */ - - - function readNumber(source, start, firstCode, line, col, prev) { - var body = source.body; - var code = firstCode; - var position = start; - var isFloat = false; - - if (code === 45) { - // - - code = body.charCodeAt(++position); - } - - if (code === 48) { - // 0 - code = body.charCodeAt(++position); - - if (code >= 48 && code <= 57) { - throw syntaxError(source, position, "Invalid number, unexpected digit after 0: ".concat(printCharCode(code), ".")); - } - } else { - position = readDigits(source, position, code); - code = body.charCodeAt(position); - } - - if (code === 46) { - // . - isFloat = true; - code = body.charCodeAt(++position); - position = readDigits(source, position, code); - code = body.charCodeAt(position); - } - - if (code === 69 || code === 101) { - // E e - isFloat = true; - code = body.charCodeAt(++position); - - if (code === 43 || code === 45) { - // + - - code = body.charCodeAt(++position); - } - - position = readDigits(source, position, code); - } - - return new Tok(isFloat ? TokenKind.FLOAT : TokenKind.INT, start, position, line, col, prev, body.slice(start, position)); - } - /** - * Returns the new position in the source after reading digits. - */ - - - function readDigits(source, start, firstCode) { - var body = source.body; - var position = start; - var code = firstCode; - - if (code >= 48 && code <= 57) { - // 0 - 9 - do { - code = body.charCodeAt(++position); - } while (code >= 48 && code <= 57); // 0 - 9 - - - return position; - } - - throw syntaxError(source, position, "Invalid number, expected digit but got: ".concat(printCharCode(code), ".")); - } - /** - * Reads a string token from the source file. - * - * "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*" - */ - - - function readString(source, start, line, col, prev) { - var body = source.body; - var position = start + 1; - var chunkStart = position; - var code = 0; - var value = ''; - - while (position < body.length && !isNaN(code = body.charCodeAt(position)) && // not LineTerminator - code !== 0x000a && code !== 0x000d) { - // Closing Quote (") - if (code === 34) { - value += body.slice(chunkStart, position); - return new Tok(TokenKind.STRING, start, position + 1, line, col, prev, value); - } // SourceCharacter - - - if (code < 0x0020 && code !== 0x0009) { - throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), ".")); - } - - ++position; - - if (code === 92) { - // \ - value += body.slice(chunkStart, position - 1); - code = body.charCodeAt(position); - - switch (code) { - case 34: - value += '"'; - break; - - case 47: - value += '/'; - break; - - case 92: - value += '\\'; - break; - - case 98: - value += '\b'; - break; - - case 102: - value += '\f'; - break; - - case 110: - value += '\n'; - break; - - case 114: - value += '\r'; - break; - - case 116: - value += '\t'; - break; - - case 117: - { - // uXXXX - var charCode = uniCharCode(body.charCodeAt(position + 1), body.charCodeAt(position + 2), body.charCodeAt(position + 3), body.charCodeAt(position + 4)); - - if (charCode < 0) { - throw syntaxError(source, position, 'Invalid character escape sequence: ' + "\\u".concat(body.slice(position + 1, position + 5), ".")); - } - - value += String.fromCharCode(charCode); - position += 4; - break; - } - - default: - throw syntaxError(source, position, "Invalid character escape sequence: \\".concat(String.fromCharCode(code), ".")); - } - - ++position; - chunkStart = position; - } - } - - throw syntaxError(source, position, 'Unterminated string.'); - } - /** - * Reads a block string token from the source file. - * - * """("?"?(\\"""|\\(?!=""")|[^"\\]))*""" - */ - - - function readBlockString(source, start, line, col, prev, lexer) { - var body = source.body; - var position = start + 3; - var chunkStart = position; - var code = 0; - var rawValue = ''; - - while (position < body.length && !isNaN(code = body.charCodeAt(position))) { - // Closing Triple-Quote (""") - if (code === 34 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34) { - rawValue += body.slice(chunkStart, position); - return new Tok(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, dedentBlockStringValue(rawValue)); - } // SourceCharacter - - - if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) { - throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), ".")); - } - - if (code === 10) { - // new line - ++position; - ++lexer.line; - lexer.lineStart = position; - } else if (code === 13) { - // carriage return - if (body.charCodeAt(position + 1) === 10) { - position += 2; - } else { - ++position; - } - - ++lexer.line; - lexer.lineStart = position; - } else if ( // Escape Triple-Quote (\""") - code === 92 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34 && body.charCodeAt(position + 3) === 34) { - rawValue += body.slice(chunkStart, position) + '"""'; - position += 4; - chunkStart = position; - } else { - ++position; - } - } - - throw syntaxError(source, position, 'Unterminated string.'); - } - /** - * Converts four hexadecimal chars to the integer that the - * string represents. For example, uniCharCode('0','0','0','f') - * will return 15, and uniCharCode('0','0','f','f') returns 255. - * - * Returns a negative number on error, if a char was invalid. - * - * This is implemented by noting that char2hex() returns -1 on error, - * which means the result of ORing the char2hex() will also be negative. - */ - - - function uniCharCode(a, b, c, d) { - return char2hex(a) << 12 | char2hex(b) << 8 | char2hex(c) << 4 | char2hex(d); - } - /** - * Converts a hex character to its integer value. - * '0' becomes 0, '9' becomes 9 - * 'A' becomes 10, 'F' becomes 15 - * 'a' becomes 10, 'f' becomes 15 - * - * Returns -1 on error. - */ - - - function char2hex(a) { - return a >= 48 && a <= 57 ? a - 48 // 0-9 - : a >= 65 && a <= 70 ? a - 55 // A-F - : a >= 97 && a <= 102 ? a - 87 // a-f - : -1; - } - /** - * Reads an alphanumeric + underscore name from the source. - * - * [_A-Za-z][_0-9A-Za-z]* - */ - - - function readName(source, start, line, col, prev) { - var body = source.body; - var bodyLength = body.length; - var position = start + 1; - var code = 0; - - while (position !== bodyLength && !isNaN(code = body.charCodeAt(position)) && (code === 95 || // _ - code >= 48 && code <= 57 || // 0-9 - code >= 65 && code <= 90 || // A-Z - code >= 97 && code <= 122) // a-z - ) { - ++position; - } - - return new Tok(TokenKind.NAME, start, position, line, col, prev, body.slice(start, position)); - } - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * The set of allowed kind values for AST nodes. - */ - var Kind = Object.freeze({ - // Name - NAME: 'Name', - // Document - DOCUMENT: 'Document', - OPERATION_DEFINITION: 'OperationDefinition', - VARIABLE_DEFINITION: 'VariableDefinition', - SELECTION_SET: 'SelectionSet', - FIELD: 'Field', - ARGUMENT: 'Argument', - // Fragments - FRAGMENT_SPREAD: 'FragmentSpread', - INLINE_FRAGMENT: 'InlineFragment', - FRAGMENT_DEFINITION: 'FragmentDefinition', - // Values - VARIABLE: 'Variable', - INT: 'IntValue', - FLOAT: 'FloatValue', - STRING: 'StringValue', - BOOLEAN: 'BooleanValue', - NULL: 'NullValue', - ENUM: 'EnumValue', - LIST: 'ListValue', - OBJECT: 'ObjectValue', - OBJECT_FIELD: 'ObjectField', - // Directives - DIRECTIVE: 'Directive', - // Types - NAMED_TYPE: 'NamedType', - LIST_TYPE: 'ListType', - NON_NULL_TYPE: 'NonNullType', - // Type System Definitions - SCHEMA_DEFINITION: 'SchemaDefinition', - OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition', - // Type Definitions - SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition', - OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition', - FIELD_DEFINITION: 'FieldDefinition', - INPUT_VALUE_DEFINITION: 'InputValueDefinition', - INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition', - UNION_TYPE_DEFINITION: 'UnionTypeDefinition', - ENUM_TYPE_DEFINITION: 'EnumTypeDefinition', - ENUM_VALUE_DEFINITION: 'EnumValueDefinition', - INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition', - // Directive Definitions - DIRECTIVE_DEFINITION: 'DirectiveDefinition', - // Type System Extensions - SCHEMA_EXTENSION: 'SchemaExtension', - // Type Extensions - SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension', - OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension', - INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension', - UNION_TYPE_EXTENSION: 'UnionTypeExtension', - ENUM_TYPE_EXTENSION: 'EnumTypeExtension', - INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension' - }); - /** - * The enum type representing the possible kind values of AST nodes. - */ - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - - /** - * The set of allowed directive location values. - */ - var DirectiveLocation = Object.freeze({ - // Request Definitions - QUERY: 'QUERY', - MUTATION: 'MUTATION', - SUBSCRIPTION: 'SUBSCRIPTION', - FIELD: 'FIELD', - FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION', - FRAGMENT_SPREAD: 'FRAGMENT_SPREAD', - INLINE_FRAGMENT: 'INLINE_FRAGMENT', - VARIABLE_DEFINITION: 'VARIABLE_DEFINITION', - // Type System Definitions - SCHEMA: 'SCHEMA', - SCALAR: 'SCALAR', - OBJECT: 'OBJECT', - FIELD_DEFINITION: 'FIELD_DEFINITION', - ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION', - INTERFACE: 'INTERFACE', - UNION: 'UNION', - ENUM: 'ENUM', - ENUM_VALUE: 'ENUM_VALUE', - INPUT_OBJECT: 'INPUT_OBJECT', - INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION' - }); - /** - * The enum type representing the directive location values. - */ - - /** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - /** - * Configuration options to control parser behavior - */ - - /** - * Given a GraphQL source, parses it into a Document. - * Throws GraphQLError if a syntax error is encountered. - */ - function parse(source, options) { - var sourceObj = typeof source === 'string' ? new Source(source) : source; - - if (!(sourceObj instanceof Source)) { - throw new TypeError("Must provide Source. Received: ".concat(inspect(sourceObj))); - } - - var lexer = createLexer(sourceObj, options || {}); - return parseDocument(lexer); - } - /** - * Given a string containing a GraphQL value (ex. `[42]`), parse the AST for - * that value. - * Throws GraphQLError if a syntax error is encountered. - * - * This is useful within tools that operate upon GraphQL Values directly and - * in isolation of complete GraphQL documents. - * - * Consider providing the results to the utility function: valueFromAST(). - */ - - function parseValue(source, options) { - var sourceObj = typeof source === 'string' ? new Source(source) : source; - var lexer = createLexer(sourceObj, options || {}); - expectToken(lexer, TokenKind.SOF); - var value = parseValueLiteral(lexer, false); - expectToken(lexer, TokenKind.EOF); - return value; - } - /** - * Given a string containing a GraphQL Type (ex. `[Int!]`), parse the AST for - * that type. - * Throws GraphQLError if a syntax error is encountered. - * - * This is useful within tools that operate upon GraphQL Types directly and - * in isolation of complete GraphQL documents. - * - * Consider providing the results to the utility function: typeFromAST(). - */ - - function parseType(source, options) { - var sourceObj = typeof source === 'string' ? new Source(source) : source; - var lexer = createLexer(sourceObj, options || {}); - expectToken(lexer, TokenKind.SOF); - var type = parseTypeReference(lexer); - expectToken(lexer, TokenKind.EOF); - return type; - } - /** - * Converts a name lex token into a name parse node. - */ - - function parseName(lexer) { - var token = expectToken(lexer, TokenKind.NAME); - return { - kind: Kind.NAME, - value: token.value, - loc: loc(lexer, token) - }; - } // Implements the parsing rules in the Document section. - - /** - * Document : Definition+ - */ - - - function parseDocument(lexer) { - var start = lexer.token; - return { - kind: Kind.DOCUMENT, - definitions: many(lexer, TokenKind.SOF, parseDefinition, TokenKind.EOF), - loc: loc(lexer, start) - }; - } - /** - * Definition : - * - ExecutableDefinition - * - TypeSystemDefinition - * - TypeSystemExtension - */ - - - function parseDefinition(lexer) { - if (peek(lexer, TokenKind.NAME)) { - switch (lexer.token.value) { - case 'query': - case 'mutation': - case 'subscription': - case 'fragment': - return parseExecutableDefinition(lexer); - - case 'schema': - case 'scalar': - case 'type': - case 'interface': - case 'union': - case 'enum': - case 'input': - case 'directive': - return parseTypeSystemDefinition(lexer); - - case 'extend': - return parseTypeSystemExtension(lexer); - } - } else if (peek(lexer, TokenKind.BRACE_L)) { - return parseExecutableDefinition(lexer); - } else if (peekDescription(lexer)) { - return parseTypeSystemDefinition(lexer); - } - - throw unexpected(lexer); - } - /** - * ExecutableDefinition : - * - OperationDefinition - * - FragmentDefinition - */ - - - function parseExecutableDefinition(lexer) { - if (peek(lexer, TokenKind.NAME)) { - switch (lexer.token.value) { - case 'query': - case 'mutation': - case 'subscription': - return parseOperationDefinition(lexer); - - case 'fragment': - return parseFragmentDefinition(lexer); - } - } else if (peek(lexer, TokenKind.BRACE_L)) { - return parseOperationDefinition(lexer); - } - - throw unexpected(lexer); - } // Implements the parsing rules in the Operations section. - - /** - * OperationDefinition : - * - SelectionSet - * - OperationType Name? VariableDefinitions? Directives? SelectionSet - */ - - - function parseOperationDefinition(lexer) { - var start = lexer.token; - - if (peek(lexer, TokenKind.BRACE_L)) { - return { - kind: Kind.OPERATION_DEFINITION, - operation: 'query', - name: undefined, - variableDefinitions: [], - directives: [], - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; - } - - var operation = parseOperationType(lexer); - var name; - - if (peek(lexer, TokenKind.NAME)) { - name = parseName(lexer); - } - - return { - kind: Kind.OPERATION_DEFINITION, - operation: operation, - name: name, - variableDefinitions: parseVariableDefinitions(lexer), - directives: parseDirectives(lexer, false), - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; - } - /** - * OperationType : one of query mutation subscription - */ - - - function parseOperationType(lexer) { - var operationToken = expectToken(lexer, TokenKind.NAME); - - switch (operationToken.value) { - case 'query': - return 'query'; - - case 'mutation': - return 'mutation'; - - case 'subscription': - return 'subscription'; - } - - throw unexpected(lexer, operationToken); - } - /** - * VariableDefinitions : ( VariableDefinition+ ) - */ - - - function parseVariableDefinitions(lexer) { - return peek(lexer, TokenKind.PAREN_L) ? many(lexer, TokenKind.PAREN_L, parseVariableDefinition, TokenKind.PAREN_R) : []; - } - /** - * VariableDefinition : Variable : Type DefaultValue? Directives[Const]? - */ - - - function parseVariableDefinition(lexer) { - var start = lexer.token; - return { - kind: Kind.VARIABLE_DEFINITION, - variable: parseVariable(lexer), - type: (expectToken(lexer, TokenKind.COLON), parseTypeReference(lexer)), - defaultValue: expectOptionalToken(lexer, TokenKind.EQUALS) ? parseValueLiteral(lexer, true) : undefined, - directives: parseDirectives(lexer, true), - loc: loc(lexer, start) - }; - } - /** - * Variable : $ Name - */ - - - function parseVariable(lexer) { - var start = lexer.token; - expectToken(lexer, TokenKind.DOLLAR); - return { - kind: Kind.VARIABLE, - name: parseName(lexer), - loc: loc(lexer, start) - }; - } - /** - * SelectionSet : { Selection+ } - */ - - - function parseSelectionSet(lexer) { - var start = lexer.token; - return { - kind: Kind.SELECTION_SET, - selections: many(lexer, TokenKind.BRACE_L, parseSelection, TokenKind.BRACE_R), - loc: loc(lexer, start) - }; - } - /** - * Selection : - * - Field - * - FragmentSpread - * - InlineFragment - */ - - - function parseSelection(lexer) { - return peek(lexer, TokenKind.SPREAD) ? parseFragment(lexer) : parseField(lexer); - } - /** - * Field : Alias? Name Arguments? Directives? SelectionSet? - * - * Alias : Name : - */ - - - function parseField(lexer) { - var start = lexer.token; - var nameOrAlias = parseName(lexer); - var alias; - var name; - - if (expectOptionalToken(lexer, TokenKind.COLON)) { - alias = nameOrAlias; - name = parseName(lexer); - } else { - name = nameOrAlias; - } - - return { - kind: Kind.FIELD, - alias: alias, - name: name, - arguments: parseArguments(lexer, false), - directives: parseDirectives(lexer, false), - selectionSet: peek(lexer, TokenKind.BRACE_L) ? parseSelectionSet(lexer) : undefined, - loc: loc(lexer, start) - }; - } - /** - * Arguments[Const] : ( Argument[?Const]+ ) - */ - - - function parseArguments(lexer, isConst) { - var item = isConst ? parseConstArgument : parseArgument; - return peek(lexer, TokenKind.PAREN_L) ? many(lexer, TokenKind.PAREN_L, item, TokenKind.PAREN_R) : []; - } - /** - * Argument[Const] : Name : Value[?Const] - */ - - - function parseArgument(lexer) { - var start = lexer.token; - var name = parseName(lexer); - expectToken(lexer, TokenKind.COLON); - return { - kind: Kind.ARGUMENT, - name: name, - value: parseValueLiteral(lexer, false), - loc: loc(lexer, start) - }; - } - - function parseConstArgument(lexer) { - var start = lexer.token; - return { - kind: Kind.ARGUMENT, - name: parseName(lexer), - value: (expectToken(lexer, TokenKind.COLON), parseConstValue(lexer)), - loc: loc(lexer, start) - }; - } // Implements the parsing rules in the Fragments section. - - /** - * Corresponds to both FragmentSpread and InlineFragment in the spec. - * - * FragmentSpread : ... FragmentName Directives? - * - * InlineFragment : ... TypeCondition? Directives? SelectionSet - */ - - - function parseFragment(lexer) { - var start = lexer.token; - expectToken(lexer, TokenKind.SPREAD); - var hasTypeCondition = expectOptionalKeyword(lexer, 'on'); - - if (!hasTypeCondition && peek(lexer, TokenKind.NAME)) { - return { - kind: Kind.FRAGMENT_SPREAD, - name: parseFragmentName(lexer), - directives: parseDirectives(lexer, false), - loc: loc(lexer, start) - }; - } - - return { - kind: Kind.INLINE_FRAGMENT, - typeCondition: hasTypeCondition ? parseNamedType(lexer) : undefined, - directives: parseDirectives(lexer, false), - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; - } - /** - * FragmentDefinition : - * - fragment FragmentName on TypeCondition Directives? SelectionSet - * - * TypeCondition : NamedType - */ - - - function parseFragmentDefinition(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'fragment'); // Experimental support for defining variables within fragments changes - // the grammar of FragmentDefinition: - // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet - - if (lexer.options.experimentalFragmentVariables) { - return { - kind: Kind.FRAGMENT_DEFINITION, - name: parseFragmentName(lexer), - variableDefinitions: parseVariableDefinitions(lexer), - typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)), - directives: parseDirectives(lexer, false), - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; - } - - return { - kind: Kind.FRAGMENT_DEFINITION, - name: parseFragmentName(lexer), - typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)), - directives: parseDirectives(lexer, false), - selectionSet: parseSelectionSet(lexer), - loc: loc(lexer, start) - }; - } - /** - * FragmentName : Name but not `on` - */ - - - function parseFragmentName(lexer) { - if (lexer.token.value === 'on') { - throw unexpected(lexer); - } - - return parseName(lexer); - } // Implements the parsing rules in the Values section. - - /** - * Value[Const] : - * - [~Const] Variable - * - IntValue - * - FloatValue - * - StringValue - * - BooleanValue - * - NullValue - * - EnumValue - * - ListValue[?Const] - * - ObjectValue[?Const] - * - * BooleanValue : one of `true` `false` - * - * NullValue : `null` - * - * EnumValue : Name but not `true`, `false` or `null` - */ - - - function parseValueLiteral(lexer, isConst) { - var token = lexer.token; - - switch (token.kind) { - case TokenKind.BRACKET_L: - return parseList(lexer, isConst); - - case TokenKind.BRACE_L: - return parseObject(lexer, isConst); - - case TokenKind.INT: - lexer.advance(); - return { - kind: Kind.INT, - value: token.value, - loc: loc(lexer, token) - }; - - case TokenKind.FLOAT: - lexer.advance(); - return { - kind: Kind.FLOAT, - value: token.value, - loc: loc(lexer, token) - }; - - case TokenKind.STRING: - case TokenKind.BLOCK_STRING: - return parseStringLiteral(lexer); - - case TokenKind.NAME: - if (token.value === 'true' || token.value === 'false') { - lexer.advance(); - return { - kind: Kind.BOOLEAN, - value: token.value === 'true', - loc: loc(lexer, token) - }; - } else if (token.value === 'null') { - lexer.advance(); - return { - kind: Kind.NULL, - loc: loc(lexer, token) - }; - } - - lexer.advance(); - return { - kind: Kind.ENUM, - value: token.value, - loc: loc(lexer, token) - }; - - case TokenKind.DOLLAR: - if (!isConst) { - return parseVariable(lexer); - } - - break; - } - - throw unexpected(lexer); - } - - function parseStringLiteral(lexer) { - var token = lexer.token; - lexer.advance(); - return { - kind: Kind.STRING, - value: token.value, - block: token.kind === TokenKind.BLOCK_STRING, - loc: loc(lexer, token) - }; - } - - function parseConstValue(lexer) { - return parseValueLiteral(lexer, true); - } - - function parseValueValue(lexer) { - return parseValueLiteral(lexer, false); - } - /** - * ListValue[Const] : - * - [ ] - * - [ Value[?Const]+ ] - */ - - - function parseList(lexer, isConst) { - var start = lexer.token; - var item = isConst ? parseConstValue : parseValueValue; - return { - kind: Kind.LIST, - values: any(lexer, TokenKind.BRACKET_L, item, TokenKind.BRACKET_R), - loc: loc(lexer, start) - }; - } - /** - * ObjectValue[Const] : - * - { } - * - { ObjectField[?Const]+ } - */ - - - function parseObject(lexer, isConst) { - var start = lexer.token; - - var item = function item() { - return parseObjectField(lexer, isConst); - }; - - return { - kind: Kind.OBJECT, - fields: any(lexer, TokenKind.BRACE_L, item, TokenKind.BRACE_R), - loc: loc(lexer, start) - }; - } - /** - * ObjectField[Const] : Name : Value[?Const] - */ - - - function parseObjectField(lexer, isConst) { - var start = lexer.token; - var name = parseName(lexer); - expectToken(lexer, TokenKind.COLON); - return { - kind: Kind.OBJECT_FIELD, - name: name, - value: parseValueLiteral(lexer, isConst), - loc: loc(lexer, start) - }; - } // Implements the parsing rules in the Directives section. - - /** - * Directives[Const] : Directive[?Const]+ - */ - - - function parseDirectives(lexer, isConst) { - var directives = []; - - while (peek(lexer, TokenKind.AT)) { - directives.push(parseDirective(lexer, isConst)); - } - - return directives; - } - /** - * Directive[Const] : @ Name Arguments[?Const]? - */ - - - function parseDirective(lexer, isConst) { - var start = lexer.token; - expectToken(lexer, TokenKind.AT); - return { - kind: Kind.DIRECTIVE, - name: parseName(lexer), - arguments: parseArguments(lexer, isConst), - loc: loc(lexer, start) - }; - } // Implements the parsing rules in the Types section. - - /** - * Type : - * - NamedType - * - ListType - * - NonNullType - */ - - - function parseTypeReference(lexer) { - var start = lexer.token; - var type; - - if (expectOptionalToken(lexer, TokenKind.BRACKET_L)) { - type = parseTypeReference(lexer); - expectToken(lexer, TokenKind.BRACKET_R); - type = { - kind: Kind.LIST_TYPE, - type: type, - loc: loc(lexer, start) - }; - } else { - type = parseNamedType(lexer); - } - - if (expectOptionalToken(lexer, TokenKind.BANG)) { - return { - kind: Kind.NON_NULL_TYPE, - type: type, - loc: loc(lexer, start) - }; - } - - return type; - } - /** - * NamedType : Name - */ - - function parseNamedType(lexer) { - var start = lexer.token; - return { - kind: Kind.NAMED_TYPE, - name: parseName(lexer), - loc: loc(lexer, start) - }; - } // Implements the parsing rules in the Type Definition section. - - /** - * TypeSystemDefinition : - * - SchemaDefinition - * - TypeDefinition - * - DirectiveDefinition - * - * TypeDefinition : - * - ScalarTypeDefinition - * - ObjectTypeDefinition - * - InterfaceTypeDefinition - * - UnionTypeDefinition - * - EnumTypeDefinition - * - InputObjectTypeDefinition - */ - - function parseTypeSystemDefinition(lexer) { - // Many definitions begin with a description and require a lookahead. - var keywordToken = peekDescription(lexer) ? lexer.lookahead() : lexer.token; - - if (keywordToken.kind === TokenKind.NAME) { - switch (keywordToken.value) { - case 'schema': - return parseSchemaDefinition(lexer); - - case 'scalar': - return parseScalarTypeDefinition(lexer); - - case 'type': - return parseObjectTypeDefinition(lexer); - - case 'interface': - return parseInterfaceTypeDefinition(lexer); - - case 'union': - return parseUnionTypeDefinition(lexer); - - case 'enum': - return parseEnumTypeDefinition(lexer); - - case 'input': - return parseInputObjectTypeDefinition(lexer); - - case 'directive': - return parseDirectiveDefinition(lexer); - } - } - - throw unexpected(lexer, keywordToken); - } - - function peekDescription(lexer) { - return peek(lexer, TokenKind.STRING) || peek(lexer, TokenKind.BLOCK_STRING); - } - /** - * Description : StringValue - */ - - - function parseDescription(lexer) { - if (peekDescription(lexer)) { - return parseStringLiteral(lexer); - } - } - /** - * SchemaDefinition : schema Directives[Const]? { OperationTypeDefinition+ } - */ - - - function parseSchemaDefinition(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'schema'); - var directives = parseDirectives(lexer, true); - var operationTypes = many(lexer, TokenKind.BRACE_L, parseOperationTypeDefinition, TokenKind.BRACE_R); - return { - kind: Kind.SCHEMA_DEFINITION, - directives: directives, - operationTypes: operationTypes, - loc: loc(lexer, start) - }; - } - /** - * OperationTypeDefinition : OperationType : NamedType - */ - - - function parseOperationTypeDefinition(lexer) { - var start = lexer.token; - var operation = parseOperationType(lexer); - expectToken(lexer, TokenKind.COLON); - var type = parseNamedType(lexer); - return { - kind: Kind.OPERATION_TYPE_DEFINITION, - operation: operation, - type: type, - loc: loc(lexer, start) - }; - } - /** - * ScalarTypeDefinition : Description? scalar Name Directives[Const]? - */ - - - function parseScalarTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'scalar'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - return { - kind: Kind.SCALAR_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - loc: loc(lexer, start) - }; - } - /** - * ObjectTypeDefinition : - * Description? - * type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition? - */ - - - function parseObjectTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'type'); - var name = parseName(lexer); - var interfaces = parseImplementsInterfaces(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseFieldsDefinition(lexer); - return { - kind: Kind.OBJECT_TYPE_DEFINITION, - description: description, - name: name, - interfaces: interfaces, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; - } - /** - * ImplementsInterfaces : - * - implements `&`? NamedType - * - ImplementsInterfaces & NamedType - */ - - - function parseImplementsInterfaces(lexer) { - var types = []; - - if (expectOptionalKeyword(lexer, 'implements')) { - // Optional leading ampersand - expectOptionalToken(lexer, TokenKind.AMP); - - do { - types.push(parseNamedType(lexer)); - } while (expectOptionalToken(lexer, TokenKind.AMP) || // Legacy support for the SDL? - lexer.options.allowLegacySDLImplementsInterfaces && peek(lexer, TokenKind.NAME)); - } - - return types; - } - /** - * FieldsDefinition : { FieldDefinition+ } - */ - - - function parseFieldsDefinition(lexer) { - // Legacy support for the SDL? - if (lexer.options.allowLegacySDLEmptyFields && peek(lexer, TokenKind.BRACE_L) && lexer.lookahead().kind === TokenKind.BRACE_R) { - lexer.advance(); - lexer.advance(); - return []; - } - - return peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseFieldDefinition, TokenKind.BRACE_R) : []; - } - /** - * FieldDefinition : - * - Description? Name ArgumentsDefinition? : Type Directives[Const]? - */ - - - function parseFieldDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - var name = parseName(lexer); - var args = parseArgumentDefs(lexer); - expectToken(lexer, TokenKind.COLON); - var type = parseTypeReference(lexer); - var directives = parseDirectives(lexer, true); - return { - kind: Kind.FIELD_DEFINITION, - description: description, - name: name, - arguments: args, - type: type, - directives: directives, - loc: loc(lexer, start) - }; - } - /** - * ArgumentsDefinition : ( InputValueDefinition+ ) - */ - - - function parseArgumentDefs(lexer) { - if (!peek(lexer, TokenKind.PAREN_L)) { - return []; - } - - return many(lexer, TokenKind.PAREN_L, parseInputValueDef, TokenKind.PAREN_R); - } - /** - * InputValueDefinition : - * - Description? Name : Type DefaultValue? Directives[Const]? - */ - - - function parseInputValueDef(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - var name = parseName(lexer); - expectToken(lexer, TokenKind.COLON); - var type = parseTypeReference(lexer); - var defaultValue; - - if (expectOptionalToken(lexer, TokenKind.EQUALS)) { - defaultValue = parseConstValue(lexer); - } - - var directives = parseDirectives(lexer, true); - return { - kind: Kind.INPUT_VALUE_DEFINITION, - description: description, - name: name, - type: type, - defaultValue: defaultValue, - directives: directives, - loc: loc(lexer, start) - }; - } - /** - * InterfaceTypeDefinition : - * - Description? interface Name Directives[Const]? FieldsDefinition? - */ - - - function parseInterfaceTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'interface'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseFieldsDefinition(lexer); - return { - kind: Kind.INTERFACE_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; - } - /** - * UnionTypeDefinition : - * - Description? union Name Directives[Const]? UnionMemberTypes? - */ - - - function parseUnionTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'union'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var types = parseUnionMemberTypes(lexer); - return { - kind: Kind.UNION_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - types: types, - loc: loc(lexer, start) - }; - } - /** - * UnionMemberTypes : - * - = `|`? NamedType - * - UnionMemberTypes | NamedType - */ - - - function parseUnionMemberTypes(lexer) { - var types = []; - - if (expectOptionalToken(lexer, TokenKind.EQUALS)) { - // Optional leading pipe - expectOptionalToken(lexer, TokenKind.PIPE); - - do { - types.push(parseNamedType(lexer)); - } while (expectOptionalToken(lexer, TokenKind.PIPE)); - } - - return types; - } - /** - * EnumTypeDefinition : - * - Description? enum Name Directives[Const]? EnumValuesDefinition? - */ - - - function parseEnumTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'enum'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var values = parseEnumValuesDefinition(lexer); - return { - kind: Kind.ENUM_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - values: values, - loc: loc(lexer, start) - }; - } - /** - * EnumValuesDefinition : { EnumValueDefinition+ } - */ - - - function parseEnumValuesDefinition(lexer) { - return peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseEnumValueDefinition, TokenKind.BRACE_R) : []; - } - /** - * EnumValueDefinition : Description? EnumValue Directives[Const]? - * - * EnumValue : Name - */ - - - function parseEnumValueDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - return { - kind: Kind.ENUM_VALUE_DEFINITION, - description: description, - name: name, - directives: directives, - loc: loc(lexer, start) - }; - } - /** - * InputObjectTypeDefinition : - * - Description? input Name Directives[Const]? InputFieldsDefinition? - */ - - - function parseInputObjectTypeDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'input'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseInputFieldsDefinition(lexer); - return { - kind: Kind.INPUT_OBJECT_TYPE_DEFINITION, - description: description, - name: name, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; - } - /** - * InputFieldsDefinition : { InputValueDefinition+ } - */ - - - function parseInputFieldsDefinition(lexer) { - return peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseInputValueDef, TokenKind.BRACE_R) : []; - } - /** - * TypeSystemExtension : - * - SchemaExtension - * - TypeExtension - * - * TypeExtension : - * - ScalarTypeExtension - * - ObjectTypeExtension - * - InterfaceTypeExtension - * - UnionTypeExtension - * - EnumTypeExtension - * - InputObjectTypeDefinition - */ - - - function parseTypeSystemExtension(lexer) { - var keywordToken = lexer.lookahead(); - - if (keywordToken.kind === TokenKind.NAME) { - switch (keywordToken.value) { - case 'schema': - return parseSchemaExtension(lexer); - - case 'scalar': - return parseScalarTypeExtension(lexer); - - case 'type': - return parseObjectTypeExtension(lexer); - - case 'interface': - return parseInterfaceTypeExtension(lexer); - - case 'union': - return parseUnionTypeExtension(lexer); - - case 'enum': - return parseEnumTypeExtension(lexer); - - case 'input': - return parseInputObjectTypeExtension(lexer); - } - } - - throw unexpected(lexer, keywordToken); - } - /** - * SchemaExtension : - * - extend schema Directives[Const]? { OperationTypeDefinition+ } - * - extend schema Directives[Const] - */ - - - function parseSchemaExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'schema'); - var directives = parseDirectives(lexer, true); - var operationTypes = peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseOperationTypeDefinition, TokenKind.BRACE_R) : []; - - if (directives.length === 0 && operationTypes.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.SCHEMA_EXTENSION, - directives: directives, - operationTypes: operationTypes, - loc: loc(lexer, start) - }; - } - /** - * ScalarTypeExtension : - * - extend scalar Name Directives[Const] - */ - - - function parseScalarTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'scalar'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - - if (directives.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.SCALAR_TYPE_EXTENSION, - name: name, - directives: directives, - loc: loc(lexer, start) - }; - } - /** - * ObjectTypeExtension : - * - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition - * - extend type Name ImplementsInterfaces? Directives[Const] - * - extend type Name ImplementsInterfaces - */ - - - function parseObjectTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'type'); - var name = parseName(lexer); - var interfaces = parseImplementsInterfaces(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseFieldsDefinition(lexer); - - if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.OBJECT_TYPE_EXTENSION, - name: name, - interfaces: interfaces, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; - } - /** - * InterfaceTypeExtension : - * - extend interface Name Directives[Const]? FieldsDefinition - * - extend interface Name Directives[Const] - */ - - - function parseInterfaceTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'interface'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseFieldsDefinition(lexer); - - if (directives.length === 0 && fields.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.INTERFACE_TYPE_EXTENSION, - name: name, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; - } - /** - * UnionTypeExtension : - * - extend union Name Directives[Const]? UnionMemberTypes - * - extend union Name Directives[Const] - */ - - - function parseUnionTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'union'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var types = parseUnionMemberTypes(lexer); - - if (directives.length === 0 && types.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.UNION_TYPE_EXTENSION, - name: name, - directives: directives, - types: types, - loc: loc(lexer, start) - }; - } - /** - * EnumTypeExtension : - * - extend enum Name Directives[Const]? EnumValuesDefinition - * - extend enum Name Directives[Const] - */ - - - function parseEnumTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'enum'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var values = parseEnumValuesDefinition(lexer); - - if (directives.length === 0 && values.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.ENUM_TYPE_EXTENSION, - name: name, - directives: directives, - values: values, - loc: loc(lexer, start) - }; - } - /** - * InputObjectTypeExtension : - * - extend input Name Directives[Const]? InputFieldsDefinition - * - extend input Name Directives[Const] - */ - - - function parseInputObjectTypeExtension(lexer) { - var start = lexer.token; - expectKeyword(lexer, 'extend'); - expectKeyword(lexer, 'input'); - var name = parseName(lexer); - var directives = parseDirectives(lexer, true); - var fields = parseInputFieldsDefinition(lexer); - - if (directives.length === 0 && fields.length === 0) { - throw unexpected(lexer); - } - - return { - kind: Kind.INPUT_OBJECT_TYPE_EXTENSION, - name: name, - directives: directives, - fields: fields, - loc: loc(lexer, start) - }; - } - /** - * DirectiveDefinition : - * - Description? directive @ Name ArgumentsDefinition? on DirectiveLocations - */ - - - function parseDirectiveDefinition(lexer) { - var start = lexer.token; - var description = parseDescription(lexer); - expectKeyword(lexer, 'directive'); - expectToken(lexer, TokenKind.AT); - var name = parseName(lexer); - var args = parseArgumentDefs(lexer); - expectKeyword(lexer, 'on'); - var locations = parseDirectiveLocations(lexer); - return { - kind: Kind.DIRECTIVE_DEFINITION, - description: description, - name: name, - arguments: args, - locations: locations, - loc: loc(lexer, start) - }; - } - /** - * DirectiveLocations : - * - `|`? DirectiveLocation - * - DirectiveLocations | DirectiveLocation - */ - - - function parseDirectiveLocations(lexer) { - // Optional leading pipe - expectOptionalToken(lexer, TokenKind.PIPE); - var locations = []; - - do { - locations.push(parseDirectiveLocation(lexer)); - } while (expectOptionalToken(lexer, TokenKind.PIPE)); - - return locations; - } - /* - * DirectiveLocation : - * - ExecutableDirectiveLocation - * - TypeSystemDirectiveLocation - * - * ExecutableDirectiveLocation : one of - * `QUERY` - * `MUTATION` - * `SUBSCRIPTION` - * `FIELD` - * `FRAGMENT_DEFINITION` - * `FRAGMENT_SPREAD` - * `INLINE_FRAGMENT` - * - * TypeSystemDirectiveLocation : one of - * `SCHEMA` - * `SCALAR` - * `OBJECT` - * `FIELD_DEFINITION` - * `ARGUMENT_DEFINITION` - * `INTERFACE` - * `UNION` - * `ENUM` - * `ENUM_VALUE` - * `INPUT_OBJECT` - * `INPUT_FIELD_DEFINITION` - */ - - - function parseDirectiveLocation(lexer) { - var start = lexer.token; - var name = parseName(lexer); - - if (DirectiveLocation[name.value] !== undefined) { - return name; - } - - throw unexpected(lexer, start); - } // Core parsing utility functions - - /** - * Returns a location object, used to identify the place in - * the source that created a given parsed object. - */ - - - function loc(lexer, startToken) { - if (!lexer.options.noLocation) { - return new Loc(startToken, lexer.lastToken, lexer.source); - } - } - - function Loc(startToken, endToken, source) { - this.start = startToken.start; - this.end = endToken.end; - this.startToken = startToken; - this.endToken = endToken; - this.source = source; - } // Print a simplified form when appearing in JSON/util.inspect. - - - defineToJSON(Loc, function () { - return { - start: this.start, - end: this.end - }; - }); - /** - * Determines if the next token is of a given kind - */ - - function peek(lexer, kind) { - return lexer.token.kind === kind; - } - /** - * If the next token is of the given kind, return that token after advancing - * the lexer. Otherwise, do not change the parser state and throw an error. - */ - - - function expectToken(lexer, kind) { - var token = lexer.token; - - if (token.kind === kind) { - lexer.advance(); - return token; - } - - throw syntaxError(lexer.source, token.start, "Expected ".concat(kind, ", found ").concat(getTokenDesc(token))); - } - /** - * If the next token is of the given kind, return that token after advancing - * the lexer. Otherwise, do not change the parser state and return undefined. - */ - - - function expectOptionalToken(lexer, kind) { - var token = lexer.token; - - if (token.kind === kind) { - lexer.advance(); - return token; - } - - return undefined; - } - /** - * If the next token is a given keyword, return that token after advancing - * the lexer. Otherwise, do not change the parser state and throw an error. - */ - - - function expectKeyword(lexer, value) { - var token = lexer.token; - - if (token.kind === TokenKind.NAME && token.value === value) { - lexer.advance(); - return token; - } - - throw syntaxError(lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(token))); - } - /** - * If the next token is a given keyword, return that token after advancing - * the lexer. Otherwise, do not change the parser state and return undefined. - */ - - - function expectOptionalKeyword(lexer, value) { - var token = lexer.token; - - if (token.kind === TokenKind.NAME && token.value === value) { - lexer.advance(); - return token; - } - - return undefined; - } - /** - * Helper function for creating an error when an unexpected lexed token - * is encountered. - */ - - - function unexpected(lexer, atToken) { - var token = atToken || lexer.token; - return syntaxError(lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token))); - } - /** - * Returns a possibly empty list of parse nodes, determined by - * the parseFn. This list begins with a lex token of openKind - * and ends with a lex token of closeKind. Advances the parser - * to the next lex token after the closing token. - */ - - - function any(lexer, openKind, parseFn, closeKind) { - expectToken(lexer, openKind); - var nodes = []; - - while (!expectOptionalToken(lexer, closeKind)) { - nodes.push(parseFn(lexer)); - } - - return nodes; - } - /** - * Returns a non-empty list of parse nodes, determined by - * the parseFn. This list begins with a lex token of openKind - * and ends with a lex token of closeKind. Advances the parser - * to the next lex token after the closing token. - */ - - - function many(lexer, openKind, parseFn, closeKind) { - expectToken(lexer, openKind); - var nodes = [parseFn(lexer)]; - - while (!expectOptionalToken(lexer, closeKind)) { - nodes.push(parseFn(lexer)); - } - - return nodes; - } - - var parser = /*#__PURE__*/Object.freeze({ - parse: parse, - parseValue: parseValue, - parseType: parseType, - parseConstValue: parseConstValue, - parseTypeReference: parseTypeReference, - parseNamedType: parseNamedType - }); - - var parser$1 = getCjsExportFromNamespace(parser); - - var parse$1 = parser$1.parse; - - // Strip insignificant whitespace - // Note that this could do a lot more, such as reorder fields etc. - function normalize(string) { - return string.replace(/[\s,]+/g, ' ').trim(); - } - - // A map docString -> graphql document - var docCache = {}; - - // A map fragmentName -> [normalized source] - var fragmentSourceMap = {}; - - function cacheKeyFromLoc(loc) { - return normalize(loc.source.body.substring(loc.start, loc.end)); - } - - // For testing. - function resetCaches() { - docCache = {}; - fragmentSourceMap = {}; - } - - // Take a unstripped parsed document (query/mutation or even fragment), and - // check all fragment definitions, checking for name->source uniqueness. - // We also want to make sure only unique fragments exist in the document. - var printFragmentWarnings = true; - function processFragments(ast) { - var astFragmentMap = {}; - var definitions = []; - - for (var i = 0; i < ast.definitions.length; i++) { - var fragmentDefinition = ast.definitions[i]; - - if (fragmentDefinition.kind === 'FragmentDefinition') { - var fragmentName = fragmentDefinition.name.value; - var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc); - - // We know something about this fragment - if (fragmentSourceMap.hasOwnProperty(fragmentName) && !fragmentSourceMap[fragmentName][sourceKey]) { - - // this is a problem because the app developer is trying to register another fragment with - // the same name as one previously registered. So, we tell them about it. - if (printFragmentWarnings) { - console.warn("Warning: fragment with name " + fragmentName + " already exists.\n" - + "graphql-tag enforces all fragment names across your application to be unique; read more about\n" - + "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names"); - } - - fragmentSourceMap[fragmentName][sourceKey] = true; - - } else if (!fragmentSourceMap.hasOwnProperty(fragmentName)) { - fragmentSourceMap[fragmentName] = {}; - fragmentSourceMap[fragmentName][sourceKey] = true; - } - - if (!astFragmentMap[sourceKey]) { - astFragmentMap[sourceKey] = true; - definitions.push(fragmentDefinition); - } - } else { - definitions.push(fragmentDefinition); - } - } - - ast.definitions = definitions; - return ast; - } - - function disableFragmentWarnings() { - printFragmentWarnings = false; - } - - function stripLoc(doc, removeLocAtThisLevel) { - var docType = Object.prototype.toString.call(doc); - - if (docType === '[object Array]') { - return doc.map(function (d) { - return stripLoc(d, removeLocAtThisLevel); - }); - } - - if (docType !== '[object Object]') { - throw new Error('Unexpected input.'); - } - - // We don't want to remove the root loc field so we can use it - // for fragment substitution (see below) - if (removeLocAtThisLevel && doc.loc) { - delete doc.loc; - } - - // https://github.com/apollographql/graphql-tag/issues/40 - if (doc.loc) { - delete doc.loc.startToken; - delete doc.loc.endToken; - } - - var keys = Object.keys(doc); - var key; - var value; - var valueType; - - for (key in keys) { - if (keys.hasOwnProperty(key)) { - value = doc[keys[key]]; - valueType = Object.prototype.toString.call(value); - - if (valueType === '[object Object]' || valueType === '[object Array]') { - doc[keys[key]] = stripLoc(value, true); - } - } - } - - return doc; - } - - var experimentalFragmentVariables = false; - function parseDocument$1(doc) { - var cacheKey = normalize(doc); - - if (docCache[cacheKey]) { - return docCache[cacheKey]; - } - - var parsed = parse$1(doc, { experimentalFragmentVariables: experimentalFragmentVariables }); - if (!parsed || parsed.kind !== 'Document') { - throw new Error('Not a valid GraphQL document.'); - } - - // check that all "new" fragments inside the documents are consistent with - // existing fragments of the same name - parsed = processFragments(parsed); - parsed = stripLoc(parsed, false); - docCache[cacheKey] = parsed; - - return parsed; - } - - function enableExperimentalFragmentVariables() { - experimentalFragmentVariables = true; - } - - function disableExperimentalFragmentVariables() { - experimentalFragmentVariables = false; - } - - // XXX This should eventually disallow arbitrary string interpolation, like Relay does - function gql(/* arguments */) { - var args = Array.prototype.slice.call(arguments); - - var literals = args[0]; - - // We always get literals[0] and then matching post literals for each arg given - var result = (typeof(literals) === "string") ? literals : literals[0]; - - for (var i = 1; i < args.length; i++) { - if (args[i] && args[i].kind && args[i].kind === 'Document') { - result += args[i].loc.source.body; - } else { - result += args[i]; - } - - result += literals[i]; - } - - return parseDocument$1(result); - } - - // Support typescript, which isn't as nice as Babel about default exports - gql.default = gql; - gql.resetCaches = resetCaches; - gql.disableFragmentWarnings = disableFragmentWarnings; - gql.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables; - gql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables; - - var src = gql; - function isDataFilled(data) { return Object.keys(data).length > 0; } @@ -4684,10 +1615,10 @@ return this.clientId; }, query: function query() { - return _objectSpread({ + return _objectSpread2({ query: function query() { if (typeof this.query === 'function') { - return this.query(src); + return this.query(gql); } return this.query; @@ -4826,7 +1757,7 @@ var document = this.document; if (typeof document === 'function') { - document = document(src); + document = document(gql); } this.$_sub = this.getDollarApollo().addSmartSubscription(this.$_key, { @@ -4893,10 +1824,10 @@ var mutation = this.mutation; if (typeof mutation === 'function') { - mutation = mutation(src); + mutation = mutation(gql); } - this.$apollo.mutate(_objectSpread({ + this.$apollo.mutate(_objectSpread2({ mutation: mutation, client: this.clientId, variables: this.variables, @@ -5037,7 +1968,7 @@ if (this.$isServer) { options = utils_5(options, this); - if (options.prefetch !== false && apollo.$prefetch !== false && !smart.skip) { + if (apolloProvider.prefetch !== false && options.prefetch !== false && apollo.$prefetch !== false && !smart.skip) { this.$_apolloPromises.push(smart.firstRun); } } @@ -5074,9 +2005,9 @@ } function installMixin(Vue, vueVersion) { - Vue.mixin(_objectSpread({}, vueVersion === '1' ? { + Vue.mixin(_objectSpread2({}, vueVersion === '1' ? { init: initProvider - } : {}, vueVersion === '2' ? { + } : {}, {}, vueVersion === '2' ? { data: function data() { return { '$apolloData': { @@ -5148,7 +2079,7 @@ } ApolloProvider.install = install; // eslint-disable-next-line no-undef - ApolloProvider.version = "3.0.0-rc.2"; // Apollo provider + ApolloProvider.version = "3.0.0-rc.3"; // Apollo provider var ApolloProvider$1 = ApolloProvider; // Components diff --git a/package.json b/package.json index 59a547b7..f7b9cd27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-apollo", - "version": "3.0.0-rc.2", + "version": "3.0.0-rc.3", "description": "Use Apollo and GraphQL with Vue.js", "main": "dist/vue-apollo.umd.js", "module": "dist/vue-apollo.esm.js",