\n*/\nexport class RestClient {\n\tprivate _options;\n\tprivate _region: string = 'us-east-1'; // this will be updated by endpoint function\n\tprivate _service: string = 'execute-api'; // this can be updated by endpoint function\n\tprivate _custom_header = undefined; // this can be updated by endpoint function\n\n\t/**\n\t * This weak map provides functionality to let clients cancel\n\t * in-flight axios requests. https://github.com/axios/axios#cancellation\n\t *\n\t * 1. For every axios request, a unique cancel token is generated and added in the request.\n\t * 2. Promise for fulfilling the request is then mapped to that unique cancel token.\n\t * 3. The promise is returned to the client.\n\t * 4. Clients can either wait for the promise to fulfill or call `API.cancel(promise)` to cancel the request.\n\t * 5. If `API.cancel(promise)` is called, then the corresponding cancel token is retrieved from the map below.\n\t * 6. Promise returned to the client will be in rejected state with the error provided during cancel.\n\t * 7. Clients can check if the error is because of cancelling by calling `API.isCancel(error)`.\n\t *\n\t * For more details, see https://github.com/aws-amplify/amplify-js/pull/3769#issuecomment-552660025\n\t */\n\tprivate _cancelTokenMap: WeakMap = null;\n\n\tCredentials = Credentials;\n\n\t/**\n\t * @param {RestClientOptions} [options] - Instance options\n\t */\n\tconstructor(options: apiOptions) {\n\t\tthis._options = options;\n\t\tlogger.debug('API Options', this._options);\n\t\tif (this._cancelTokenMap == null) {\n\t\t\tthis._cancelTokenMap = new WeakMap();\n\t\t}\n\t}\n\n\t/**\n * Update AWS credentials\n * @param {AWSCredentials} credentials - AWS credentials\n *\n updateCredentials(credentials: AWSCredentials) {\n this.options.credentials = credentials;\n }\n*/\n\t/**\n\t * Basic HTTP request. Customizable\n\t * @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information\n\t * @param {string} method - Request HTTP method\n\t * @param {json} [init] - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tasync ajax(urlOrApiInfo: string | ApiInfo, method: string, init) {\n\t\tlogger.debug(method, urlOrApiInfo);\n\n\t\tlet parsed_url;\n\t\tlet url: string;\n\t\tlet region: string = 'us-east-1';\n\t\tlet service: string = 'execute-api';\n\t\tlet custom_header: () => {\n\t\t\t[key: string]: string;\n\t\t} = undefined;\n\n\t\tif (typeof urlOrApiInfo === 'string') {\n\t\t\tparsed_url = this._parseUrl(urlOrApiInfo);\n\t\t\turl = urlOrApiInfo;\n\t\t} else {\n\t\t\t({ endpoint: url, custom_header, region, service } = urlOrApiInfo);\n\t\t\tparsed_url = this._parseUrl(urlOrApiInfo.endpoint);\n\t\t}\n\n\t\tconst params = {\n\t\t\tmethod,\n\t\t\turl,\n\t\t\thost: parsed_url.host,\n\t\t\tpath: parsed_url.path,\n\t\t\theaders: {},\n\t\t\tdata: null,\n\t\t\tresponseType: 'json',\n\t\t\ttimeout: 0,\n\t\t\tcancelToken: null,\n\t\t};\n\n\t\tlet libraryHeaders = {};\n\n\t\tif (Platform.isReactNative) {\n\t\t\tconst userAgent = Platform.userAgent || 'aws-amplify/0.1.x';\n\t\t\tlibraryHeaders = {\n\t\t\t\t'User-Agent': userAgent,\n\t\t\t};\n\t\t}\n\n\t\tconst initParams = Object.assign({}, init);\n\t\tconst isAllResponse = initParams.response;\n\t\tif (initParams.body) {\n\t\t\tif (\n\t\t\t\ttypeof FormData === 'function' &&\n\t\t\t\tinitParams.body instanceof FormData\n\t\t\t) {\n\t\t\t\tlibraryHeaders['Content-Type'] = 'multipart/form-data';\n\t\t\t\tparams.data = initParams.body;\n\t\t\t} else {\n\t\t\t\tlibraryHeaders['Content-Type'] = 'application/json; charset=UTF-8';\n\t\t\t\tparams.data = JSON.stringify(initParams.body);\n\t\t\t}\n\t\t}\n\t\tif (initParams.responseType) {\n\t\t\tparams.responseType = initParams.responseType;\n\t\t}\n\t\tif (initParams.withCredentials) {\n\t\t\tparams['withCredentials'] = initParams.withCredentials;\n\t\t}\n\t\tif (initParams.timeout) {\n\t\t\tparams.timeout = initParams.timeout;\n\t\t}\n\t\tif (initParams.cancellableToken) {\n\t\t\tparams.cancelToken = initParams.cancellableToken.token;\n\t\t}\n\n\t\tparams['signerServiceInfo'] = initParams.signerServiceInfo;\n\n\t\t// custom_header callback\n\t\tconst custom_header_obj =\n\t\t\ttypeof custom_header === 'function' ? await custom_header() : undefined;\n\n\t\tparams.headers = {\n\t\t\t...libraryHeaders,\n\t\t\t...custom_header_obj,\n\t\t\t...initParams.headers,\n\t\t};\n\n\t\t// Intentionally discarding search\n\t\tconst { search, ...parsedUrl } = parse(url, true, true);\n\t\tparams.url = format({\n\t\t\t...parsedUrl,\n\t\t\tquery: {\n\t\t\t\t...parsedUrl.query,\n\t\t\t\t...(initParams.queryStringParameters || {}),\n\t\t\t},\n\t\t});\n\n\t\t// Do not sign the request if client has added 'Authorization' header,\n\t\t// which means custom authorizer.\n\t\tif (typeof params.headers['Authorization'] !== 'undefined') {\n\t\t\tparams.headers = Object.keys(params.headers).reduce((acc, k) => {\n\t\t\t\tif (params.headers[k]) {\n\t\t\t\t\tacc[k] = params.headers[k];\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t\t// tslint:disable-next-line:align\n\t\t\t}, {});\n\t\t\treturn this._request(params, isAllResponse);\n\t\t}\n\n\t\t// Signing the request in case there credentials are available\n\t\treturn this.Credentials.get().then(\n\t\t\tcredentials => {\n\t\t\t\treturn this._signed({ ...params }, credentials, isAllResponse, {\n\t\t\t\t\tregion,\n\t\t\t\t\tservice,\n\t\t\t\t}).catch(error => {\n\t\t\t\t\tif (DateUtils.isClockSkewError(error)) {\n\t\t\t\t\t\tconst { headers } = error.response;\n\t\t\t\t\t\tconst dateHeader = headers && (headers.date || headers.Date);\n\t\t\t\t\t\tconst responseDate = new Date(dateHeader);\n\t\t\t\t\t\tconst requestDate = DateUtils.getDateFromHeaderString(\n\t\t\t\t\t\t\tparams.headers['x-amz-date']\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Compare local clock to the server clock\n\t\t\t\t\t\tif (DateUtils.isClockSkewed(responseDate)) {\n\t\t\t\t\t\t\tDateUtils.setClockOffset(\n\t\t\t\t\t\t\t\tresponseDate.getTime() - requestDate.getTime()\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\treturn this.ajax(urlOrApiInfo, method, init);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\t},\n\t\t\terr => {\n\t\t\t\tlogger.debug('No credentials available, the request will be unsigned');\n\t\t\t\treturn this._request(params, isAllResponse);\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * GET HTTP request\n\t * @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information\n\t * @param {JSON} init - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tget(urlOrApiInfo: string | ApiInfo, init) {\n\t\treturn this.ajax(urlOrApiInfo, 'GET', init);\n\t}\n\n\t/**\n\t * PUT HTTP request\n\t * @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information\n\t * @param {json} init - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tput(urlOrApiInfo: string | ApiInfo, init) {\n\t\treturn this.ajax(urlOrApiInfo, 'PUT', init);\n\t}\n\n\t/**\n\t * PATCH HTTP request\n\t * @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information\n\t * @param {json} init - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tpatch(urlOrApiInfo: string | ApiInfo, init) {\n\t\treturn this.ajax(urlOrApiInfo, 'PATCH', init);\n\t}\n\n\t/**\n\t * POST HTTP request\n\t * @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information\n\t * @param {json} init - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tpost(urlOrApiInfo: string | ApiInfo, init) {\n\t\treturn this.ajax(urlOrApiInfo, 'POST', init);\n\t}\n\n\t/**\n\t * DELETE HTTP request\n\t * @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information\n\t * @param {json} init - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tdel(urlOrApiInfo: string | ApiInfo, init) {\n\t\treturn this.ajax(urlOrApiInfo, 'DELETE', init);\n\t}\n\n\t/**\n\t * HEAD HTTP request\n\t * @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information\n\t * @param {json} init - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\thead(urlOrApiInfo: string | ApiInfo, init) {\n\t\treturn this.ajax(urlOrApiInfo, 'HEAD', init);\n\t}\n\n\t/**\n\t * Cancel an inflight API request\n\t * @param {Promise} request - The request promise to cancel\n\t * @param {string} [message] - A message to include in the cancelation exception\n\t */\n\tcancel(request: Promise, message?: string) {\n\t\tconst source = this._cancelTokenMap.get(request);\n\t\tif (source) {\n\t\t\tsource.cancel(message);\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Check if the request has a corresponding cancel token in the WeakMap.\n\t * @params request - The request promise\n\t * @return if the request has a corresponding cancel token.\n\t */\n\thasCancelToken(request: Promise) {\n\t\treturn this._cancelTokenMap.has(request);\n\t}\n\n\t/**\n\t * Checks to see if an error thrown is from an api request cancellation\n\t * @param {any} error - Any error\n\t * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n\t */\n\tisCancel(error): boolean {\n\t\treturn axios.isCancel(error);\n\t}\n\n\t/**\n\t * Retrieves a new and unique cancel token which can be\n\t * provided in an axios request to be cancelled later.\n\t */\n\tgetCancellableToken(): CancelTokenSource {\n\t\treturn axios.CancelToken.source();\n\t}\n\n\t/**\n\t * Updates the weakmap with a response promise and its\n\t * cancel token such that the cancel token can be easily\n\t * retrieved (and used for cancelling the request)\n\t */\n\tupdateRequestToBeCancellable(\n\t\tpromise: Promise,\n\t\tcancelTokenSource: CancelTokenSource\n\t) {\n\t\tthis._cancelTokenMap.set(promise, cancelTokenSource);\n\t}\n\n\t/**\n\t * Getting endpoint for API\n\t * @param {string} apiName - The name of the api\n\t * @return {string} - The endpoint of the api\n\t */\n\tendpoint(apiName: string) {\n\t\tconst cloud_logic_array = this._options.endpoints;\n\t\tlet response = '';\n\n\t\tif (!Array.isArray(cloud_logic_array)) {\n\t\t\treturn response;\n\t\t}\n\n\t\tcloud_logic_array.forEach(v => {\n\t\t\tif (v.name === apiName) {\n\t\t\t\tresponse = v.endpoint;\n\t\t\t\tif (typeof v.region === 'string') {\n\t\t\t\t\tthis._region = v.region;\n\t\t\t\t} else if (typeof this._options.region === 'string') {\n\t\t\t\t\tthis._region = this._options.region;\n\t\t\t\t}\n\t\t\t\tif (typeof v.service === 'string') {\n\t\t\t\t\tthis._service = v.service || 'execute-api';\n\t\t\t\t} else {\n\t\t\t\t\tthis._service = 'execute-api';\n\t\t\t\t}\n\t\t\t\tif (typeof v.custom_header === 'function') {\n\t\t\t\t\tthis._custom_header = v.custom_header;\n\t\t\t\t} else {\n\t\t\t\t\tthis._custom_header = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn response;\n\t}\n\n\t/** private methods **/\n\n\tprivate _signed(params, credentials, isAllResponse, { service, region }) {\n\t\tconst { signerServiceInfo: signerServiceInfoParams, ...otherParams } =\n\t\t\tparams;\n\n\t\tconst endpoint_region: string =\n\t\t\tregion || this._region || this._options.region;\n\t\tconst endpoint_service: string =\n\t\t\tservice || this._service || this._options.service;\n\n\t\tconst creds = {\n\t\t\tsecret_key: credentials.secretAccessKey,\n\t\t\taccess_key: credentials.accessKeyId,\n\t\t\tsession_token: credentials.sessionToken,\n\t\t};\n\n\t\tconst endpointInfo = {\n\t\t\tregion: endpoint_region,\n\t\t\tservice: endpoint_service,\n\t\t};\n\n\t\tconst signerServiceInfo = Object.assign(\n\t\t\tendpointInfo,\n\t\t\tsignerServiceInfoParams\n\t\t);\n\n\t\tconst signed_params = Signer.sign(otherParams, creds, signerServiceInfo);\n\n\t\tif (signed_params.data) {\n\t\t\tsigned_params.body = signed_params.data;\n\t\t}\n\n\t\tlogger.debug('Signed Request: ', signed_params);\n\n\t\tdelete signed_params.headers['host'];\n\n\t\treturn axios(signed_params)\n\t\t\t.then(response => (isAllResponse ? response : response.data))\n\t\t\t.catch(error => {\n\t\t\t\tlogger.debug(error);\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\tprivate _request(params, isAllResponse = false) {\n\t\treturn axios(params)\n\t\t\t.then(response => (isAllResponse ? response : response.data))\n\t\t\t.catch(error => {\n\t\t\t\tlogger.debug(error);\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\tprivate _parseUrl(url) {\n\t\tconst parts = url.split('/');\n\n\t\treturn {\n\t\t\thost: parts[2],\n\t\t\tpath: '/' + parts.slice(3).join('/'),\n\t\t};\n\t}\n}\n","/*\n * Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with\n * the License. A copy of the License is located at\n *\n * http://aws.amazon.com/apache2.0/\n *\n * or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\n * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions\n * and limitations under the License.\n */\nimport { RestClient } from './RestClient';\nimport {\n\tAmplify,\n\tConsoleLogger as Logger,\n\tCredentials,\n} from '@aws-amplify/core';\nimport { ApiInfo } from './types';\n\nconst logger = new Logger('RestAPI');\n\n/**\n * Export Cloud Logic APIs\n */\nexport class RestAPIClass {\n\t/**\n\t * @private\n\t */\n\tprivate _options;\n\tprivate _api: RestClient = null;\n\n\tCredentials = Credentials;\n\n\t/**\n\t * Initialize Rest API with AWS configuration\n\t * @param {Object} options - Configuration object for API\n\t */\n\tconstructor(options) {\n\t\tthis._options = options;\n\t\tlogger.debug('API Options', this._options);\n\t}\n\n\tpublic getModuleName() {\n\t\treturn 'RestAPI';\n\t}\n\n\t/**\n\t * Configure API part with aws configurations\n\t * @param {Object} config - Configuration of the API\n\t * @return {Object} - The current configuration\n\t */\n\tconfigure(options) {\n\t\tconst { API = {}, ...otherOptions } = options || {};\n\t\tlet opt = { ...otherOptions, ...API };\n\t\tlogger.debug('configure Rest API', { opt });\n\n\t\tif (opt['aws_project_region']) {\n\t\t\tif (opt['aws_cloud_logic_custom']) {\n\t\t\t\tconst custom = opt['aws_cloud_logic_custom'];\n\t\t\t\topt.endpoints =\n\t\t\t\t\ttypeof custom === 'string' ? JSON.parse(custom) : custom;\n\t\t\t}\n\n\t\t\topt = Object.assign({}, opt, {\n\t\t\t\tregion: opt['aws_project_region'],\n\t\t\t\theader: {},\n\t\t\t});\n\t\t}\n\n\t\tif (Array.isArray(opt.endpoints)) {\n\t\t\t// Check if endpoints has custom_headers and validate if is a function\n\t\t\topt.endpoints.forEach(endpoint => {\n\t\t\t\tif (\n\t\t\t\t\ttypeof endpoint.custom_header !== 'undefined' &&\n\t\t\t\t\ttypeof endpoint.custom_header !== 'function'\n\t\t\t\t) {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t'Rest API ' + endpoint.name + ', custom_header should be a function'\n\t\t\t\t\t);\n\t\t\t\t\tendpoint.custom_header = undefined;\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (this._options && Array.isArray(this._options.endpoints)) {\n\t\t\topt.endpoints = this._options.endpoints;\n\t\t} else {\n\t\t\topt.endpoints = [];\n\t\t}\n\n\t\tthis._options = Object.assign({}, this._options, opt);\n\n\t\tthis.createInstance();\n\n\t\treturn this._options;\n\t}\n\n\t/**\n\t * Create an instance of API for the library\n\t * @return - A promise of true if Success\n\t */\n\tcreateInstance() {\n\t\tlogger.debug('create Rest API instance');\n\t\tthis._api = new RestClient(this._options);\n\n\t\t// Share Amplify instance with client for SSR\n\t\tthis._api.Credentials = this.Credentials;\n\t\treturn true;\n\t}\n\n\t/**\n\t * Make a GET request\n\t * @param {string} apiName - The api name of the request\n\t * @param {string} path - The path of the request\n\t * @param {json} [init] - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tget(apiName, path, init): Promise {\n\t\ttry {\n\t\t\tconst apiInfo = this.getEndpointInfo(apiName, path);\n\n\t\t\tconst cancellableToken = this._api.getCancellableToken();\n\n\t\t\tconst initParams = Object.assign({}, init);\n\t\t\tinitParams.cancellableToken = cancellableToken;\n\n\t\t\tconst responsePromise = this._api.get(apiInfo, initParams);\n\n\t\t\tthis._api.updateRequestToBeCancellable(responsePromise, cancellableToken);\n\n\t\t\treturn responsePromise;\n\t\t} catch (err) {\n\t\t\treturn Promise.reject(err.message);\n\t\t}\n\t}\n\n\t/**\n\t * Make a POST request\n\t * @param {string} apiName - The api name of the request\n\t * @param {string} path - The path of the request\n\t * @param {json} [init] - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tpost(apiName, path, init): Promise {\n\t\ttry {\n\t\t\tconst apiInfo = this.getEndpointInfo(apiName, path);\n\n\t\t\tconst cancellableToken = this._api.getCancellableToken();\n\n\t\t\tconst initParams = Object.assign({}, init);\n\t\t\tinitParams.cancellableToken = cancellableToken;\n\n\t\t\tconst responsePromise = this._api.post(apiInfo, initParams);\n\n\t\t\tthis._api.updateRequestToBeCancellable(responsePromise, cancellableToken);\n\n\t\t\treturn responsePromise;\n\t\t} catch (err) {\n\t\t\treturn Promise.reject(err.message);\n\t\t}\n\t}\n\n\t/**\n\t * Make a PUT request\n\t * @param {string} apiName - The api name of the request\n\t * @param {string} path - The path of the request\n\t * @param {json} [init] - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tput(apiName, path, init): Promise {\n\t\ttry {\n\t\t\tconst apiInfo = this.getEndpointInfo(apiName, path);\n\n\t\t\tconst cancellableToken = this._api.getCancellableToken();\n\n\t\t\tconst initParams = Object.assign({}, init);\n\t\t\tinitParams.cancellableToken = cancellableToken;\n\n\t\t\tconst responsePromise = this._api.put(apiInfo, initParams);\n\n\t\t\tthis._api.updateRequestToBeCancellable(responsePromise, cancellableToken);\n\n\t\t\treturn responsePromise;\n\t\t} catch (err) {\n\t\t\treturn Promise.reject(err.message);\n\t\t}\n\t}\n\n\t/**\n\t * Make a PATCH request\n\t * @param {string} apiName - The api name of the request\n\t * @param {string} path - The path of the request\n\t * @param {json} [init] - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tpatch(apiName, path, init): Promise {\n\t\ttry {\n\t\t\tconst apiInfo = this.getEndpointInfo(apiName, path);\n\n\t\t\tconst cancellableToken = this._api.getCancellableToken();\n\n\t\t\tconst initParams = Object.assign({}, init);\n\t\t\tinitParams.cancellableToken = cancellableToken;\n\n\t\t\tconst responsePromise = this._api.patch(apiInfo, initParams);\n\n\t\t\tthis._api.updateRequestToBeCancellable(responsePromise, cancellableToken);\n\n\t\t\treturn responsePromise;\n\t\t} catch (err) {\n\t\t\treturn Promise.reject(err.message);\n\t\t}\n\t}\n\n\t/**\n\t * Make a DEL request\n\t * @param {string} apiName - The api name of the request\n\t * @param {string} path - The path of the request\n\t * @param {json} [init] - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tdel(apiName, path, init): Promise {\n\t\ttry {\n\t\t\tconst apiInfo = this.getEndpointInfo(apiName, path);\n\n\t\t\tconst cancellableToken = this._api.getCancellableToken();\n\n\t\t\tconst initParams = Object.assign({}, init);\n\t\t\tinitParams.cancellableToken = cancellableToken;\n\n\t\t\tconst responsePromise = this._api.del(apiInfo, initParams);\n\n\t\t\tthis._api.updateRequestToBeCancellable(responsePromise, cancellableToken);\n\n\t\t\treturn responsePromise;\n\t\t} catch (err) {\n\t\t\treturn Promise.reject(err.message);\n\t\t}\n\t}\n\n\t/**\n\t * Make a HEAD request\n\t * @param {string} apiName - The api name of the request\n\t * @param {string} path - The path of the request\n\t * @param {json} [init] - Request extra params\n\t * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\thead(apiName, path, init): Promise {\n\t\ttry {\n\t\t\tconst apiInfo = this.getEndpointInfo(apiName, path);\n\n\t\t\tconst cancellableToken = this._api.getCancellableToken();\n\n\t\t\tconst initParams = Object.assign({}, init);\n\t\t\tinitParams.cancellableToken = cancellableToken;\n\n\t\t\tconst responsePromise = this._api.head(apiInfo, initParams);\n\n\t\t\tthis._api.updateRequestToBeCancellable(responsePromise, cancellableToken);\n\n\t\t\treturn responsePromise;\n\t\t} catch (err) {\n\t\t\treturn Promise.reject(err.message);\n\t\t}\n\t}\n\n\t/**\n\t * Checks to see if an error thrown is from an api request cancellation\n\t * @param {any} error - Any error\n\t * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n\t */\n\tisCancel(error) {\n\t\treturn this._api.isCancel(error);\n\t}\n\n\t/**\n\t * Cancels an inflight request\n\t * @param {any} request - request to cancel\n\t * @return {boolean} - A boolean indicating if the request was cancelled\n\t */\n\tcancel(request: Promise, message?: string) {\n\t\treturn this._api.cancel(request, message);\n\t}\n\n\t/**\n\t * Check if the request has a corresponding cancel token in the WeakMap.\n\t * @params request - The request promise\n\t * @return if the request has a corresponding cancel token.\n\t */\n\thasCancelToken(request: Promise) {\n\t\treturn this._api.hasCancelToken(request);\n\t}\n\n\t/**\n\t * Getting endpoint for API\n\t * @param {string} apiName - The name of the api\n\t * @return {string} - The endpoint of the api\n\t */\n\tasync endpoint(apiName) {\n\t\treturn this._api.endpoint(apiName);\n\t}\n\n\t/**\n\t * Getting endpoint info for API\n\t * @param {string} apiName - The name of the api\n\t * @param {string} path - The path of the api that is going to accessed\n\t * @return {ApiInfo} - The endpoint information for that api-name\n\t */\n\tprivate getEndpointInfo(apiName: string, path: string): ApiInfo {\n\t\tconst cloud_logic_array = this._options.endpoints;\n\n\t\tif (!Array.isArray(cloud_logic_array)) {\n\t\t\tthrow new Error(`API category not configured`);\n\t\t}\n\n\t\tconst apiConfig = cloud_logic_array.find(api => api.name === apiName);\n\n\t\tif (!apiConfig) {\n\t\t\tthrow new Error(`API ${apiName} does not exist`);\n\t\t}\n\n\t\tconst response: ApiInfo = {\n\t\t\tendpoint: apiConfig.endpoint + path,\n\t\t};\n\n\t\tif (typeof apiConfig.region === 'string') {\n\t\t\tresponse.region = apiConfig.region;\n\t\t} else if (typeof this._options.region === 'string') {\n\t\t\tresponse.region = this._options.region;\n\t\t}\n\n\t\tif (typeof apiConfig.service === 'string') {\n\t\t\tresponse.service = apiConfig.service || 'execute-api';\n\t\t} else {\n\t\t\tresponse.service = 'execute-api';\n\t\t}\n\n\t\tif (typeof apiConfig.custom_header === 'function') {\n\t\t\tresponse.custom_header = apiConfig.custom_header;\n\t\t} else {\n\t\t\tresponse.custom_header = undefined;\n\t\t}\n\n\t\treturn response;\n\t}\n}\n\nexport const RestAPI = new RestAPIClass(null);\nAmplify.register(RestAPI);\n","import { GraphQLError } from \"./GraphQLError.mjs\";\n/**\n * Produces a GraphQLError representing a syntax error, containing useful\n * descriptive information about the syntax error's position in the source.\n */\n\nexport function syntaxError(source, position, description) {\n return new GraphQLError(\"Syntax Error: \".concat(description), undefined, source, [position]);\n}\n","/**\n * The set of allowed kind values for AST nodes.\n */\nexport var Kind = Object.freeze({\n // Name\n NAME: 'Name',\n // Document\n DOCUMENT: 'Document',\n OPERATION_DEFINITION: 'OperationDefinition',\n VARIABLE_DEFINITION: 'VariableDefinition',\n SELECTION_SET: 'SelectionSet',\n FIELD: 'Field',\n ARGUMENT: 'Argument',\n // Fragments\n FRAGMENT_SPREAD: 'FragmentSpread',\n INLINE_FRAGMENT: 'InlineFragment',\n FRAGMENT_DEFINITION: 'FragmentDefinition',\n // Values\n VARIABLE: 'Variable',\n INT: 'IntValue',\n FLOAT: 'FloatValue',\n STRING: 'StringValue',\n BOOLEAN: 'BooleanValue',\n NULL: 'NullValue',\n ENUM: 'EnumValue',\n LIST: 'ListValue',\n OBJECT: 'ObjectValue',\n OBJECT_FIELD: 'ObjectField',\n // Directives\n DIRECTIVE: 'Directive',\n // Types\n NAMED_TYPE: 'NamedType',\n LIST_TYPE: 'ListType',\n NON_NULL_TYPE: 'NonNullType',\n // Type System Definitions\n SCHEMA_DEFINITION: 'SchemaDefinition',\n OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition',\n // Type Definitions\n SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition',\n OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition',\n FIELD_DEFINITION: 'FieldDefinition',\n INPUT_VALUE_DEFINITION: 'InputValueDefinition',\n INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition',\n UNION_TYPE_DEFINITION: 'UnionTypeDefinition',\n ENUM_TYPE_DEFINITION: 'EnumTypeDefinition',\n ENUM_VALUE_DEFINITION: 'EnumValueDefinition',\n INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition',\n // Directive Definitions\n DIRECTIVE_DEFINITION: 'DirectiveDefinition',\n // Type System Extensions\n SCHEMA_EXTENSION: 'SchemaExtension',\n // Type Extensions\n SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension',\n OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension',\n INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension',\n UNION_TYPE_EXTENSION: 'UnionTypeExtension',\n ENUM_TYPE_EXTENSION: 'EnumTypeExtension',\n INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension'\n});\n/**\n * The enum type representing the possible kind values of AST nodes.\n */\n","// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')\nvar nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;\nexport default nodejsCustomInspectSymbol;\n","import invariant from \"./invariant.mjs\";\nimport nodejsCustomInspectSymbol from \"./nodejsCustomInspectSymbol.mjs\";\n/**\n * The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`\n */\n\nexport default function defineInspect(classObject) {\n var fn = classObject.prototype.toJSON;\n typeof fn === 'function' || invariant(0);\n classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')\n\n if (nodejsCustomInspectSymbol) {\n classObject.prototype[nodejsCustomInspectSymbol] = fn;\n }\n}\n","export default function invariant(condition, message) {\n var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')\n\n if (!booleanCondition) {\n throw new Error(message != null ? message : 'Unexpected invariant triggered.');\n }\n}\n","import defineInspect from \"../jsutils/defineInspect.mjs\";\n\n/**\n * Contains a range of UTF-8 character offsets and token references that\n * identify the region of the source from which the AST derived.\n */\nexport var Location = /*#__PURE__*/function () {\n /**\n * The character offset at which this Node begins.\n */\n\n /**\n * The character offset at which this Node ends.\n */\n\n /**\n * The Token at which this Node begins.\n */\n\n /**\n * The Token at which this Node ends.\n */\n\n /**\n * The Source document the AST represents.\n */\n function Location(startToken, endToken, source) {\n this.start = startToken.start;\n this.end = endToken.end;\n this.startToken = startToken;\n this.endToken = endToken;\n this.source = source;\n }\n\n var _proto = Location.prototype;\n\n _proto.toJSON = function toJSON() {\n return {\n start: this.start,\n end: this.end\n };\n };\n\n return Location;\n}(); // Print a simplified form when appearing in `inspect` and `util.inspect`.\n\ndefineInspect(Location);\n/**\n * Represents a range of characters represented by a lexical token\n * within a Source.\n */\n\nexport var Token = /*#__PURE__*/function () {\n /**\n * The kind of Token.\n */\n\n /**\n * The character offset at which this Node begins.\n */\n\n /**\n * The character offset at which this Node ends.\n */\n\n /**\n * The 1-indexed line number on which this Token appears.\n */\n\n /**\n * The 1-indexed column number at which this Token begins.\n */\n\n /**\n * For non-punctuation tokens, represents the interpreted value of the token.\n */\n\n /**\n * Tokens exist as nodes in a double-linked-list amongst all tokens\n * including ignored tokens. is always the first node and \n * the last.\n */\n function Token(kind, start, end, line, column, prev, value) {\n this.kind = kind;\n this.start = start;\n this.end = end;\n this.line = line;\n this.column = column;\n this.value = value;\n this.prev = prev;\n this.next = null;\n }\n\n var _proto2 = Token.prototype;\n\n _proto2.toJSON = function toJSON() {\n return {\n kind: this.kind,\n value: this.value,\n line: this.line,\n column: this.column\n };\n };\n\n return Token;\n}(); // Print a simplified form when appearing in `inspect` and `util.inspect`.\n\ndefineInspect(Token);\n/**\n * @internal\n */\n\nexport function isNode(maybeNode) {\n return maybeNode != null && typeof maybeNode.kind === 'string';\n}\n/**\n * The list of all possible AST node types.\n */\n","/**\n * An exported enum describing the different kinds of tokens that the\n * lexer emits.\n */\nexport var TokenKind = Object.freeze({\n SOF: '',\n EOF: '',\n BANG: '!',\n DOLLAR: '$',\n AMP: '&',\n PAREN_L: '(',\n PAREN_R: ')',\n SPREAD: '...',\n COLON: ':',\n EQUALS: '=',\n AT: '@',\n BRACKET_L: '[',\n BRACKET_R: ']',\n BRACE_L: '{',\n PIPE: '|',\n BRACE_R: '}',\n NAME: 'Name',\n INT: 'Int',\n FLOAT: 'Float',\n STRING: 'String',\n BLOCK_STRING: 'BlockString',\n COMMENT: 'Comment'\n});\n/**\n * The enum type representing the token kinds values.\n */\n","function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n/* eslint-disable flowtype/no-weak-types */\nimport nodejsCustomInspectSymbol from \"./nodejsCustomInspectSymbol.mjs\";\nvar MAX_ARRAY_LENGTH = 10;\nvar MAX_RECURSIVE_DEPTH = 2;\n/**\n * Used to print values in error messages.\n */\n\nexport default function inspect(value) {\n return formatValue(value, []);\n}\n\nfunction formatValue(value, seenValues) {\n switch (_typeof(value)) {\n case 'string':\n return JSON.stringify(value);\n\n case 'function':\n return value.name ? \"[function \".concat(value.name, \"]\") : '[function]';\n\n case 'object':\n if (value === null) {\n return 'null';\n }\n\n return formatObjectValue(value, seenValues);\n\n default:\n return String(value);\n }\n}\n\nfunction formatObjectValue(value, previouslySeenValues) {\n if (previouslySeenValues.indexOf(value) !== -1) {\n return '[Circular]';\n }\n\n var seenValues = [].concat(previouslySeenValues, [value]);\n var customInspectFn = getCustomFn(value);\n\n if (customInspectFn !== undefined) {\n var customValue = customInspectFn.call(value); // check for infinite recursion\n\n if (customValue !== value) {\n return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues);\n }\n } else if (Array.isArray(value)) {\n return formatArray(value, seenValues);\n }\n\n return formatObject(value, seenValues);\n}\n\nfunction formatObject(object, seenValues) {\n var keys = Object.keys(object);\n\n if (keys.length === 0) {\n return '{}';\n }\n\n if (seenValues.length > MAX_RECURSIVE_DEPTH) {\n return '[' + getObjectTag(object) + ']';\n }\n\n var properties = keys.map(function (key) {\n var value = formatValue(object[key], seenValues);\n return key + ': ' + value;\n });\n return '{ ' + properties.join(', ') + ' }';\n}\n\nfunction formatArray(array, seenValues) {\n if (array.length === 0) {\n return '[]';\n }\n\n if (seenValues.length > MAX_RECURSIVE_DEPTH) {\n return '[Array]';\n }\n\n var len = Math.min(MAX_ARRAY_LENGTH, array.length);\n var remaining = array.length - len;\n var items = [];\n\n for (var i = 0; i < len; ++i) {\n items.push(formatValue(array[i], seenValues));\n }\n\n if (remaining === 1) {\n items.push('... 1 more item');\n } else if (remaining > 1) {\n items.push(\"... \".concat(remaining, \" more items\"));\n }\n\n return '[' + items.join(', ') + ']';\n}\n\nfunction getCustomFn(object) {\n var customInspectFn = object[String(nodejsCustomInspectSymbol)];\n\n if (typeof customInspectFn === 'function') {\n return customInspectFn;\n }\n\n if (typeof object.inspect === 'function') {\n return object.inspect;\n }\n}\n\nfunction getObjectTag(object) {\n var tag = Object.prototype.toString.call(object).replace(/^\\[object /, '').replace(/]$/, '');\n\n if (tag === 'Object' && typeof object.constructor === 'function') {\n var name = object.constructor.name;\n\n if (typeof name === 'string' && name !== '') {\n return name;\n }\n }\n\n return tag;\n}\n","export default function devAssert(condition, message) {\n var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')\n\n if (!booleanCondition) {\n throw new Error(message);\n }\n}\n","function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nimport inspect from \"./inspect.mjs\";\n/**\n * A replacement for instanceof which includes an error warning when multi-realm\n * constructors are detected.\n */\n\n// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production\n// See: https://webpack.js.org/guides/production/\nexport default process.env.NODE_ENV === 'production' ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')\n// eslint-disable-next-line no-shadow\nfunction instanceOf(value, constructor) {\n return value instanceof constructor;\n} : // eslint-disable-next-line no-shadow\nfunction instanceOf(value, constructor) {\n if (value instanceof constructor) {\n return true;\n }\n\n if (_typeof(value) === 'object' && value !== null) {\n var _value$constructor;\n\n var className = constructor.prototype[Symbol.toStringTag];\n var valueClassName = // We still need to support constructor's name to detect conflicts with older versions of this library.\n Symbol.toStringTag in value ? value[Symbol.toStringTag] : (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name;\n\n if (className === valueClassName) {\n var stringifiedValue = inspect(value);\n throw new Error(\"Cannot use \".concat(className, \" \\\"\").concat(stringifiedValue, \"\\\" from another module or realm.\\n\\nEnsure that there is only one instance of \\\"graphql\\\" in the node_modules\\ndirectory. If different versions of \\\"graphql\\\" are the dependencies of other\\nrelied on modules, use \\\"resolutions\\\" to ensure only one version is installed.\\n\\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\\n\\nDuplicate \\\"graphql\\\" modules cannot be used at the same time since different\\nversions may have different capabilities and behavior. The data from one\\nversion used in the function from another could produce confusing and\\nspurious results.\"));\n }\n }\n\n return false;\n};\n","function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nimport { SYMBOL_TO_STRING_TAG } from \"../polyfills/symbols.mjs\";\nimport inspect from \"../jsutils/inspect.mjs\";\nimport devAssert from \"../jsutils/devAssert.mjs\";\nimport instanceOf from \"../jsutils/instanceOf.mjs\";\n\n/**\n * A representation of source input to GraphQL. The `name` and `locationOffset` parameters are\n * optional, but they are useful for clients who store GraphQL documents in source files.\n * For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might\n * be useful for `name` to be `\"Foo.graphql\"` and location to be `{ line: 40, column: 1 }`.\n * The `line` and `column` properties in `locationOffset` are 1-indexed.\n */\nexport var Source = /*#__PURE__*/function () {\n function Source(body) {\n var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GraphQL request';\n var locationOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {\n line: 1,\n column: 1\n };\n typeof body === 'string' || devAssert(0, \"Body must be a string. Received: \".concat(inspect(body), \".\"));\n this.body = body;\n this.name = name;\n this.locationOffset = locationOffset;\n this.locationOffset.line > 0 || devAssert(0, 'line in locationOffset is 1-indexed and must be positive.');\n this.locationOffset.column > 0 || devAssert(0, 'column in locationOffset is 1-indexed and must be positive.');\n } // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet\n\n\n _createClass(Source, [{\n key: SYMBOL_TO_STRING_TAG,\n get: function get() {\n return 'Source';\n }\n }]);\n\n return Source;\n}();\n/**\n * Test if the given value is a Source object.\n *\n * @internal\n */\n\n// eslint-disable-next-line no-redeclare\nexport function isSource(source) {\n return instanceOf(source, Source);\n}\n","/**\n * The set of allowed directive location values.\n */\nexport var DirectiveLocation = Object.freeze({\n // Request Definitions\n QUERY: 'QUERY',\n MUTATION: 'MUTATION',\n SUBSCRIPTION: 'SUBSCRIPTION',\n FIELD: 'FIELD',\n FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION',\n FRAGMENT_SPREAD: 'FRAGMENT_SPREAD',\n INLINE_FRAGMENT: 'INLINE_FRAGMENT',\n VARIABLE_DEFINITION: 'VARIABLE_DEFINITION',\n // Type System Definitions\n SCHEMA: 'SCHEMA',\n SCALAR: 'SCALAR',\n OBJECT: 'OBJECT',\n FIELD_DEFINITION: 'FIELD_DEFINITION',\n ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION',\n INTERFACE: 'INTERFACE',\n UNION: 'UNION',\n ENUM: 'ENUM',\n ENUM_VALUE: 'ENUM_VALUE',\n INPUT_OBJECT: 'INPUT_OBJECT',\n INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION'\n});\n/**\n * The enum type representing the directive location values.\n */\n","/**\n * Produces the value of a block string from its parsed raw value, similar to\n * CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.\n *\n * This implements the GraphQL spec's BlockStringValue() static algorithm.\n *\n * @internal\n */\nexport function dedentBlockStringValue(rawString) {\n // Expand a block string's raw value into independent lines.\n var lines = rawString.split(/\\r\\n|[\\n\\r]/g); // Remove common indentation from all lines but first.\n\n var commonIndent = getBlockStringIndentation(rawString);\n\n if (commonIndent !== 0) {\n for (var i = 1; i < lines.length; i++) {\n lines[i] = lines[i].slice(commonIndent);\n }\n } // Remove leading and trailing blank lines.\n\n\n var startLine = 0;\n\n while (startLine < lines.length && isBlank(lines[startLine])) {\n ++startLine;\n }\n\n var endLine = lines.length;\n\n while (endLine > startLine && isBlank(lines[endLine - 1])) {\n --endLine;\n } // Return a string of the lines joined with U+000A.\n\n\n return lines.slice(startLine, endLine).join('\\n');\n}\n\nfunction isBlank(str) {\n for (var i = 0; i < str.length; ++i) {\n if (str[i] !== ' ' && str[i] !== '\\t') {\n return false;\n }\n }\n\n return true;\n}\n/**\n * @internal\n */\n\n\nexport function getBlockStringIndentation(value) {\n var _commonIndent;\n\n var isFirstLine = true;\n var isEmptyLine = true;\n var indent = 0;\n var commonIndent = null;\n\n for (var i = 0; i < value.length; ++i) {\n switch (value.charCodeAt(i)) {\n case 13:\n // \\r\n if (value.charCodeAt(i + 1) === 10) {\n ++i; // skip \\r\\n as one symbol\n }\n\n // falls through\n\n case 10:\n // \\n\n isFirstLine = false;\n isEmptyLine = true;\n indent = 0;\n break;\n\n case 9: // \\t\n\n case 32:\n // \n ++indent;\n break;\n\n default:\n if (isEmptyLine && !isFirstLine && (commonIndent === null || indent < commonIndent)) {\n commonIndent = indent;\n }\n\n isEmptyLine = false;\n }\n }\n\n return (_commonIndent = commonIndent) !== null && _commonIndent !== void 0 ? _commonIndent : 0;\n}\n/**\n * Print a block string in the indented block form by adding a leading and\n * trailing blank line. However, if a block string starts with whitespace and is\n * a single-line, adding a leading blank line would strip that whitespace.\n *\n * @internal\n */\n\nexport function printBlockString(value) {\n var indentation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';\n var preferMultipleLines = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n var isSingleLine = value.indexOf('\\n') === -1;\n var hasLeadingSpace = value[0] === ' ' || value[0] === '\\t';\n var hasTrailingQuote = value[value.length - 1] === '\"';\n var hasTrailingSlash = value[value.length - 1] === '\\\\';\n var printAsMultipleLines = !isSingleLine || hasTrailingQuote || hasTrailingSlash || preferMultipleLines;\n var result = ''; // Format a multi-line block quote to account for leading space.\n\n if (printAsMultipleLines && !(isSingleLine && hasLeadingSpace)) {\n result += '\\n' + indentation;\n }\n\n result += indentation ? value.replace(/\\n/g, '\\n' + indentation) : value;\n\n if (printAsMultipleLines) {\n result += '\\n';\n }\n\n return '\"\"\"' + result.replace(/\"\"\"/g, '\\\\\"\"\"') + '\"\"\"';\n}\n","import { syntaxError } from \"../error/syntaxError.mjs\";\nimport { Token } from \"./ast.mjs\";\nimport { TokenKind } from \"./tokenKind.mjs\";\nimport { dedentBlockStringValue } from \"./blockString.mjs\";\n/**\n * Given a Source object, creates a Lexer for that source.\n * A Lexer is a stateful stream generator in that every time\n * it is advanced, it returns the next token in the Source. Assuming the\n * source lexes, the final Token emitted by the lexer will be of kind\n * EOF, after which the lexer will repeatedly return the same EOF token\n * whenever called.\n */\n\nexport var Lexer = /*#__PURE__*/function () {\n /**\n * The previously focused non-ignored token.\n */\n\n /**\n * The currently focused non-ignored token.\n */\n\n /**\n * The (1-indexed) line containing the current token.\n */\n\n /**\n * The character offset at which the current line begins.\n */\n function Lexer(source) {\n var startOfFileToken = new Token(TokenKind.SOF, 0, 0, 0, 0, null);\n this.source = source;\n this.lastToken = startOfFileToken;\n this.token = startOfFileToken;\n this.line = 1;\n this.lineStart = 0;\n }\n /**\n * Advances the token stream to the next non-ignored token.\n */\n\n\n var _proto = Lexer.prototype;\n\n _proto.advance = function advance() {\n this.lastToken = this.token;\n var token = this.token = this.lookahead();\n return token;\n }\n /**\n * Looks ahead and returns the next non-ignored token, but does not change\n * the state of Lexer.\n */\n ;\n\n _proto.lookahead = function lookahead() {\n var token = this.token;\n\n if (token.kind !== TokenKind.EOF) {\n do {\n var _token$next;\n\n // Note: next is only mutable during parsing, so we cast to allow this.\n token = (_token$next = token.next) !== null && _token$next !== void 0 ? _token$next : token.next = readToken(this, token);\n } while (token.kind === TokenKind.COMMENT);\n }\n\n return token;\n };\n\n return Lexer;\n}();\n/**\n * @internal\n */\n\nexport function isPunctuatorTokenKind(kind) {\n return kind === TokenKind.BANG || kind === TokenKind.DOLLAR || kind === TokenKind.AMP || kind === TokenKind.PAREN_L || kind === TokenKind.PAREN_R || kind === TokenKind.SPREAD || kind === TokenKind.COLON || kind === TokenKind.EQUALS || kind === TokenKind.AT || kind === TokenKind.BRACKET_L || kind === TokenKind.BRACKET_R || kind === TokenKind.BRACE_L || kind === TokenKind.PIPE || kind === TokenKind.BRACE_R;\n}\n\nfunction printCharCode(code) {\n return (// NaN/undefined represents access beyond the end of the file.\n isNaN(code) ? TokenKind.EOF : // Trust JSON for ASCII.\n code < 0x007f ? JSON.stringify(String.fromCharCode(code)) : // Otherwise print the escaped form.\n \"\\\"\\\\u\".concat(('00' + code.toString(16).toUpperCase()).slice(-4), \"\\\"\")\n );\n}\n/**\n * Gets the next token from the source starting at the given position.\n *\n * This skips over whitespace until it finds the next lexable token, then lexes\n * punctuators immediately or calls the appropriate helper function for more\n * complicated tokens.\n */\n\n\nfunction readToken(lexer, prev) {\n var source = lexer.source;\n var body = source.body;\n var bodyLength = body.length;\n var pos = prev.end;\n\n while (pos < bodyLength) {\n var code = body.charCodeAt(pos);\n var _line = lexer.line;\n\n var _col = 1 + pos - lexer.lineStart; // SourceCharacter\n\n\n switch (code) {\n case 0xfeff: // \n\n case 9: // \\t\n\n case 32: // \n\n case 44:\n // ,\n ++pos;\n continue;\n\n case 10:\n // \\n\n ++pos;\n ++lexer.line;\n lexer.lineStart = pos;\n continue;\n\n case 13:\n // \\r\n if (body.charCodeAt(pos + 1) === 10) {\n pos += 2;\n } else {\n ++pos;\n }\n\n ++lexer.line;\n lexer.lineStart = pos;\n continue;\n\n case 33:\n // !\n return new Token(TokenKind.BANG, pos, pos + 1, _line, _col, prev);\n\n case 35:\n // #\n return readComment(source, pos, _line, _col, prev);\n\n case 36:\n // $\n return new Token(TokenKind.DOLLAR, pos, pos + 1, _line, _col, prev);\n\n case 38:\n // &\n return new Token(TokenKind.AMP, pos, pos + 1, _line, _col, prev);\n\n case 40:\n // (\n return new Token(TokenKind.PAREN_L, pos, pos + 1, _line, _col, prev);\n\n case 41:\n // )\n return new Token(TokenKind.PAREN_R, pos, pos + 1, _line, _col, prev);\n\n case 46:\n // .\n if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) {\n return new Token(TokenKind.SPREAD, pos, pos + 3, _line, _col, prev);\n }\n\n break;\n\n case 58:\n // :\n return new Token(TokenKind.COLON, pos, pos + 1, _line, _col, prev);\n\n case 61:\n // =\n return new Token(TokenKind.EQUALS, pos, pos + 1, _line, _col, prev);\n\n case 64:\n // @\n return new Token(TokenKind.AT, pos, pos + 1, _line, _col, prev);\n\n case 91:\n // [\n return new Token(TokenKind.BRACKET_L, pos, pos + 1, _line, _col, prev);\n\n case 93:\n // ]\n return new Token(TokenKind.BRACKET_R, pos, pos + 1, _line, _col, prev);\n\n case 123:\n // {\n return new Token(TokenKind.BRACE_L, pos, pos + 1, _line, _col, prev);\n\n case 124:\n // |\n return new Token(TokenKind.PIPE, pos, pos + 1, _line, _col, prev);\n\n case 125:\n // }\n return new Token(TokenKind.BRACE_R, pos, pos + 1, _line, _col, prev);\n\n case 34:\n // \"\n if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) {\n return readBlockString(source, pos, _line, _col, prev, lexer);\n }\n\n return readString(source, pos, _line, _col, prev);\n\n case 45: // -\n\n case 48: // 0\n\n case 49: // 1\n\n case 50: // 2\n\n case 51: // 3\n\n case 52: // 4\n\n case 53: // 5\n\n case 54: // 6\n\n case 55: // 7\n\n case 56: // 8\n\n case 57:\n // 9\n return readNumber(source, pos, code, _line, _col, prev);\n\n case 65: // A\n\n case 66: // B\n\n case 67: // C\n\n case 68: // D\n\n case 69: // E\n\n case 70: // F\n\n case 71: // G\n\n case 72: // H\n\n case 73: // I\n\n case 74: // J\n\n case 75: // K\n\n case 76: // L\n\n case 77: // M\n\n case 78: // N\n\n case 79: // O\n\n case 80: // P\n\n case 81: // Q\n\n case 82: // R\n\n case 83: // S\n\n case 84: // T\n\n case 85: // U\n\n case 86: // V\n\n case 87: // W\n\n case 88: // X\n\n case 89: // Y\n\n case 90: // Z\n\n case 95: // _\n\n case 97: // a\n\n case 98: // b\n\n case 99: // c\n\n case 100: // d\n\n case 101: // e\n\n case 102: // f\n\n case 103: // g\n\n case 104: // h\n\n case 105: // i\n\n case 106: // j\n\n case 107: // k\n\n case 108: // l\n\n case 109: // m\n\n case 110: // n\n\n case 111: // o\n\n case 112: // p\n\n case 113: // q\n\n case 114: // r\n\n case 115: // s\n\n case 116: // t\n\n case 117: // u\n\n case 118: // v\n\n case 119: // w\n\n case 120: // x\n\n case 121: // y\n\n case 122:\n // z\n return readName(source, pos, _line, _col, prev);\n }\n\n throw syntaxError(source, pos, unexpectedCharacterMessage(code));\n }\n\n var line = lexer.line;\n var col = 1 + pos - lexer.lineStart;\n return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);\n}\n/**\n * Report a message that an unexpected character was encountered.\n */\n\n\nfunction unexpectedCharacterMessage(code) {\n if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {\n return \"Cannot contain the invalid character \".concat(printCharCode(code), \".\");\n }\n\n if (code === 39) {\n // '\n return 'Unexpected single quote character (\\'), did you mean to use a double quote (\")?';\n }\n\n return \"Cannot parse the unexpected character \".concat(printCharCode(code), \".\");\n}\n/**\n * Reads a comment token from the source file.\n *\n * #[\\u0009\\u0020-\\uFFFF]*\n */\n\n\nfunction readComment(source, start, line, col, prev) {\n var body = source.body;\n var code;\n var position = start;\n\n do {\n code = body.charCodeAt(++position);\n } while (!isNaN(code) && ( // SourceCharacter but not LineTerminator\n code > 0x001f || code === 0x0009));\n\n return new Token(TokenKind.COMMENT, start, position, line, col, prev, body.slice(start + 1, position));\n}\n/**\n * Reads a number token from the source file, either a float\n * or an int depending on whether a decimal point appears.\n *\n * Int: -?(0|[1-9][0-9]*)\n * Float: -?(0|[1-9][0-9]*)(\\.[0-9]+)?((E|e)(+|-)?[0-9]+)?\n */\n\n\nfunction readNumber(source, start, firstCode, line, col, prev) {\n var body = source.body;\n var code = firstCode;\n var position = start;\n var isFloat = false;\n\n if (code === 45) {\n // -\n code = body.charCodeAt(++position);\n }\n\n if (code === 48) {\n // 0\n code = body.charCodeAt(++position);\n\n if (code >= 48 && code <= 57) {\n throw syntaxError(source, position, \"Invalid number, unexpected digit after 0: \".concat(printCharCode(code), \".\"));\n }\n } else {\n position = readDigits(source, position, code);\n code = body.charCodeAt(position);\n }\n\n if (code === 46) {\n // .\n isFloat = true;\n code = body.charCodeAt(++position);\n position = readDigits(source, position, code);\n code = body.charCodeAt(position);\n }\n\n if (code === 69 || code === 101) {\n // E e\n isFloat = true;\n code = body.charCodeAt(++position);\n\n if (code === 43 || code === 45) {\n // + -\n code = body.charCodeAt(++position);\n }\n\n position = readDigits(source, position, code);\n code = body.charCodeAt(position);\n } // Numbers cannot be followed by . or NameStart\n\n\n if (code === 46 || isNameStart(code)) {\n throw syntaxError(source, position, \"Invalid number, expected digit but got: \".concat(printCharCode(code), \".\"));\n }\n\n return new Token(isFloat ? TokenKind.FLOAT : TokenKind.INT, start, position, line, col, prev, body.slice(start, position));\n}\n/**\n * Returns the new position in the source after reading digits.\n */\n\n\nfunction readDigits(source, start, firstCode) {\n var body = source.body;\n var position = start;\n var code = firstCode;\n\n if (code >= 48 && code <= 57) {\n // 0 - 9\n do {\n code = body.charCodeAt(++position);\n } while (code >= 48 && code <= 57); // 0 - 9\n\n\n return position;\n }\n\n throw syntaxError(source, position, \"Invalid number, expected digit but got: \".concat(printCharCode(code), \".\"));\n}\n/**\n * Reads a string token from the source file.\n *\n * \"([^\"\\\\\\u000A\\u000D]|(\\\\(u[0-9a-fA-F]{4}|[\"\\\\/bfnrt])))*\"\n */\n\n\nfunction readString(source, start, line, col, prev) {\n var body = source.body;\n var position = start + 1;\n var chunkStart = position;\n var code = 0;\n var value = '';\n\n while (position < body.length && !isNaN(code = body.charCodeAt(position)) && // not LineTerminator\n code !== 0x000a && code !== 0x000d) {\n // Closing Quote (\")\n if (code === 34) {\n value += body.slice(chunkStart, position);\n return new Token(TokenKind.STRING, start, position + 1, line, col, prev, value);\n } // SourceCharacter\n\n\n if (code < 0x0020 && code !== 0x0009) {\n throw syntaxError(source, position, \"Invalid character within String: \".concat(printCharCode(code), \".\"));\n }\n\n ++position;\n\n if (code === 92) {\n // \\\n value += body.slice(chunkStart, position - 1);\n code = body.charCodeAt(position);\n\n switch (code) {\n case 34:\n value += '\"';\n break;\n\n case 47:\n value += '/';\n break;\n\n case 92:\n value += '\\\\';\n break;\n\n case 98:\n value += '\\b';\n break;\n\n case 102:\n value += '\\f';\n break;\n\n case 110:\n value += '\\n';\n break;\n\n case 114:\n value += '\\r';\n break;\n\n case 116:\n value += '\\t';\n break;\n\n case 117:\n {\n // uXXXX\n var charCode = uniCharCode(body.charCodeAt(position + 1), body.charCodeAt(position + 2), body.charCodeAt(position + 3), body.charCodeAt(position + 4));\n\n if (charCode < 0) {\n var invalidSequence = body.slice(position + 1, position + 5);\n throw syntaxError(source, position, \"Invalid character escape sequence: \\\\u\".concat(invalidSequence, \".\"));\n }\n\n value += String.fromCharCode(charCode);\n position += 4;\n break;\n }\n\n default:\n throw syntaxError(source, position, \"Invalid character escape sequence: \\\\\".concat(String.fromCharCode(code), \".\"));\n }\n\n ++position;\n chunkStart = position;\n }\n }\n\n throw syntaxError(source, position, 'Unterminated string.');\n}\n/**\n * Reads a block string token from the source file.\n *\n * \"\"\"(\"?\"?(\\\\\"\"\"|\\\\(?!=\"\"\")|[^\"\\\\]))*\"\"\"\n */\n\n\nfunction readBlockString(source, start, line, col, prev, lexer) {\n var body = source.body;\n var position = start + 3;\n var chunkStart = position;\n var code = 0;\n var rawValue = '';\n\n while (position < body.length && !isNaN(code = body.charCodeAt(position))) {\n // Closing Triple-Quote (\"\"\")\n if (code === 34 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34) {\n rawValue += body.slice(chunkStart, position);\n return new Token(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, dedentBlockStringValue(rawValue));\n } // SourceCharacter\n\n\n if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {\n throw syntaxError(source, position, \"Invalid character within String: \".concat(printCharCode(code), \".\"));\n }\n\n if (code === 10) {\n // new line\n ++position;\n ++lexer.line;\n lexer.lineStart = position;\n } else if (code === 13) {\n // carriage return\n if (body.charCodeAt(position + 1) === 10) {\n position += 2;\n } else {\n ++position;\n }\n\n ++lexer.line;\n lexer.lineStart = position;\n } else if ( // Escape Triple-Quote (\\\"\"\")\n code === 92 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34 && body.charCodeAt(position + 3) === 34) {\n rawValue += body.slice(chunkStart, position) + '\"\"\"';\n position += 4;\n chunkStart = position;\n } else {\n ++position;\n }\n }\n\n throw syntaxError(source, position, 'Unterminated string.');\n}\n/**\n * Converts four hexadecimal chars to the integer that the\n * string represents. For example, uniCharCode('0','0','0','f')\n * will return 15, and uniCharCode('0','0','f','f') returns 255.\n *\n * Returns a negative number on error, if a char was invalid.\n *\n * This is implemented by noting that char2hex() returns -1 on error,\n * which means the result of ORing the char2hex() will also be negative.\n */\n\n\nfunction uniCharCode(a, b, c, d) {\n return char2hex(a) << 12 | char2hex(b) << 8 | char2hex(c) << 4 | char2hex(d);\n}\n/**\n * Converts a hex character to its integer value.\n * '0' becomes 0, '9' becomes 9\n * 'A' becomes 10, 'F' becomes 15\n * 'a' becomes 10, 'f' becomes 15\n *\n * Returns -1 on error.\n */\n\n\nfunction char2hex(a) {\n return a >= 48 && a <= 57 ? a - 48 // 0-9\n : a >= 65 && a <= 70 ? a - 55 // A-F\n : a >= 97 && a <= 102 ? a - 87 // a-f\n : -1;\n}\n/**\n * Reads an alphanumeric + underscore name from the source.\n *\n * [_A-Za-z][_0-9A-Za-z]*\n */\n\n\nfunction readName(source, start, line, col, prev) {\n var body = source.body;\n var bodyLength = body.length;\n var position = start + 1;\n var code = 0;\n\n while (position !== bodyLength && !isNaN(code = body.charCodeAt(position)) && (code === 95 || // _\n code >= 48 && code <= 57 || // 0-9\n code >= 65 && code <= 90 || // A-Z\n code >= 97 && code <= 122) // a-z\n ) {\n ++position;\n }\n\n return new Token(TokenKind.NAME, start, position, line, col, prev, body.slice(start, position));\n} // _ A-Z a-z\n\n\nfunction isNameStart(code) {\n return code === 95 || code >= 65 && code <= 90 || code >= 97 && code <= 122;\n}\n","import { syntaxError } from \"../error/syntaxError.mjs\";\nimport { Kind } from \"./kinds.mjs\";\nimport { Location } from \"./ast.mjs\";\nimport { TokenKind } from \"./tokenKind.mjs\";\nimport { Source, isSource } from \"./source.mjs\";\nimport { DirectiveLocation } from \"./directiveLocation.mjs\";\nimport { Lexer, isPunctuatorTokenKind } from \"./lexer.mjs\";\n/**\n * Configuration options to control parser behavior\n */\n\n/**\n * Given a GraphQL source, parses it into a Document.\n * Throws GraphQLError if a syntax error is encountered.\n */\nexport function parse(source, options) {\n var parser = new Parser(source, options);\n return parser.parseDocument();\n}\n/**\n * Given a string containing a GraphQL value (ex. `[42]`), parse the AST for\n * that value.\n * Throws GraphQLError if a syntax error is encountered.\n *\n * This is useful within tools that operate upon GraphQL Values directly and\n * in isolation of complete GraphQL documents.\n *\n * Consider providing the results to the utility function: valueFromAST().\n */\n\nexport function parseValue(source, options) {\n var parser = new Parser(source, options);\n parser.expectToken(TokenKind.SOF);\n var value = parser.parseValueLiteral(false);\n parser.expectToken(TokenKind.EOF);\n return value;\n}\n/**\n * Given a string containing a GraphQL Type (ex. `[Int!]`), parse the AST for\n * that type.\n * Throws GraphQLError if a syntax error is encountered.\n *\n * This is useful within tools that operate upon GraphQL Types directly and\n * in isolation of complete GraphQL documents.\n *\n * Consider providing the results to the utility function: typeFromAST().\n */\n\nexport function parseType(source, options) {\n var parser = new Parser(source, options);\n parser.expectToken(TokenKind.SOF);\n var type = parser.parseTypeReference();\n parser.expectToken(TokenKind.EOF);\n return type;\n}\n/**\n * This class is exported only to assist people in implementing their own parsers\n * without duplicating too much code and should be used only as last resort for cases\n * such as experimental syntax or if certain features could not be contributed upstream.\n *\n * It is still part of the internal API and is versioned, so any changes to it are never\n * considered breaking changes. If you still need to support multiple versions of the\n * library, please use the `versionInfo` variable for version detection.\n *\n * @internal\n */\n\nexport var Parser = /*#__PURE__*/function () {\n function Parser(source, options) {\n var sourceObj = isSource(source) ? source : new Source(source);\n this._lexer = new Lexer(sourceObj);\n this._options = options;\n }\n /**\n * Converts a name lex token into a name parse node.\n */\n\n\n var _proto = Parser.prototype;\n\n _proto.parseName = function parseName() {\n var token = this.expectToken(TokenKind.NAME);\n return {\n kind: Kind.NAME,\n value: token.value,\n loc: this.loc(token)\n };\n } // Implements the parsing rules in the Document section.\n\n /**\n * Document : Definition+\n */\n ;\n\n _proto.parseDocument = function parseDocument() {\n var start = this._lexer.token;\n return {\n kind: Kind.DOCUMENT,\n definitions: this.many(TokenKind.SOF, this.parseDefinition, TokenKind.EOF),\n loc: this.loc(start)\n };\n }\n /**\n * Definition :\n * - ExecutableDefinition\n * - TypeSystemDefinition\n * - TypeSystemExtension\n *\n * ExecutableDefinition :\n * - OperationDefinition\n * - FragmentDefinition\n */\n ;\n\n _proto.parseDefinition = function parseDefinition() {\n if (this.peek(TokenKind.NAME)) {\n switch (this._lexer.token.value) {\n case 'query':\n case 'mutation':\n case 'subscription':\n return this.parseOperationDefinition();\n\n case 'fragment':\n return this.parseFragmentDefinition();\n\n case 'schema':\n case 'scalar':\n case 'type':\n case 'interface':\n case 'union':\n case 'enum':\n case 'input':\n case 'directive':\n return this.parseTypeSystemDefinition();\n\n case 'extend':\n return this.parseTypeSystemExtension();\n }\n } else if (this.peek(TokenKind.BRACE_L)) {\n return this.parseOperationDefinition();\n } else if (this.peekDescription()) {\n return this.parseTypeSystemDefinition();\n }\n\n throw this.unexpected();\n } // Implements the parsing rules in the Operations section.\n\n /**\n * OperationDefinition :\n * - SelectionSet\n * - OperationType Name? VariableDefinitions? Directives? SelectionSet\n */\n ;\n\n _proto.parseOperationDefinition = function parseOperationDefinition() {\n var start = this._lexer.token;\n\n if (this.peek(TokenKind.BRACE_L)) {\n return {\n kind: Kind.OPERATION_DEFINITION,\n operation: 'query',\n name: undefined,\n variableDefinitions: [],\n directives: [],\n selectionSet: this.parseSelectionSet(),\n loc: this.loc(start)\n };\n }\n\n var operation = this.parseOperationType();\n var name;\n\n if (this.peek(TokenKind.NAME)) {\n name = this.parseName();\n }\n\n return {\n kind: Kind.OPERATION_DEFINITION,\n operation: operation,\n name: name,\n variableDefinitions: this.parseVariableDefinitions(),\n directives: this.parseDirectives(false),\n selectionSet: this.parseSelectionSet(),\n loc: this.loc(start)\n };\n }\n /**\n * OperationType : one of query mutation subscription\n */\n ;\n\n _proto.parseOperationType = function parseOperationType() {\n var operationToken = this.expectToken(TokenKind.NAME);\n\n switch (operationToken.value) {\n case 'query':\n return 'query';\n\n case 'mutation':\n return 'mutation';\n\n case 'subscription':\n return 'subscription';\n }\n\n throw this.unexpected(operationToken);\n }\n /**\n * VariableDefinitions : ( VariableDefinition+ )\n */\n ;\n\n _proto.parseVariableDefinitions = function parseVariableDefinitions() {\n return this.optionalMany(TokenKind.PAREN_L, this.parseVariableDefinition, TokenKind.PAREN_R);\n }\n /**\n * VariableDefinition : Variable : Type DefaultValue? Directives[Const]?\n */\n ;\n\n _proto.parseVariableDefinition = function parseVariableDefinition() {\n var start = this._lexer.token;\n return {\n kind: Kind.VARIABLE_DEFINITION,\n variable: this.parseVariable(),\n type: (this.expectToken(TokenKind.COLON), this.parseTypeReference()),\n defaultValue: this.expectOptionalToken(TokenKind.EQUALS) ? this.parseValueLiteral(true) : undefined,\n directives: this.parseDirectives(true),\n loc: this.loc(start)\n };\n }\n /**\n * Variable : $ Name\n */\n ;\n\n _proto.parseVariable = function parseVariable() {\n var start = this._lexer.token;\n this.expectToken(TokenKind.DOLLAR);\n return {\n kind: Kind.VARIABLE,\n name: this.parseName(),\n loc: this.loc(start)\n };\n }\n /**\n * SelectionSet : { Selection+ }\n */\n ;\n\n _proto.parseSelectionSet = function parseSelectionSet() {\n var start = this._lexer.token;\n return {\n kind: Kind.SELECTION_SET,\n selections: this.many(TokenKind.BRACE_L, this.parseSelection, TokenKind.BRACE_R),\n loc: this.loc(start)\n };\n }\n /**\n * Selection :\n * - Field\n * - FragmentSpread\n * - InlineFragment\n */\n ;\n\n _proto.parseSelection = function parseSelection() {\n return this.peek(TokenKind.SPREAD) ? this.parseFragment() : this.parseField();\n }\n /**\n * Field : Alias? Name Arguments? Directives? SelectionSet?\n *\n * Alias : Name :\n */\n ;\n\n _proto.parseField = function parseField() {\n var start = this._lexer.token;\n var nameOrAlias = this.parseName();\n var alias;\n var name;\n\n if (this.expectOptionalToken(TokenKind.COLON)) {\n alias = nameOrAlias;\n name = this.parseName();\n } else {\n name = nameOrAlias;\n }\n\n return {\n kind: Kind.FIELD,\n alias: alias,\n name: name,\n arguments: this.parseArguments(false),\n directives: this.parseDirectives(false),\n selectionSet: this.peek(TokenKind.BRACE_L) ? this.parseSelectionSet() : undefined,\n loc: this.loc(start)\n };\n }\n /**\n * Arguments[Const] : ( Argument[?Const]+ )\n */\n ;\n\n _proto.parseArguments = function parseArguments(isConst) {\n var item = isConst ? this.parseConstArgument : this.parseArgument;\n return this.optionalMany(TokenKind.PAREN_L, item, TokenKind.PAREN_R);\n }\n /**\n * Argument[Const] : Name : Value[?Const]\n */\n ;\n\n _proto.parseArgument = function parseArgument() {\n var start = this._lexer.token;\n var name = this.parseName();\n this.expectToken(TokenKind.COLON);\n return {\n kind: Kind.ARGUMENT,\n name: name,\n value: this.parseValueLiteral(false),\n loc: this.loc(start)\n };\n };\n\n _proto.parseConstArgument = function parseConstArgument() {\n var start = this._lexer.token;\n return {\n kind: Kind.ARGUMENT,\n name: this.parseName(),\n value: (this.expectToken(TokenKind.COLON), this.parseValueLiteral(true)),\n loc: this.loc(start)\n };\n } // Implements the parsing rules in the Fragments section.\n\n /**\n * Corresponds to both FragmentSpread and InlineFragment in the spec.\n *\n * FragmentSpread : ... FragmentName Directives?\n *\n * InlineFragment : ... TypeCondition? Directives? SelectionSet\n */\n ;\n\n _proto.parseFragment = function parseFragment() {\n var start = this._lexer.token;\n this.expectToken(TokenKind.SPREAD);\n var hasTypeCondition = this.expectOptionalKeyword('on');\n\n if (!hasTypeCondition && this.peek(TokenKind.NAME)) {\n return {\n kind: Kind.FRAGMENT_SPREAD,\n name: this.parseFragmentName(),\n directives: this.parseDirectives(false),\n loc: this.loc(start)\n };\n }\n\n return {\n kind: Kind.INLINE_FRAGMENT,\n typeCondition: hasTypeCondition ? this.parseNamedType() : undefined,\n directives: this.parseDirectives(false),\n selectionSet: this.parseSelectionSet(),\n loc: this.loc(start)\n };\n }\n /**\n * FragmentDefinition :\n * - fragment FragmentName on TypeCondition Directives? SelectionSet\n *\n * TypeCondition : NamedType\n */\n ;\n\n _proto.parseFragmentDefinition = function parseFragmentDefinition() {\n var _this$_options;\n\n var start = this._lexer.token;\n this.expectKeyword('fragment'); // Experimental support for defining variables within fragments changes\n // the grammar of FragmentDefinition:\n // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet\n\n if (((_this$_options = this._options) === null || _this$_options === void 0 ? void 0 : _this$_options.experimentalFragmentVariables) === true) {\n return {\n kind: Kind.FRAGMENT_DEFINITION,\n name: this.parseFragmentName(),\n variableDefinitions: this.parseVariableDefinitions(),\n typeCondition: (this.expectKeyword('on'), this.parseNamedType()),\n directives: this.parseDirectives(false),\n selectionSet: this.parseSelectionSet(),\n loc: this.loc(start)\n };\n }\n\n return {\n kind: Kind.FRAGMENT_DEFINITION,\n name: this.parseFragmentName(),\n typeCondition: (this.expectKeyword('on'), this.parseNamedType()),\n directives: this.parseDirectives(false),\n selectionSet: this.parseSelectionSet(),\n loc: this.loc(start)\n };\n }\n /**\n * FragmentName : Name but not `on`\n */\n ;\n\n _proto.parseFragmentName = function parseFragmentName() {\n if (this._lexer.token.value === 'on') {\n throw this.unexpected();\n }\n\n return this.parseName();\n } // Implements the parsing rules in the Values section.\n\n /**\n * Value[Const] :\n * - [~Const] Variable\n * - IntValue\n * - FloatValue\n * - StringValue\n * - BooleanValue\n * - NullValue\n * - EnumValue\n * - ListValue[?Const]\n * - ObjectValue[?Const]\n *\n * BooleanValue : one of `true` `false`\n *\n * NullValue : `null`\n *\n * EnumValue : Name but not `true`, `false` or `null`\n */\n ;\n\n _proto.parseValueLiteral = function parseValueLiteral(isConst) {\n var token = this._lexer.token;\n\n switch (token.kind) {\n case TokenKind.BRACKET_L:\n return this.parseList(isConst);\n\n case TokenKind.BRACE_L:\n return this.parseObject(isConst);\n\n case TokenKind.INT:\n this._lexer.advance();\n\n return {\n kind: Kind.INT,\n value: token.value,\n loc: this.loc(token)\n };\n\n case TokenKind.FLOAT:\n this._lexer.advance();\n\n return {\n kind: Kind.FLOAT,\n value: token.value,\n loc: this.loc(token)\n };\n\n case TokenKind.STRING:\n case TokenKind.BLOCK_STRING:\n return this.parseStringLiteral();\n\n case TokenKind.NAME:\n this._lexer.advance();\n\n switch (token.value) {\n case 'true':\n return {\n kind: Kind.BOOLEAN,\n value: true,\n loc: this.loc(token)\n };\n\n case 'false':\n return {\n kind: Kind.BOOLEAN,\n value: false,\n loc: this.loc(token)\n };\n\n case 'null':\n return {\n kind: Kind.NULL,\n loc: this.loc(token)\n };\n\n default:\n return {\n kind: Kind.ENUM,\n value: token.value,\n loc: this.loc(token)\n };\n }\n\n case TokenKind.DOLLAR:\n if (!isConst) {\n return this.parseVariable();\n }\n\n break;\n }\n\n throw this.unexpected();\n };\n\n _proto.parseStringLiteral = function parseStringLiteral() {\n var token = this._lexer.token;\n\n this._lexer.advance();\n\n return {\n kind: Kind.STRING,\n value: token.value,\n block: token.kind === TokenKind.BLOCK_STRING,\n loc: this.loc(token)\n };\n }\n /**\n * ListValue[Const] :\n * - [ ]\n * - [ Value[?Const]+ ]\n */\n ;\n\n _proto.parseList = function parseList(isConst) {\n var _this = this;\n\n var start = this._lexer.token;\n\n var item = function item() {\n return _this.parseValueLiteral(isConst);\n };\n\n return {\n kind: Kind.LIST,\n values: this.any(TokenKind.BRACKET_L, item, TokenKind.BRACKET_R),\n loc: this.loc(start)\n };\n }\n /**\n * ObjectValue[Const] :\n * - { }\n * - { ObjectField[?Const]+ }\n */\n ;\n\n _proto.parseObject = function parseObject(isConst) {\n var _this2 = this;\n\n var start = this._lexer.token;\n\n var item = function item() {\n return _this2.parseObjectField(isConst);\n };\n\n return {\n kind: Kind.OBJECT,\n fields: this.any(TokenKind.BRACE_L, item, TokenKind.BRACE_R),\n loc: this.loc(start)\n };\n }\n /**\n * ObjectField[Const] : Name : Value[?Const]\n */\n ;\n\n _proto.parseObjectField = function parseObjectField(isConst) {\n var start = this._lexer.token;\n var name = this.parseName();\n this.expectToken(TokenKind.COLON);\n return {\n kind: Kind.OBJECT_FIELD,\n name: name,\n value: this.parseValueLiteral(isConst),\n loc: this.loc(start)\n };\n } // Implements the parsing rules in the Directives section.\n\n /**\n * Directives[Const] : Directive[?Const]+\n */\n ;\n\n _proto.parseDirectives = function parseDirectives(isConst) {\n var directives = [];\n\n while (this.peek(TokenKind.AT)) {\n directives.push(this.parseDirective(isConst));\n }\n\n return directives;\n }\n /**\n * Directive[Const] : @ Name Arguments[?Const]?\n */\n ;\n\n _proto.parseDirective = function parseDirective(isConst) {\n var start = this._lexer.token;\n this.expectToken(TokenKind.AT);\n return {\n kind: Kind.DIRECTIVE,\n name: this.parseName(),\n arguments: this.parseArguments(isConst),\n loc: this.loc(start)\n };\n } // Implements the parsing rules in the Types section.\n\n /**\n * Type :\n * - NamedType\n * - ListType\n * - NonNullType\n */\n ;\n\n _proto.parseTypeReference = function parseTypeReference() {\n var start = this._lexer.token;\n var type;\n\n if (this.expectOptionalToken(TokenKind.BRACKET_L)) {\n type = this.parseTypeReference();\n this.expectToken(TokenKind.BRACKET_R);\n type = {\n kind: Kind.LIST_TYPE,\n type: type,\n loc: this.loc(start)\n };\n } else {\n type = this.parseNamedType();\n }\n\n if (this.expectOptionalToken(TokenKind.BANG)) {\n return {\n kind: Kind.NON_NULL_TYPE,\n type: type,\n loc: this.loc(start)\n };\n }\n\n return type;\n }\n /**\n * NamedType : Name\n */\n ;\n\n _proto.parseNamedType = function parseNamedType() {\n var start = this._lexer.token;\n return {\n kind: Kind.NAMED_TYPE,\n name: this.parseName(),\n loc: this.loc(start)\n };\n } // Implements the parsing rules in the Type Definition section.\n\n /**\n * TypeSystemDefinition :\n * - SchemaDefinition\n * - TypeDefinition\n * - DirectiveDefinition\n *\n * TypeDefinition :\n * - ScalarTypeDefinition\n * - ObjectTypeDefinition\n * - InterfaceTypeDefinition\n * - UnionTypeDefinition\n * - EnumTypeDefinition\n * - InputObjectTypeDefinition\n */\n ;\n\n _proto.parseTypeSystemDefinition = function parseTypeSystemDefinition() {\n // Many definitions begin with a description and require a lookahead.\n var keywordToken = this.peekDescription() ? this._lexer.lookahead() : this._lexer.token;\n\n if (keywordToken.kind === TokenKind.NAME) {\n switch (keywordToken.value) {\n case 'schema':\n return this.parseSchemaDefinition();\n\n case 'scalar':\n return this.parseScalarTypeDefinition();\n\n case 'type':\n return this.parseObjectTypeDefinition();\n\n case 'interface':\n return this.parseInterfaceTypeDefinition();\n\n case 'union':\n return this.parseUnionTypeDefinition();\n\n case 'enum':\n return this.parseEnumTypeDefinition();\n\n case 'input':\n return this.parseInputObjectTypeDefinition();\n\n case 'directive':\n return this.parseDirectiveDefinition();\n }\n }\n\n throw this.unexpected(keywordToken);\n };\n\n _proto.peekDescription = function peekDescription() {\n return this.peek(TokenKind.STRING) || this.peek(TokenKind.BLOCK_STRING);\n }\n /**\n * Description : StringValue\n */\n ;\n\n _proto.parseDescription = function parseDescription() {\n if (this.peekDescription()) {\n return this.parseStringLiteral();\n }\n }\n /**\n * SchemaDefinition : Description? schema Directives[Const]? { OperationTypeDefinition+ }\n */\n ;\n\n _proto.parseSchemaDefinition = function parseSchemaDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n this.expectKeyword('schema');\n var directives = this.parseDirectives(true);\n var operationTypes = this.many(TokenKind.BRACE_L, this.parseOperationTypeDefinition, TokenKind.BRACE_R);\n return {\n kind: Kind.SCHEMA_DEFINITION,\n description: description,\n directives: directives,\n operationTypes: operationTypes,\n loc: this.loc(start)\n };\n }\n /**\n * OperationTypeDefinition : OperationType : NamedType\n */\n ;\n\n _proto.parseOperationTypeDefinition = function parseOperationTypeDefinition() {\n var start = this._lexer.token;\n var operation = this.parseOperationType();\n this.expectToken(TokenKind.COLON);\n var type = this.parseNamedType();\n return {\n kind: Kind.OPERATION_TYPE_DEFINITION,\n operation: operation,\n type: type,\n loc: this.loc(start)\n };\n }\n /**\n * ScalarTypeDefinition : Description? scalar Name Directives[Const]?\n */\n ;\n\n _proto.parseScalarTypeDefinition = function parseScalarTypeDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n this.expectKeyword('scalar');\n var name = this.parseName();\n var directives = this.parseDirectives(true);\n return {\n kind: Kind.SCALAR_TYPE_DEFINITION,\n description: description,\n name: name,\n directives: directives,\n loc: this.loc(start)\n };\n }\n /**\n * ObjectTypeDefinition :\n * Description?\n * type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?\n */\n ;\n\n _proto.parseObjectTypeDefinition = function parseObjectTypeDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n this.expectKeyword('type');\n var name = this.parseName();\n var interfaces = this.parseImplementsInterfaces();\n var directives = this.parseDirectives(true);\n var fields = this.parseFieldsDefinition();\n return {\n kind: Kind.OBJECT_TYPE_DEFINITION,\n description: description,\n name: name,\n interfaces: interfaces,\n directives: directives,\n fields: fields,\n loc: this.loc(start)\n };\n }\n /**\n * ImplementsInterfaces :\n * - implements `&`? NamedType\n * - ImplementsInterfaces & NamedType\n */\n ;\n\n _proto.parseImplementsInterfaces = function parseImplementsInterfaces() {\n var _this$_options2;\n\n if (!this.expectOptionalKeyword('implements')) {\n return [];\n }\n\n if (((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true) {\n var types = []; // Optional leading ampersand\n\n this.expectOptionalToken(TokenKind.AMP);\n\n do {\n types.push(this.parseNamedType());\n } while (this.expectOptionalToken(TokenKind.AMP) || this.peek(TokenKind.NAME));\n\n return types;\n }\n\n return this.delimitedMany(TokenKind.AMP, this.parseNamedType);\n }\n /**\n * FieldsDefinition : { FieldDefinition+ }\n */\n ;\n\n _proto.parseFieldsDefinition = function parseFieldsDefinition() {\n var _this$_options3;\n\n // Legacy support for the SDL?\n if (((_this$_options3 = this._options) === null || _this$_options3 === void 0 ? void 0 : _this$_options3.allowLegacySDLEmptyFields) === true && this.peek(TokenKind.BRACE_L) && this._lexer.lookahead().kind === TokenKind.BRACE_R) {\n this._lexer.advance();\n\n this._lexer.advance();\n\n return [];\n }\n\n return this.optionalMany(TokenKind.BRACE_L, this.parseFieldDefinition, TokenKind.BRACE_R);\n }\n /**\n * FieldDefinition :\n * - Description? Name ArgumentsDefinition? : Type Directives[Const]?\n */\n ;\n\n _proto.parseFieldDefinition = function parseFieldDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n var name = this.parseName();\n var args = this.parseArgumentDefs();\n this.expectToken(TokenKind.COLON);\n var type = this.parseTypeReference();\n var directives = this.parseDirectives(true);\n return {\n kind: Kind.FIELD_DEFINITION,\n description: description,\n name: name,\n arguments: args,\n type: type,\n directives: directives,\n loc: this.loc(start)\n };\n }\n /**\n * ArgumentsDefinition : ( InputValueDefinition+ )\n */\n ;\n\n _proto.parseArgumentDefs = function parseArgumentDefs() {\n return this.optionalMany(TokenKind.PAREN_L, this.parseInputValueDef, TokenKind.PAREN_R);\n }\n /**\n * InputValueDefinition :\n * - Description? Name : Type DefaultValue? Directives[Const]?\n */\n ;\n\n _proto.parseInputValueDef = function parseInputValueDef() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n var name = this.parseName();\n this.expectToken(TokenKind.COLON);\n var type = this.parseTypeReference();\n var defaultValue;\n\n if (this.expectOptionalToken(TokenKind.EQUALS)) {\n defaultValue = this.parseValueLiteral(true);\n }\n\n var directives = this.parseDirectives(true);\n return {\n kind: Kind.INPUT_VALUE_DEFINITION,\n description: description,\n name: name,\n type: type,\n defaultValue: defaultValue,\n directives: directives,\n loc: this.loc(start)\n };\n }\n /**\n * InterfaceTypeDefinition :\n * - Description? interface Name Directives[Const]? FieldsDefinition?\n */\n ;\n\n _proto.parseInterfaceTypeDefinition = function parseInterfaceTypeDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n this.expectKeyword('interface');\n var name = this.parseName();\n var interfaces = this.parseImplementsInterfaces();\n var directives = this.parseDirectives(true);\n var fields = this.parseFieldsDefinition();\n return {\n kind: Kind.INTERFACE_TYPE_DEFINITION,\n description: description,\n name: name,\n interfaces: interfaces,\n directives: directives,\n fields: fields,\n loc: this.loc(start)\n };\n }\n /**\n * UnionTypeDefinition :\n * - Description? union Name Directives[Const]? UnionMemberTypes?\n */\n ;\n\n _proto.parseUnionTypeDefinition = function parseUnionTypeDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n this.expectKeyword('union');\n var name = this.parseName();\n var directives = this.parseDirectives(true);\n var types = this.parseUnionMemberTypes();\n return {\n kind: Kind.UNION_TYPE_DEFINITION,\n description: description,\n name: name,\n directives: directives,\n types: types,\n loc: this.loc(start)\n };\n }\n /**\n * UnionMemberTypes :\n * - = `|`? NamedType\n * - UnionMemberTypes | NamedType\n */\n ;\n\n _proto.parseUnionMemberTypes = function parseUnionMemberTypes() {\n return this.expectOptionalToken(TokenKind.EQUALS) ? this.delimitedMany(TokenKind.PIPE, this.parseNamedType) : [];\n }\n /**\n * EnumTypeDefinition :\n * - Description? enum Name Directives[Const]? EnumValuesDefinition?\n */\n ;\n\n _proto.parseEnumTypeDefinition = function parseEnumTypeDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n this.expectKeyword('enum');\n var name = this.parseName();\n var directives = this.parseDirectives(true);\n var values = this.parseEnumValuesDefinition();\n return {\n kind: Kind.ENUM_TYPE_DEFINITION,\n description: description,\n name: name,\n directives: directives,\n values: values,\n loc: this.loc(start)\n };\n }\n /**\n * EnumValuesDefinition : { EnumValueDefinition+ }\n */\n ;\n\n _proto.parseEnumValuesDefinition = function parseEnumValuesDefinition() {\n return this.optionalMany(TokenKind.BRACE_L, this.parseEnumValueDefinition, TokenKind.BRACE_R);\n }\n /**\n * EnumValueDefinition : Description? EnumValue Directives[Const]?\n *\n * EnumValue : Name\n */\n ;\n\n _proto.parseEnumValueDefinition = function parseEnumValueDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n var name = this.parseName();\n var directives = this.parseDirectives(true);\n return {\n kind: Kind.ENUM_VALUE_DEFINITION,\n description: description,\n name: name,\n directives: directives,\n loc: this.loc(start)\n };\n }\n /**\n * InputObjectTypeDefinition :\n * - Description? input Name Directives[Const]? InputFieldsDefinition?\n */\n ;\n\n _proto.parseInputObjectTypeDefinition = function parseInputObjectTypeDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n this.expectKeyword('input');\n var name = this.parseName();\n var directives = this.parseDirectives(true);\n var fields = this.parseInputFieldsDefinition();\n return {\n kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,\n description: description,\n name: name,\n directives: directives,\n fields: fields,\n loc: this.loc(start)\n };\n }\n /**\n * InputFieldsDefinition : { InputValueDefinition+ }\n */\n ;\n\n _proto.parseInputFieldsDefinition = function parseInputFieldsDefinition() {\n return this.optionalMany(TokenKind.BRACE_L, this.parseInputValueDef, TokenKind.BRACE_R);\n }\n /**\n * TypeSystemExtension :\n * - SchemaExtension\n * - TypeExtension\n *\n * TypeExtension :\n * - ScalarTypeExtension\n * - ObjectTypeExtension\n * - InterfaceTypeExtension\n * - UnionTypeExtension\n * - EnumTypeExtension\n * - InputObjectTypeDefinition\n */\n ;\n\n _proto.parseTypeSystemExtension = function parseTypeSystemExtension() {\n var keywordToken = this._lexer.lookahead();\n\n if (keywordToken.kind === TokenKind.NAME) {\n switch (keywordToken.value) {\n case 'schema':\n return this.parseSchemaExtension();\n\n case 'scalar':\n return this.parseScalarTypeExtension();\n\n case 'type':\n return this.parseObjectTypeExtension();\n\n case 'interface':\n return this.parseInterfaceTypeExtension();\n\n case 'union':\n return this.parseUnionTypeExtension();\n\n case 'enum':\n return this.parseEnumTypeExtension();\n\n case 'input':\n return this.parseInputObjectTypeExtension();\n }\n }\n\n throw this.unexpected(keywordToken);\n }\n /**\n * SchemaExtension :\n * - extend schema Directives[Const]? { OperationTypeDefinition+ }\n * - extend schema Directives[Const]\n */\n ;\n\n _proto.parseSchemaExtension = function parseSchemaExtension() {\n var start = this._lexer.token;\n this.expectKeyword('extend');\n this.expectKeyword('schema');\n var directives = this.parseDirectives(true);\n var operationTypes = this.optionalMany(TokenKind.BRACE_L, this.parseOperationTypeDefinition, TokenKind.BRACE_R);\n\n if (directives.length === 0 && operationTypes.length === 0) {\n throw this.unexpected();\n }\n\n return {\n kind: Kind.SCHEMA_EXTENSION,\n directives: directives,\n operationTypes: operationTypes,\n loc: this.loc(start)\n };\n }\n /**\n * ScalarTypeExtension :\n * - extend scalar Name Directives[Const]\n */\n ;\n\n _proto.parseScalarTypeExtension = function parseScalarTypeExtension() {\n var start = this._lexer.token;\n this.expectKeyword('extend');\n this.expectKeyword('scalar');\n var name = this.parseName();\n var directives = this.parseDirectives(true);\n\n if (directives.length === 0) {\n throw this.unexpected();\n }\n\n return {\n kind: Kind.SCALAR_TYPE_EXTENSION,\n name: name,\n directives: directives,\n loc: this.loc(start)\n };\n }\n /**\n * ObjectTypeExtension :\n * - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition\n * - extend type Name ImplementsInterfaces? Directives[Const]\n * - extend type Name ImplementsInterfaces\n */\n ;\n\n _proto.parseObjectTypeExtension = function parseObjectTypeExtension() {\n var start = this._lexer.token;\n this.expectKeyword('extend');\n this.expectKeyword('type');\n var name = this.parseName();\n var interfaces = this.parseImplementsInterfaces();\n var directives = this.parseDirectives(true);\n var fields = this.parseFieldsDefinition();\n\n if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {\n throw this.unexpected();\n }\n\n return {\n kind: Kind.OBJECT_TYPE_EXTENSION,\n name: name,\n interfaces: interfaces,\n directives: directives,\n fields: fields,\n loc: this.loc(start)\n };\n }\n /**\n * InterfaceTypeExtension :\n * - extend interface Name ImplementsInterfaces? Directives[Const]? FieldsDefinition\n * - extend interface Name ImplementsInterfaces? Directives[Const]\n * - extend interface Name ImplementsInterfaces\n */\n ;\n\n _proto.parseInterfaceTypeExtension = function parseInterfaceTypeExtension() {\n var start = this._lexer.token;\n this.expectKeyword('extend');\n this.expectKeyword('interface');\n var name = this.parseName();\n var interfaces = this.parseImplementsInterfaces();\n var directives = this.parseDirectives(true);\n var fields = this.parseFieldsDefinition();\n\n if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {\n throw this.unexpected();\n }\n\n return {\n kind: Kind.INTERFACE_TYPE_EXTENSION,\n name: name,\n interfaces: interfaces,\n directives: directives,\n fields: fields,\n loc: this.loc(start)\n };\n }\n /**\n * UnionTypeExtension :\n * - extend union Name Directives[Const]? UnionMemberTypes\n * - extend union Name Directives[Const]\n */\n ;\n\n _proto.parseUnionTypeExtension = function parseUnionTypeExtension() {\n var start = this._lexer.token;\n this.expectKeyword('extend');\n this.expectKeyword('union');\n var name = this.parseName();\n var directives = this.parseDirectives(true);\n var types = this.parseUnionMemberTypes();\n\n if (directives.length === 0 && types.length === 0) {\n throw this.unexpected();\n }\n\n return {\n kind: Kind.UNION_TYPE_EXTENSION,\n name: name,\n directives: directives,\n types: types,\n loc: this.loc(start)\n };\n }\n /**\n * EnumTypeExtension :\n * - extend enum Name Directives[Const]? EnumValuesDefinition\n * - extend enum Name Directives[Const]\n */\n ;\n\n _proto.parseEnumTypeExtension = function parseEnumTypeExtension() {\n var start = this._lexer.token;\n this.expectKeyword('extend');\n this.expectKeyword('enum');\n var name = this.parseName();\n var directives = this.parseDirectives(true);\n var values = this.parseEnumValuesDefinition();\n\n if (directives.length === 0 && values.length === 0) {\n throw this.unexpected();\n }\n\n return {\n kind: Kind.ENUM_TYPE_EXTENSION,\n name: name,\n directives: directives,\n values: values,\n loc: this.loc(start)\n };\n }\n /**\n * InputObjectTypeExtension :\n * - extend input Name Directives[Const]? InputFieldsDefinition\n * - extend input Name Directives[Const]\n */\n ;\n\n _proto.parseInputObjectTypeExtension = function parseInputObjectTypeExtension() {\n var start = this._lexer.token;\n this.expectKeyword('extend');\n this.expectKeyword('input');\n var name = this.parseName();\n var directives = this.parseDirectives(true);\n var fields = this.parseInputFieldsDefinition();\n\n if (directives.length === 0 && fields.length === 0) {\n throw this.unexpected();\n }\n\n return {\n kind: Kind.INPUT_OBJECT_TYPE_EXTENSION,\n name: name,\n directives: directives,\n fields: fields,\n loc: this.loc(start)\n };\n }\n /**\n * DirectiveDefinition :\n * - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations\n */\n ;\n\n _proto.parseDirectiveDefinition = function parseDirectiveDefinition() {\n var start = this._lexer.token;\n var description = this.parseDescription();\n this.expectKeyword('directive');\n this.expectToken(TokenKind.AT);\n var name = this.parseName();\n var args = this.parseArgumentDefs();\n var repeatable = this.expectOptionalKeyword('repeatable');\n this.expectKeyword('on');\n var locations = this.parseDirectiveLocations();\n return {\n kind: Kind.DIRECTIVE_DEFINITION,\n description: description,\n name: name,\n arguments: args,\n repeatable: repeatable,\n locations: locations,\n loc: this.loc(start)\n };\n }\n /**\n * DirectiveLocations :\n * - `|`? DirectiveLocation\n * - DirectiveLocations | DirectiveLocation\n */\n ;\n\n _proto.parseDirectiveLocations = function parseDirectiveLocations() {\n return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);\n }\n /*\n * DirectiveLocation :\n * - ExecutableDirectiveLocation\n * - TypeSystemDirectiveLocation\n *\n * ExecutableDirectiveLocation : one of\n * `QUERY`\n * `MUTATION`\n * `SUBSCRIPTION`\n * `FIELD`\n * `FRAGMENT_DEFINITION`\n * `FRAGMENT_SPREAD`\n * `INLINE_FRAGMENT`\n *\n * TypeSystemDirectiveLocation : one of\n * `SCHEMA`\n * `SCALAR`\n * `OBJECT`\n * `FIELD_DEFINITION`\n * `ARGUMENT_DEFINITION`\n * `INTERFACE`\n * `UNION`\n * `ENUM`\n * `ENUM_VALUE`\n * `INPUT_OBJECT`\n * `INPUT_FIELD_DEFINITION`\n */\n ;\n\n _proto.parseDirectiveLocation = function parseDirectiveLocation() {\n var start = this._lexer.token;\n var name = this.parseName();\n\n if (DirectiveLocation[name.value] !== undefined) {\n return name;\n }\n\n throw this.unexpected(start);\n } // Core parsing utility functions\n\n /**\n * Returns a location object, used to identify the place in the source that created a given parsed object.\n */\n ;\n\n _proto.loc = function loc(startToken) {\n var _this$_options4;\n\n if (((_this$_options4 = this._options) === null || _this$_options4 === void 0 ? void 0 : _this$_options4.noLocation) !== true) {\n return new Location(startToken, this._lexer.lastToken, this._lexer.source);\n }\n }\n /**\n * Determines if the next token is of a given kind\n */\n ;\n\n _proto.peek = function peek(kind) {\n return this._lexer.token.kind === kind;\n }\n /**\n * If the next token is of the given kind, return that token after advancing the lexer.\n * Otherwise, do not change the parser state and throw an error.\n */\n ;\n\n _proto.expectToken = function expectToken(kind) {\n var token = this._lexer.token;\n\n if (token.kind === kind) {\n this._lexer.advance();\n\n return token;\n }\n\n throw syntaxError(this._lexer.source, token.start, \"Expected \".concat(getTokenKindDesc(kind), \", found \").concat(getTokenDesc(token), \".\"));\n }\n /**\n * If the next token is of the given kind, return that token after advancing the lexer.\n * Otherwise, do not change the parser state and return undefined.\n */\n ;\n\n _proto.expectOptionalToken = function expectOptionalToken(kind) {\n var token = this._lexer.token;\n\n if (token.kind === kind) {\n this._lexer.advance();\n\n return token;\n }\n\n return undefined;\n }\n /**\n * If the next token is a given keyword, advance the lexer.\n * Otherwise, do not change the parser state and throw an error.\n */\n ;\n\n _proto.expectKeyword = function expectKeyword(value) {\n var token = this._lexer.token;\n\n if (token.kind === TokenKind.NAME && token.value === value) {\n this._lexer.advance();\n } else {\n throw syntaxError(this._lexer.source, token.start, \"Expected \\\"\".concat(value, \"\\\", found \").concat(getTokenDesc(token), \".\"));\n }\n }\n /**\n * If the next token is a given keyword, return \"true\" after advancing the lexer.\n * Otherwise, do not change the parser state and return \"false\".\n */\n ;\n\n _proto.expectOptionalKeyword = function expectOptionalKeyword(value) {\n var token = this._lexer.token;\n\n if (token.kind === TokenKind.NAME && token.value === value) {\n this._lexer.advance();\n\n return true;\n }\n\n return false;\n }\n /**\n * Helper function for creating an error when an unexpected lexed token is encountered.\n */\n ;\n\n _proto.unexpected = function unexpected(atToken) {\n var token = atToken !== null && atToken !== void 0 ? atToken : this._lexer.token;\n return syntaxError(this._lexer.source, token.start, \"Unexpected \".concat(getTokenDesc(token), \".\"));\n }\n /**\n * Returns a possibly empty list of parse nodes, determined by the parseFn.\n * This list begins with a lex token of openKind and ends with a lex token of closeKind.\n * Advances the parser to the next lex token after the closing token.\n */\n ;\n\n _proto.any = function any(openKind, parseFn, closeKind) {\n this.expectToken(openKind);\n var nodes = [];\n\n while (!this.expectOptionalToken(closeKind)) {\n nodes.push(parseFn.call(this));\n }\n\n return nodes;\n }\n /**\n * Returns a list of parse nodes, determined by the parseFn.\n * It can be empty only if open token is missing otherwise it will always return non-empty list\n * that begins with a lex token of openKind and ends with a lex token of closeKind.\n * Advances the parser to the next lex token after the closing token.\n */\n ;\n\n _proto.optionalMany = function optionalMany(openKind, parseFn, closeKind) {\n if (this.expectOptionalToken(openKind)) {\n var nodes = [];\n\n do {\n nodes.push(parseFn.call(this));\n } while (!this.expectOptionalToken(closeKind));\n\n return nodes;\n }\n\n return [];\n }\n /**\n * Returns a non-empty list of parse nodes, determined by the parseFn.\n * This list begins with a lex token of openKind and ends with a lex token of closeKind.\n * Advances the parser to the next lex token after the closing token.\n */\n ;\n\n _proto.many = function many(openKind, parseFn, closeKind) {\n this.expectToken(openKind);\n var nodes = [];\n\n do {\n nodes.push(parseFn.call(this));\n } while (!this.expectOptionalToken(closeKind));\n\n return nodes;\n }\n /**\n * Returns a non-empty list of parse nodes, determined by the parseFn.\n * This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.\n * Advances the parser to the next lex token after last item in the list.\n */\n ;\n\n _proto.delimitedMany = function delimitedMany(delimiterKind, parseFn) {\n this.expectOptionalToken(delimiterKind);\n var nodes = [];\n\n do {\n nodes.push(parseFn.call(this));\n } while (this.expectOptionalToken(delimiterKind));\n\n return nodes;\n };\n\n return Parser;\n}();\n/**\n * A helper function to describe a token as a string for debugging.\n */\n\nfunction getTokenDesc(token) {\n var value = token.value;\n return getTokenKindDesc(token.kind) + (value != null ? \" \\\"\".concat(value, \"\\\"\") : '');\n}\n/**\n * A helper function to describe a token kind as a string for debugging.\n */\n\n\nfunction getTokenKindDesc(kind) {\n return isPunctuatorTokenKind(kind) ? \"\\\"\".concat(kind, \"\\\"\") : kind;\n}\n","import inspect from \"../jsutils/inspect.mjs\";\nimport { isNode } from \"./ast.mjs\";\n/**\n * A visitor is provided to visit, it contains the collection of\n * relevant functions to be called during the visitor's traversal.\n */\n\nexport var QueryDocumentKeys = {\n Name: [],\n Document: ['definitions'],\n OperationDefinition: ['name', 'variableDefinitions', 'directives', 'selectionSet'],\n VariableDefinition: ['variable', 'type', 'defaultValue', 'directives'],\n Variable: ['name'],\n SelectionSet: ['selections'],\n Field: ['alias', 'name', 'arguments', 'directives', 'selectionSet'],\n Argument: ['name', 'value'],\n FragmentSpread: ['name', 'directives'],\n InlineFragment: ['typeCondition', 'directives', 'selectionSet'],\n FragmentDefinition: ['name', // Note: fragment variable definitions are experimental and may be changed\n // or removed in the future.\n 'variableDefinitions', 'typeCondition', 'directives', 'selectionSet'],\n IntValue: [],\n FloatValue: [],\n StringValue: [],\n BooleanValue: [],\n NullValue: [],\n EnumValue: [],\n ListValue: ['values'],\n ObjectValue: ['fields'],\n ObjectField: ['name', 'value'],\n Directive: ['name', 'arguments'],\n NamedType: ['name'],\n ListType: ['type'],\n NonNullType: ['type'],\n SchemaDefinition: ['description', 'directives', 'operationTypes'],\n OperationTypeDefinition: ['type'],\n ScalarTypeDefinition: ['description', 'name', 'directives'],\n ObjectTypeDefinition: ['description', 'name', 'interfaces', 'directives', 'fields'],\n FieldDefinition: ['description', 'name', 'arguments', 'type', 'directives'],\n InputValueDefinition: ['description', 'name', 'type', 'defaultValue', 'directives'],\n InterfaceTypeDefinition: ['description', 'name', 'interfaces', 'directives', 'fields'],\n UnionTypeDefinition: ['description', 'name', 'directives', 'types'],\n EnumTypeDefinition: ['description', 'name', 'directives', 'values'],\n EnumValueDefinition: ['description', 'name', 'directives'],\n InputObjectTypeDefinition: ['description', 'name', 'directives', 'fields'],\n DirectiveDefinition: ['description', 'name', 'arguments', 'locations'],\n SchemaExtension: ['directives', 'operationTypes'],\n ScalarTypeExtension: ['name', 'directives'],\n ObjectTypeExtension: ['name', 'interfaces', 'directives', 'fields'],\n InterfaceTypeExtension: ['name', 'interfaces', 'directives', 'fields'],\n UnionTypeExtension: ['name', 'directives', 'types'],\n EnumTypeExtension: ['name', 'directives', 'values'],\n InputObjectTypeExtension: ['name', 'directives', 'fields']\n};\nexport var BREAK = Object.freeze({});\n/**\n * visit() will walk through an AST using a depth-first traversal, calling\n * the visitor's enter function at each node in the traversal, and calling the\n * leave function after visiting that node and all of its child nodes.\n *\n * By returning different values from the enter and leave functions, the\n * behavior of the visitor can be altered, including skipping over a sub-tree of\n * the AST (by returning false), editing the AST by returning a value or null\n * to remove the value, or to stop the whole traversal by returning BREAK.\n *\n * When using visit() to edit an AST, the original AST will not be modified, and\n * a new version of the AST with the changes applied will be returned from the\n * visit function.\n *\n * const editedAST = visit(ast, {\n * enter(node, key, parent, path, ancestors) {\n * // @return\n * // undefined: no action\n * // false: skip visiting this node\n * // visitor.BREAK: stop visiting altogether\n * // null: delete this node\n * // any value: replace this node with the returned value\n * },\n * leave(node, key, parent, path, ancestors) {\n * // @return\n * // undefined: no action\n * // false: no action\n * // visitor.BREAK: stop visiting altogether\n * // null: delete this node\n * // any value: replace this node with the returned value\n * }\n * });\n *\n * Alternatively to providing enter() and leave() functions, a visitor can\n * instead provide functions named the same as the kinds of AST nodes, or\n * enter/leave visitors at a named key, leading to four permutations of the\n * visitor API:\n *\n * 1) Named visitors triggered when entering a node of a specific kind.\n *\n * visit(ast, {\n * Kind(node) {\n * // enter the \"Kind\" node\n * }\n * })\n *\n * 2) Named visitors that trigger upon entering and leaving a node of\n * a specific kind.\n *\n * visit(ast, {\n * Kind: {\n * enter(node) {\n * // enter the \"Kind\" node\n * }\n * leave(node) {\n * // leave the \"Kind\" node\n * }\n * }\n * })\n *\n * 3) Generic visitors that trigger upon entering and leaving any node.\n *\n * visit(ast, {\n * enter(node) {\n * // enter any node\n * },\n * leave(node) {\n * // leave any node\n * }\n * })\n *\n * 4) Parallel visitors for entering and leaving nodes of a specific kind.\n *\n * visit(ast, {\n * enter: {\n * Kind(node) {\n * // enter the \"Kind\" node\n * }\n * },\n * leave: {\n * Kind(node) {\n * // leave the \"Kind\" node\n * }\n * }\n * })\n */\n\nexport function visit(root, visitor) {\n var visitorKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : QueryDocumentKeys;\n\n /* eslint-disable no-undef-init */\n var stack = undefined;\n var inArray = Array.isArray(root);\n var keys = [root];\n var index = -1;\n var edits = [];\n var node = undefined;\n var key = undefined;\n var parent = undefined;\n var path = [];\n var ancestors = [];\n var newRoot = root;\n /* eslint-enable no-undef-init */\n\n do {\n index++;\n var isLeaving = index === keys.length;\n var isEdited = isLeaving && edits.length !== 0;\n\n if (isLeaving) {\n key = ancestors.length === 0 ? undefined : path[path.length - 1];\n node = parent;\n parent = ancestors.pop();\n\n if (isEdited) {\n if (inArray) {\n node = node.slice();\n } else {\n var clone = {};\n\n for (var _i2 = 0, _Object$keys2 = Object.keys(node); _i2 < _Object$keys2.length; _i2++) {\n var k = _Object$keys2[_i2];\n clone[k] = node[k];\n }\n\n node = clone;\n }\n\n var editOffset = 0;\n\n for (var ii = 0; ii < edits.length; ii++) {\n var editKey = edits[ii][0];\n var editValue = edits[ii][1];\n\n if (inArray) {\n editKey -= editOffset;\n }\n\n if (inArray && editValue === null) {\n node.splice(editKey, 1);\n editOffset++;\n } else {\n node[editKey] = editValue;\n }\n }\n }\n\n index = stack.index;\n keys = stack.keys;\n edits = stack.edits;\n inArray = stack.inArray;\n stack = stack.prev;\n } else {\n key = parent ? inArray ? index : keys[index] : undefined;\n node = parent ? parent[key] : newRoot;\n\n if (node === null || node === undefined) {\n continue;\n }\n\n if (parent) {\n path.push(key);\n }\n }\n\n var result = void 0;\n\n if (!Array.isArray(node)) {\n if (!isNode(node)) {\n throw new Error(\"Invalid AST Node: \".concat(inspect(node), \".\"));\n }\n\n var visitFn = getVisitFn(visitor, node.kind, isLeaving);\n\n if (visitFn) {\n result = visitFn.call(visitor, node, key, parent, path, ancestors);\n\n if (result === BREAK) {\n break;\n }\n\n if (result === false) {\n if (!isLeaving) {\n path.pop();\n continue;\n }\n } else if (result !== undefined) {\n edits.push([key, result]);\n\n if (!isLeaving) {\n if (isNode(result)) {\n node = result;\n } else {\n path.pop();\n continue;\n }\n }\n }\n }\n }\n\n if (result === undefined && isEdited) {\n edits.push([key, node]);\n }\n\n if (isLeaving) {\n path.pop();\n } else {\n var _visitorKeys$node$kin;\n\n stack = {\n inArray: inArray,\n index: index,\n keys: keys,\n edits: edits,\n prev: stack\n };\n inArray = Array.isArray(node);\n keys = inArray ? node : (_visitorKeys$node$kin = visitorKeys[node.kind]) !== null && _visitorKeys$node$kin !== void 0 ? _visitorKeys$node$kin : [];\n index = -1;\n edits = [];\n\n if (parent) {\n ancestors.push(parent);\n }\n\n parent = node;\n }\n } while (stack !== undefined);\n\n if (edits.length !== 0) {\n newRoot = edits[edits.length - 1][1];\n }\n\n return newRoot;\n}\n/**\n * Creates a new visitor instance which delegates to many visitors to run in\n * parallel. Each visitor will be visited for each node before moving on.\n *\n * If a prior visitor edits a node, no following visitors will see that node.\n */\n\nexport function visitInParallel(visitors) {\n var skipping = new Array(visitors.length);\n return {\n enter: function enter(node) {\n for (var i = 0; i < visitors.length; i++) {\n if (skipping[i] == null) {\n var fn = getVisitFn(visitors[i], node.kind,\n /* isLeaving */\n false);\n\n if (fn) {\n var result = fn.apply(visitors[i], arguments);\n\n if (result === false) {\n skipping[i] = node;\n } else if (result === BREAK) {\n skipping[i] = BREAK;\n } else if (result !== undefined) {\n return result;\n }\n }\n }\n }\n },\n leave: function leave(node) {\n for (var i = 0; i < visitors.length; i++) {\n if (skipping[i] == null) {\n var fn = getVisitFn(visitors[i], node.kind,\n /* isLeaving */\n true);\n\n if (fn) {\n var result = fn.apply(visitors[i], arguments);\n\n if (result === BREAK) {\n skipping[i] = BREAK;\n } else if (result !== undefined && result !== false) {\n return result;\n }\n }\n } else if (skipping[i] === node) {\n skipping[i] = null;\n }\n }\n }\n };\n}\n/**\n * Given a visitor instance, if it is leaving or not, and a node kind, return\n * the function the visitor runtime should call.\n */\n\nexport function getVisitFn(visitor, kind, isLeaving) {\n var kindVisitor = visitor[kind];\n\n if (kindVisitor) {\n if (!isLeaving && typeof kindVisitor === 'function') {\n // { Kind() {} }\n return kindVisitor;\n }\n\n var kindSpecificVisitor = isLeaving ? kindVisitor.leave : kindVisitor.enter;\n\n if (typeof kindSpecificVisitor === 'function') {\n // { Kind: { enter() {}, leave() {} } }\n return kindSpecificVisitor;\n }\n } else {\n var specificVisitor = isLeaving ? visitor.leave : visitor.enter;\n\n if (specificVisitor) {\n if (typeof specificVisitor === 'function') {\n // { enter() {}, leave() {} }\n return specificVisitor;\n }\n\n var specificKindVisitor = specificVisitor[kind];\n\n if (typeof specificKindVisitor === 'function') {\n // { enter: { Kind() {} }, leave: { Kind() {} } }\n return specificKindVisitor;\n }\n }\n }\n}\n","import { visit } from \"./visitor.mjs\";\nimport { printBlockString } from \"./blockString.mjs\";\n/**\n * Converts an AST into a string, using one set of reasonable\n * formatting rules.\n */\n\nexport function print(ast) {\n return visit(ast, {\n leave: printDocASTReducer\n });\n}\nvar MAX_LINE_LENGTH = 80; // TODO: provide better type coverage in future\n\nvar printDocASTReducer = {\n Name: function Name(node) {\n return node.value;\n },\n Variable: function Variable(node) {\n return '$' + node.name;\n },\n // Document\n Document: function Document(node) {\n return join(node.definitions, '\\n\\n') + '\\n';\n },\n OperationDefinition: function OperationDefinition(node) {\n var op = node.operation;\n var name = node.name;\n var varDefs = wrap('(', join(node.variableDefinitions, ', '), ')');\n var directives = join(node.directives, ' ');\n var selectionSet = node.selectionSet; // Anonymous queries with no directives or variable definitions can use\n // the query short form.\n\n return !name && !directives && !varDefs && op === 'query' ? selectionSet : join([op, join([name, varDefs]), directives, selectionSet], ' ');\n },\n VariableDefinition: function VariableDefinition(_ref) {\n var variable = _ref.variable,\n type = _ref.type,\n defaultValue = _ref.defaultValue,\n directives = _ref.directives;\n return variable + ': ' + type + wrap(' = ', defaultValue) + wrap(' ', join(directives, ' '));\n },\n SelectionSet: function SelectionSet(_ref2) {\n var selections = _ref2.selections;\n return block(selections);\n },\n Field: function Field(_ref3) {\n var alias = _ref3.alias,\n name = _ref3.name,\n args = _ref3.arguments,\n directives = _ref3.directives,\n selectionSet = _ref3.selectionSet;\n var prefix = wrap('', alias, ': ') + name;\n var argsLine = prefix + wrap('(', join(args, ', '), ')');\n\n if (argsLine.length > MAX_LINE_LENGTH) {\n argsLine = prefix + wrap('(\\n', indent(join(args, '\\n')), '\\n)');\n }\n\n return join([argsLine, join(directives, ' '), selectionSet], ' ');\n },\n Argument: function Argument(_ref4) {\n var name = _ref4.name,\n value = _ref4.value;\n return name + ': ' + value;\n },\n // Fragments\n FragmentSpread: function FragmentSpread(_ref5) {\n var name = _ref5.name,\n directives = _ref5.directives;\n return '...' + name + wrap(' ', join(directives, ' '));\n },\n InlineFragment: function InlineFragment(_ref6) {\n var typeCondition = _ref6.typeCondition,\n directives = _ref6.directives,\n selectionSet = _ref6.selectionSet;\n return join(['...', wrap('on ', typeCondition), join(directives, ' '), selectionSet], ' ');\n },\n FragmentDefinition: function FragmentDefinition(_ref7) {\n var name = _ref7.name,\n typeCondition = _ref7.typeCondition,\n variableDefinitions = _ref7.variableDefinitions,\n directives = _ref7.directives,\n selectionSet = _ref7.selectionSet;\n return (// Note: fragment variable definitions are experimental and may be changed\n // or removed in the future.\n \"fragment \".concat(name).concat(wrap('(', join(variableDefinitions, ', '), ')'), \" \") + \"on \".concat(typeCondition, \" \").concat(wrap('', join(directives, ' '), ' ')) + selectionSet\n );\n },\n // Value\n IntValue: function IntValue(_ref8) {\n var value = _ref8.value;\n return value;\n },\n FloatValue: function FloatValue(_ref9) {\n var value = _ref9.value;\n return value;\n },\n StringValue: function StringValue(_ref10, key) {\n var value = _ref10.value,\n isBlockString = _ref10.block;\n return isBlockString ? printBlockString(value, key === 'description' ? '' : ' ') : JSON.stringify(value);\n },\n BooleanValue: function BooleanValue(_ref11) {\n var value = _ref11.value;\n return value ? 'true' : 'false';\n },\n NullValue: function NullValue() {\n return 'null';\n },\n EnumValue: function EnumValue(_ref12) {\n var value = _ref12.value;\n return value;\n },\n ListValue: function ListValue(_ref13) {\n var values = _ref13.values;\n return '[' + join(values, ', ') + ']';\n },\n ObjectValue: function ObjectValue(_ref14) {\n var fields = _ref14.fields;\n return '{' + join(fields, ', ') + '}';\n },\n ObjectField: function ObjectField(_ref15) {\n var name = _ref15.name,\n value = _ref15.value;\n return name + ': ' + value;\n },\n // Directive\n Directive: function Directive(_ref16) {\n var name = _ref16.name,\n args = _ref16.arguments;\n return '@' + name + wrap('(', join(args, ', '), ')');\n },\n // Type\n NamedType: function NamedType(_ref17) {\n var name = _ref17.name;\n return name;\n },\n ListType: function ListType(_ref18) {\n var type = _ref18.type;\n return '[' + type + ']';\n },\n NonNullType: function NonNullType(_ref19) {\n var type = _ref19.type;\n return type + '!';\n },\n // Type System Definitions\n SchemaDefinition: addDescription(function (_ref20) {\n var directives = _ref20.directives,\n operationTypes = _ref20.operationTypes;\n return join(['schema', join(directives, ' '), block(operationTypes)], ' ');\n }),\n OperationTypeDefinition: function OperationTypeDefinition(_ref21) {\n var operation = _ref21.operation,\n type = _ref21.type;\n return operation + ': ' + type;\n },\n ScalarTypeDefinition: addDescription(function (_ref22) {\n var name = _ref22.name,\n directives = _ref22.directives;\n return join(['scalar', name, join(directives, ' ')], ' ');\n }),\n ObjectTypeDefinition: addDescription(function (_ref23) {\n var name = _ref23.name,\n interfaces = _ref23.interfaces,\n directives = _ref23.directives,\n fields = _ref23.fields;\n return join(['type', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');\n }),\n FieldDefinition: addDescription(function (_ref24) {\n var name = _ref24.name,\n args = _ref24.arguments,\n type = _ref24.type,\n directives = _ref24.directives;\n return name + (hasMultilineItems(args) ? wrap('(\\n', indent(join(args, '\\n')), '\\n)') : wrap('(', join(args, ', '), ')')) + ': ' + type + wrap(' ', join(directives, ' '));\n }),\n InputValueDefinition: addDescription(function (_ref25) {\n var name = _ref25.name,\n type = _ref25.type,\n defaultValue = _ref25.defaultValue,\n directives = _ref25.directives;\n return join([name + ': ' + type, wrap('= ', defaultValue), join(directives, ' ')], ' ');\n }),\n InterfaceTypeDefinition: addDescription(function (_ref26) {\n var name = _ref26.name,\n interfaces = _ref26.interfaces,\n directives = _ref26.directives,\n fields = _ref26.fields;\n return join(['interface', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');\n }),\n UnionTypeDefinition: addDescription(function (_ref27) {\n var name = _ref27.name,\n directives = _ref27.directives,\n types = _ref27.types;\n return join(['union', name, join(directives, ' '), types && types.length !== 0 ? '= ' + join(types, ' | ') : ''], ' ');\n }),\n EnumTypeDefinition: addDescription(function (_ref28) {\n var name = _ref28.name,\n directives = _ref28.directives,\n values = _ref28.values;\n return join(['enum', name, join(directives, ' '), block(values)], ' ');\n }),\n EnumValueDefinition: addDescription(function (_ref29) {\n var name = _ref29.name,\n directives = _ref29.directives;\n return join([name, join(directives, ' ')], ' ');\n }),\n InputObjectTypeDefinition: addDescription(function (_ref30) {\n var name = _ref30.name,\n directives = _ref30.directives,\n fields = _ref30.fields;\n return join(['input', name, join(directives, ' '), block(fields)], ' ');\n }),\n DirectiveDefinition: addDescription(function (_ref31) {\n var name = _ref31.name,\n args = _ref31.arguments,\n repeatable = _ref31.repeatable,\n locations = _ref31.locations;\n return 'directive @' + name + (hasMultilineItems(args) ? wrap('(\\n', indent(join(args, '\\n')), '\\n)') : wrap('(', join(args, ', '), ')')) + (repeatable ? ' repeatable' : '') + ' on ' + join(locations, ' | ');\n }),\n SchemaExtension: function SchemaExtension(_ref32) {\n var directives = _ref32.directives,\n operationTypes = _ref32.operationTypes;\n return join(['extend schema', join(directives, ' '), block(operationTypes)], ' ');\n },\n ScalarTypeExtension: function ScalarTypeExtension(_ref33) {\n var name = _ref33.name,\n directives = _ref33.directives;\n return join(['extend scalar', name, join(directives, ' ')], ' ');\n },\n ObjectTypeExtension: function ObjectTypeExtension(_ref34) {\n var name = _ref34.name,\n interfaces = _ref34.interfaces,\n directives = _ref34.directives,\n fields = _ref34.fields;\n return join(['extend type', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');\n },\n InterfaceTypeExtension: function InterfaceTypeExtension(_ref35) {\n var name = _ref35.name,\n interfaces = _ref35.interfaces,\n directives = _ref35.directives,\n fields = _ref35.fields;\n return join(['extend interface', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');\n },\n UnionTypeExtension: function UnionTypeExtension(_ref36) {\n var name = _ref36.name,\n directives = _ref36.directives,\n types = _ref36.types;\n return join(['extend union', name, join(directives, ' '), types && types.length !== 0 ? '= ' + join(types, ' | ') : ''], ' ');\n },\n EnumTypeExtension: function EnumTypeExtension(_ref37) {\n var name = _ref37.name,\n directives = _ref37.directives,\n values = _ref37.values;\n return join(['extend enum', name, join(directives, ' '), block(values)], ' ');\n },\n InputObjectTypeExtension: function InputObjectTypeExtension(_ref38) {\n var name = _ref38.name,\n directives = _ref38.directives,\n fields = _ref38.fields;\n return join(['extend input', name, join(directives, ' '), block(fields)], ' ');\n }\n};\n\nfunction addDescription(cb) {\n return function (node) {\n return join([node.description, cb(node)], '\\n');\n };\n}\n/**\n * Given maybeArray, print an empty string if it is null or empty, otherwise\n * print all items together separated by separator if provided\n */\n\n\nfunction join(maybeArray) {\n var _maybeArray$filter$jo;\n\n var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';\n return (_maybeArray$filter$jo = maybeArray === null || maybeArray === void 0 ? void 0 : maybeArray.filter(function (x) {\n return x;\n }).join(separator)) !== null && _maybeArray$filter$jo !== void 0 ? _maybeArray$filter$jo : '';\n}\n/**\n * Given array, print each item on its own line, wrapped in an\n * indented \"{ }\" block.\n */\n\n\nfunction block(array) {\n return wrap('{\\n', indent(join(array, '\\n')), '\\n}');\n}\n/**\n * If maybeString is not null or empty, then wrap with start and end, otherwise print an empty string.\n */\n\n\nfunction wrap(start, maybeString) {\n var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';\n return maybeString != null && maybeString !== '' ? start + maybeString + end : '';\n}\n\nfunction indent(str) {\n return wrap(' ', str.replace(/\\n/g, '\\n '));\n}\n\nfunction isMultiline(str) {\n return str.indexOf('\\n') !== -1;\n}\n\nfunction hasMultilineItems(maybeArray) {\n return maybeArray != null && maybeArray.some(isMultiline);\n}\n","/*\n * Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with\n * the License. A copy of the License is located at\n *\n * http://aws.amazon.com/apache2.0/\n *\n * or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\n * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions\n * and limitations under the License.\n */\nimport {\n\tDocumentNode,\n\tOperationDefinitionNode,\n\tprint,\n\tparse,\n\tGraphQLError,\n\tOperationTypeNode,\n} from 'graphql';\nimport Observable from 'zen-observable-ts';\nimport {\n\tAmplify,\n\tConsoleLogger as Logger,\n\tCredentials,\n\tgetAmplifyUserAgent,\n\tINTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,\n} from '@aws-amplify/core';\nimport PubSub from '@aws-amplify/pubsub';\nimport Auth from '@aws-amplify/auth';\nimport Cache from '@aws-amplify/cache';\nimport {\n\tGraphQLAuthError,\n\tGraphQLOptions,\n\tGraphQLResult,\n\tGraphQLOperation,\n} from './types';\nimport { RestClient } from '@aws-amplify/api-rest';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\n\nconst logger = new Logger('GraphQLAPI');\n\nexport const graphqlOperation = (\n\tquery,\n\tvariables = {},\n\tauthToken?: string,\n\tuserAgentSuffix?: string\n) => ({\n\tquery,\n\tvariables,\n\tauthToken,\n\tuserAgentSuffix,\n});\n\n/**\n * Export Cloud Logic APIs\n */\nexport class GraphQLAPIClass {\n\t/**\n\t * @private\n\t */\n\tprivate _options;\n\tprivate _api = null;\n\n\tAuth = Auth;\n\tCache = Cache;\n\tCredentials = Credentials;\n\n\t/**\n\t * Initialize GraphQL API with AWS configuration\n\t * @param {Object} options - Configuration object for API\n\t */\n\tconstructor(options) {\n\t\tthis._options = options;\n\t\tlogger.debug('API Options', this._options);\n\t}\n\n\tpublic getModuleName() {\n\t\treturn 'GraphQLAPI';\n\t}\n\n\t/**\n\t * Configure API\n\t * @param {Object} config - Configuration of the API\n\t * @return {Object} - The current configuration\n\t */\n\tconfigure(options) {\n\t\tconst { API = {}, ...otherOptions } = options || {};\n\t\tlet opt = { ...otherOptions, ...API };\n\t\tlogger.debug('configure GraphQL API', { opt });\n\n\t\tif (opt['aws_project_region']) {\n\t\t\topt = Object.assign({}, opt, {\n\t\t\t\tregion: opt['aws_project_region'],\n\t\t\t\theader: {},\n\t\t\t});\n\t\t}\n\n\t\tif (\n\t\t\ttypeof opt.graphql_headers !== 'undefined' &&\n\t\t\ttypeof opt.graphql_headers !== 'function'\n\t\t) {\n\t\t\tlogger.warn('graphql_headers should be a function');\n\t\t\topt.graphql_headers = undefined;\n\t\t}\n\n\t\tthis._options = Object.assign({}, this._options, opt);\n\n\t\tthis.createInstance();\n\n\t\treturn this._options;\n\t}\n\n\t/**\n\t * Create an instance of API for the library\n\t * @return - A promise of true if Success\n\t */\n\tcreateInstance() {\n\t\tlogger.debug('create Rest instance');\n\t\tif (this._options) {\n\t\t\tthis._api = new RestClient(this._options);\n\t\t\t// Share instance Credentials with client for SSR\n\t\t\tthis._api.Credentials = this.Credentials;\n\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn Promise.reject('API not configured');\n\t\t}\n\t}\n\n\tprivate async _headerBasedAuth(\n\t\tdefaultAuthenticationType?,\n\t\tadditionalHeaders: { [key: string]: string } = {}\n\t) {\n\t\tconst { aws_appsync_authenticationType, aws_appsync_apiKey: apiKey } =\n\t\t\tthis._options;\n\t\tconst authenticationType =\n\t\t\tdefaultAuthenticationType || aws_appsync_authenticationType || 'AWS_IAM';\n\t\tlet headers = {};\n\n\t\tswitch (authenticationType) {\n\t\t\tcase 'API_KEY':\n\t\t\t\tif (!apiKey) {\n\t\t\t\t\tthrow new Error(GraphQLAuthError.NO_API_KEY);\n\t\t\t\t}\n\t\t\t\theaders = {\n\t\t\t\t\tAuthorization: null,\n\t\t\t\t\t'X-Api-Key': apiKey,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase 'AWS_IAM':\n\t\t\t\tconst credentialsOK = await this._ensureCredentials();\n\t\t\t\tif (!credentialsOK) {\n\t\t\t\t\tthrow new Error(GraphQLAuthError.NO_CREDENTIALS);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'OPENID_CONNECT':\n\t\t\t\ttry {\n\t\t\t\t\tlet token;\n\t\t\t\t\t// backwards compatibility\n\t\t\t\t\tconst federatedInfo = await Cache.getItem('federatedInfo');\n\t\t\t\t\tif (federatedInfo) {\n\t\t\t\t\t\ttoken = federatedInfo.token;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst currentUser = await Auth.currentAuthenticatedUser();\n\t\t\t\t\t\tif (currentUser) {\n\t\t\t\t\t\t\ttoken = currentUser.token;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!token) {\n\t\t\t\t\t\tthrow new Error(GraphQLAuthError.NO_FEDERATED_JWT);\n\t\t\t\t\t}\n\t\t\t\t\theaders = {\n\t\t\t\t\t\tAuthorization: token,\n\t\t\t\t\t};\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthrow new Error(GraphQLAuthError.NO_CURRENT_USER);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'AMAZON_COGNITO_USER_POOLS':\n\t\t\t\ttry {\n\t\t\t\t\tconst session = await this.Auth.currentSession();\n\t\t\t\t\theaders = {\n\t\t\t\t\t\tAuthorization: session.getAccessToken().getJwtToken(),\n\t\t\t\t\t};\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthrow new Error(GraphQLAuthError.NO_CURRENT_USER);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'AWS_LAMBDA':\n\t\t\t\tif (!additionalHeaders.Authorization) {\n\t\t\t\t\tthrow new Error(GraphQLAuthError.NO_AUTH_TOKEN);\n\t\t\t\t}\n\t\t\t\theaders = {\n\t\t\t\t\tAuthorization: additionalHeaders.Authorization,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\theaders = {\n\t\t\t\t\tAuthorization: null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t}\n\n\t\treturn headers;\n\t}\n\n\t/**\n\t * to get the operation type\n\t * @param operation\n\t */\n\tgetGraphqlOperationType(operation: GraphQLOperation): OperationTypeNode {\n\t\tconst doc = parse(operation);\n\t\tconst definitions =\n\t\t\tdoc.definitions as ReadonlyArray;\n\t\tconst [{ operation: operationType }] = definitions;\n\n\t\treturn operationType;\n\t}\n\n\t/**\n\t * Executes a GraphQL operation\n\t *\n\t * @param options - GraphQL Options\n\t * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config\n\t * @returns An Observable if the query is a subscription query, else a promise of the graphql result.\n\t */\n\tgraphql(\n\t\t{\n\t\t\tquery: paramQuery,\n\t\t\tvariables = {},\n\t\t\tauthMode,\n\t\t\tauthToken,\n\t\t\tuserAgentSuffix,\n\t\t}: GraphQLOptions,\n\t\tadditionalHeaders?: { [key: string]: string }\n\t): Observable> | Promise> {\n\t\tconst query =\n\t\t\ttypeof paramQuery === 'string'\n\t\t\t\t? parse(paramQuery)\n\t\t\t\t: parse(print(paramQuery));\n\n\t\tconst [operationDef = {}] = query.definitions.filter(\n\t\t\tdef => def.kind === 'OperationDefinition'\n\t\t);\n\t\tconst { operation: operationType } =\n\t\t\toperationDef as OperationDefinitionNode;\n\n\t\tconst headers = additionalHeaders || {};\n\n\t\t// if an authorization header is set, have the explicit authToken take precedence\n\t\tif (authToken) {\n\t\t\theaders.Authorization = authToken;\n\t\t}\n\n\t\tswitch (operationType) {\n\t\t\tcase 'query':\n\t\t\tcase 'mutation':\n\t\t\t\tconst cancellableToken = this._api.getCancellableToken();\n\t\t\t\tconst initParams = { cancellableToken };\n\t\t\t\tconst responsePromise = this._graphql(\n\t\t\t\t\t{ query, variables, authMode, userAgentSuffix },\n\t\t\t\t\theaders,\n\t\t\t\t\tinitParams\n\t\t\t\t);\n\t\t\t\tthis._api.updateRequestToBeCancellable(\n\t\t\t\t\tresponsePromise,\n\t\t\t\t\tcancellableToken\n\t\t\t\t);\n\t\t\t\treturn responsePromise;\n\t\t\tcase 'subscription':\n\t\t\t\treturn this._graphqlSubscribe({ query, variables, authMode }, headers);\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`invalid operation type: ${operationType}`);\n\t\t}\n\t}\n\n\tprivate async _graphql(\n\t\t{ query, variables, authMode, userAgentSuffix }: GraphQLOptions,\n\t\tadditionalHeaders = {},\n\t\tinitParams = {}\n\t): Promise> {\n\t\tif (!this._api) {\n\t\t\tawait this.createInstance();\n\t\t}\n\n\t\tconst {\n\t\t\taws_appsync_region: region,\n\t\t\taws_appsync_graphqlEndpoint: appSyncGraphqlEndpoint,\n\t\t\tgraphql_headers = () => ({}),\n\t\t\tgraphql_endpoint: customGraphqlEndpoint,\n\t\t\tgraphql_endpoint_iam_region: customEndpointRegion,\n\t\t} = this._options;\n\n\t\tconst headers = {\n\t\t\t...(!customGraphqlEndpoint &&\n\t\t\t\t(await this._headerBasedAuth(authMode, additionalHeaders))),\n\t\t\t...(customGraphqlEndpoint &&\n\t\t\t\t(customEndpointRegion\n\t\t\t\t\t? await this._headerBasedAuth(authMode, additionalHeaders)\n\t\t\t\t\t: { Authorization: null })),\n\t\t\t...(await graphql_headers({ query, variables })),\n\t\t\t...additionalHeaders,\n\t\t\t...(!customGraphqlEndpoint && {\n\t\t\t\t[USER_AGENT_HEADER]: getAmplifyUserAgent(userAgentSuffix),\n\t\t\t}),\n\t\t};\n\n\t\tconst body = {\n\t\t\tquery: print(query as DocumentNode),\n\t\t\tvariables,\n\t\t};\n\n\t\tconst init = Object.assign(\n\t\t\t{\n\t\t\t\theaders,\n\t\t\t\tbody,\n\t\t\t\tsignerServiceInfo: {\n\t\t\t\t\tservice: !customGraphqlEndpoint ? 'appsync' : 'execute-api',\n\t\t\t\t\tregion: !customGraphqlEndpoint ? region : customEndpointRegion,\n\t\t\t\t},\n\t\t\t},\n\t\t\tinitParams\n\t\t);\n\n\t\tconst endpoint = customGraphqlEndpoint || appSyncGraphqlEndpoint;\n\n\t\tif (!endpoint) {\n\t\t\tconst error = new GraphQLError('No graphql endpoint provided.');\n\n\t\t\tthrow {\n\t\t\t\tdata: {},\n\t\t\t\terrors: [error],\n\t\t\t};\n\t\t}\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await this._api.post(endpoint, init);\n\t\t} catch (err) {\n\t\t\t// If the exception is because user intentionally\n\t\t\t// cancelled the request, do not modify the exception\n\t\t\t// so that clients can identify the exception correctly.\n\t\t\tif (this._api.isCancel(err)) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tresponse = {\n\t\t\t\tdata: {},\n\t\t\t\terrors: [new GraphQLError(err.message, null, null, null, null, err)],\n\t\t\t};\n\t\t}\n\n\t\tconst { errors } = response;\n\n\t\tif (errors && errors.length) {\n\t\t\tthrow response;\n\t\t}\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Checks to see if an error thrown is from an api request cancellation\n\t * @param {any} error - Any error\n\t * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n\t */\n\tisCancel(error) {\n\t\treturn this._api.isCancel(error);\n\t}\n\n\t/**\n\t * Cancels an inflight request. Only applicable for graphql queries and mutations\n\t * @param {any} request - request to cancel\n\t * @return {boolean} - A boolean indicating if the request was cancelled\n\t */\n\tcancel(request: Promise, message?: string) {\n\t\treturn this._api.cancel(request, message);\n\t}\n\n\t/**\n\t * Check if the request has a corresponding cancel token in the WeakMap.\n\t * @params request - The request promise\n\t * @return if the request has a corresponding cancel token.\n\t */\n\thasCancelToken(request: Promise) {\n\t\treturn this._api.hasCancelToken(request);\n\t}\n\n\tprivate _graphqlSubscribe(\n\t\t{\n\t\t\tquery,\n\t\t\tvariables,\n\t\t\tauthMode: defaultAuthenticationType,\n\t\t\tauthToken,\n\t\t}: GraphQLOptions,\n\t\tadditionalHeaders = {}\n\t): Observable {\n\t\tconst {\n\t\t\taws_appsync_region: region,\n\t\t\taws_appsync_graphqlEndpoint: appSyncGraphqlEndpoint,\n\t\t\taws_appsync_authenticationType,\n\t\t\taws_appsync_apiKey: apiKey,\n\t\t\tgraphql_headers = () => ({}),\n\t\t} = this._options;\n\t\tconst authenticationType =\n\t\t\tdefaultAuthenticationType || aws_appsync_authenticationType || 'AWS_IAM';\n\n\t\tif (PubSub && typeof PubSub.subscribe === 'function') {\n\t\t\treturn PubSub.subscribe('', {\n\t\t\t\tprovider: INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,\n\t\t\t\tappSyncGraphqlEndpoint,\n\t\t\t\tauthenticationType,\n\t\t\t\tapiKey,\n\t\t\t\tquery: print(query as DocumentNode),\n\t\t\t\tregion,\n\t\t\t\tvariables,\n\t\t\t\tgraphql_headers,\n\t\t\t\tadditionalHeaders,\n\t\t\t\tauthToken,\n\t\t\t});\n\t\t} else {\n\t\t\tlogger.debug('No pubsub module applied for subscription');\n\t\t\tthrow new Error('No pubsub module applied for subscription');\n\t\t}\n\t}\n\n\t/**\n\t * @private\n\t */\n\t_ensureCredentials() {\n\t\treturn this.Credentials.get()\n\t\t\t.then(credentials => {\n\t\t\t\tif (!credentials) return false;\n\t\t\t\tconst cred = this.Credentials.shear(credentials);\n\t\t\t\tlogger.debug('set credentials for api', cred);\n\n\t\t\t\treturn true;\n\t\t\t})\n\t\t\t.catch(err => {\n\t\t\t\tlogger.warn('ensure credentials error', err);\n\t\t\t\treturn false;\n\t\t\t});\n\t}\n}\n\nexport const GraphQLAPI = new GraphQLAPIClass(null);\nAmplify.register(GraphQLAPI);\n","/*\n * Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with\n * the License. A copy of the License is located at\n *\n * http://aws.amazon.com/apache2.0/\n *\n * or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\n * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions\n * and limitations under the License.\n */\nimport { Auth } from '@aws-amplify/auth';\nimport Cache from '@aws-amplify/cache';\nimport { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';\nimport { RestAPIClass } from '@aws-amplify/api-rest';\nimport {\n\tGraphQLAPIClass,\n\tGraphQLOptions,\n\tGraphQLResult,\n\tGraphQLOperation,\n\tOperationTypeNode,\n} from '@aws-amplify/api-graphql';\nimport {\n\tAmplify,\n\tConsoleLogger as Logger,\n\tCredentials,\n} from '@aws-amplify/core';\nimport Observable from 'zen-observable-ts';\nimport { GraphQLQuery, GraphQLSubscription } from './types';\n\nconst logger = new Logger('API');\n/**\n * @deprecated\n * Use RestApi or GraphQLAPI to reduce your application bundle size\n * Export Cloud Logic APIs\n */\nexport class APIClass {\n\t/**\n\t * Initialize API with AWS configuration\n\t * @param {Object} options - Configuration object for API\n\t */\n\tprivate _options;\n\tprivate _restApi: RestAPIClass;\n\tprivate _graphqlApi: GraphQLAPIClass;\n\n\tAuth = Auth;\n\tCache = Cache;\n\tCredentials = Credentials;\n\n\t/**\n\t * Initialize API with AWS configuration\n\t * @param {Object} options - Configuration object for API\n\t */\n\tconstructor(options) {\n\t\tthis._options = options;\n\t\tthis._restApi = new RestAPIClass(options);\n\t\tthis._graphqlApi = new GraphQLAPIClass(options);\n\t\tlogger.debug('API Options', this._options);\n\t}\n\n\tpublic getModuleName() {\n\t\treturn 'API';\n\t}\n\n\t/**\n\t * Configure API part with aws configurations\n\t * @param {Object} config - Configuration of the API\n\t * @return {Object} - The current configuration\n\t */\n\tconfigure(options) {\n\t\tthis._options = Object.assign({}, this._options, options);\n\n\t\t// Share Amplify instance with client for SSR\n\t\tthis._restApi.Credentials = this.Credentials;\n\n\t\tthis._graphqlApi.Auth = this.Auth;\n\t\tthis._graphqlApi.Cache = this.Cache;\n\t\tthis._graphqlApi.Credentials = this.Credentials;\n\n\t\tconst restAPIConfig = this._restApi.configure(this._options);\n\t\tconst graphQLAPIConfig = this._graphqlApi.configure(this._options);\n\n\t\treturn { ...restAPIConfig, ...graphQLAPIConfig };\n\t}\n\n\t/**\n\t * Make a GET request\n\t * @param apiName - The api name of the request\n\t * @param path - The path of the request\n\t * @param [init] - Request extra params\n\t * @return A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tget(\n\t\tapiName: string,\n\t\tpath: string,\n\t\tinit: { [key: string]: any }\n\t): Promise {\n\t\treturn this._restApi.get(apiName, path, init);\n\t}\n\n\t/**\n\t * Make a POST request\n\t * @param apiName - The api name of the request\n\t * @param path - The path of the request\n\t * @param [init] - Request extra params\n\t * @return A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tpost(\n\t\tapiName: string,\n\t\tpath: string,\n\t\tinit: { [key: string]: any }\n\t): Promise {\n\t\treturn this._restApi.post(apiName, path, init);\n\t}\n\n\t/**\n\t * Make a PUT request\n\t * @param apiName - The api name of the request\n\t * @param path - The path of the request\n\t * @param [init] - Request extra params\n\t * @return A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tput(\n\t\tapiName: string,\n\t\tpath: string,\n\t\tinit: { [key: string]: any }\n\t): Promise {\n\t\treturn this._restApi.put(apiName, path, init);\n\t}\n\n\t/**\n\t * Make a PATCH request\n\t * @param apiName - The api name of the request\n\t * @param path - The path of the request\n\t * @param [init] - Request extra params\n\t * @return A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tpatch(\n\t\tapiName: string,\n\t\tpath: string,\n\t\tinit: { [key: string]: any }\n\t): Promise {\n\t\treturn this._restApi.patch(apiName, path, init);\n\t}\n\n\t/**\n\t * Make a DEL request\n\t * @param apiName - The api name of the request\n\t * @param path - The path of the request\n\t * @param [init] - Request extra params\n\t * @return A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\tdel(\n\t\tapiName: string,\n\t\tpath: string,\n\t\tinit: { [key: string]: any }\n\t): Promise {\n\t\treturn this._restApi.del(apiName, path, init);\n\t}\n\n\t/**\n\t * Make a HEAD request\n\t * @param apiName - The api name of the request\n\t * @param path - The path of the request\n\t * @param [init] - Request extra params\n\t * @return A promise that resolves to an object with response status and JSON data, if successful.\n\t */\n\thead(\n\t\tapiName: string,\n\t\tpath: string,\n\t\tinit: { [key: string]: any }\n\t): Promise {\n\t\treturn this._restApi.head(apiName, path, init);\n\t}\n\n\t/**\n\t * Checks to see if an error thrown is from an api request cancellation\n\t * @param error - Any error\n\t * @return If the error was from an api request cancellation\n\t */\n\tisCancel(error: any): boolean {\n\t\treturn this._restApi.isCancel(error);\n\t}\n\t/**\n\t * Cancels an inflight request for either a GraphQL request or a Rest API request.\n\t * @param request - request to cancel\n\t * @param [message] - custom error message\n\t * @return If the request was cancelled\n\t */\n\tcancel(request: Promise, message?: string): boolean {\n\t\tif (this._restApi.hasCancelToken(request)) {\n\t\t\treturn this._restApi.cancel(request, message);\n\t\t} else if (this._graphqlApi.hasCancelToken(request)) {\n\t\t\treturn this._graphqlApi.cancel(request, message);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Getting endpoint for API\n\t * @param apiName - The name of the api\n\t * @return The endpoint of the api\n\t */\n\tasync endpoint(apiName: string): Promise {\n\t\treturn this._restApi.endpoint(apiName);\n\t}\n\n\t/**\n\t * to get the operation type\n\t * @param operation\n\t */\n\tgetGraphqlOperationType(operation: GraphQLOperation): OperationTypeNode {\n\t\treturn this._graphqlApi.getGraphqlOperationType(operation);\n\t}\n\n\t/**\n\t * Executes a GraphQL operation\n\t *\n\t * @param options - GraphQL Options\n\t * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config\n\t * @returns An Observable if queryType is 'subscription', else a promise of the graphql result from the query.\n\t */\n\tgraphql(\n\t\toptions: GraphQLOptions,\n\t\tadditionalHeaders?: { [key: string]: string }\n\t): T extends GraphQLQuery\n\t\t? Promise>\n\t\t: T extends GraphQLSubscription\n\t\t? Observable<{\n\t\t\t\tprovider: AWSAppSyncRealTimeProvider;\n\t\t\t\tvalue: GraphQLResult;\n\t\t }>\n\t\t: Promise> | Observable