/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/webpack-graphql-loader@1.0.2/lib/loader.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var __assign=this&&this.__assign||Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var a in r=arguments[t])Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},__awaiter=this&&this.__awaiter||function(e,r,t,n){return new(t||(t=Promise))((function(a,i){function s(e){try{c(n.next(e))}catch(e){i(e)}}function o(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){e.done?a(e.value):new t((function(r){r(e.value)})).then(s,o)}c((n=n.apply(e,r||[])).next())}))},__generator=this&&this.__generator||function(e,r){var t,n,a,i,s={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return i={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function o(i){return function(o){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,n&&(a=n[2&i[0]?"return":i[0]?"throw":"next"])&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[0,a.value]),i[0]){case 0:case 1:a=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(a=s.trys,(a=a.length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){s.label=i[1];break}if(6===i[0]&&s.label<a[1]){s.label=a[1],a=i;break}if(a&&s.label<a[2]){s.label=a[2],s.ops.push(i);break}a[2]&&s.ops.pop(),s.trys.pop();continue}i=r.call(e,s)}catch(e){i=[6,e],n=0}finally{t=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,o])}}};exports.__esModule=!0;var printer_1=require("graphql/language/printer"),parser_1=require("graphql/language/parser"),validate_1=require("graphql/validation/validate"),path_1=require("path"),fs_1=require("fs"),transforms_1=require("./transforms"),graphql_1=require("graphql"),pify=require("pify"),loaderUtils=require("loader-utils"),codegen_1=require("./codegen"),cachedSchemas={};function readFile(e,r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:return[4,pify(e.fs.readFile.bind(e.fs))(r)];case 1:return[2,t.sent().toString()]}}))}))}function stat(e,r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,pify(e.fs.stat.bind(e.fs))(r)]}))}))}function extractImports(e,r,t,n){return __awaiter(this,void 0,void 0,(function(){var a,i,s,o,c,u,l=this;return __generator(this,(function(f){switch(f.label){case 0:return a=t.split(/(\r\n|\r|\n)/),pify(e.resolve),i=[],a.forEach((function(t){if("#"===t[0]){var n=t.slice(1).split(" ");if("import"===n[0]){var a=n[1]&&n[1].match(/^[\"\'](.+)[\"\']/);if(!a||!a.length)throw new Error("#import statement must specify a quoted file path");var s=a[1];i.push(new Promise((function(t,n){e.resolve(r,s,(function(r,a){r?n(r):(e.addDependency(a),t(a))}))})))}}})),[4,Promise.all(i)];case 1:return s=f.sent(),[4,Promise.all(s.map((function(r){return __awaiter(l,void 0,void 0,(function(){var t;return __generator(this,(function(n){switch(n.label){case 0:return t=[path_1.dirname(r)],[4,readFile(e,r)];case 1:return[2,t.concat([n.sent()])]}}))}))})))];case 2:return o=f.sent(),[4,Promise.all(o.map((function(r){var t=r[0],n=r[1];return loadSource(e,t,n)})))];case 3:return c=f.sent(),u=c.reduce((function(e,r){return e.push.apply(e,r.definitions),e}),[]),n.definitions=n.definitions.concat(u),[2,n]}}))}))}function loadSource(e,r,t){return __awaiter(this,void 0,void 0,(function(){var n;return __generator(this,(function(a){switch(a.label){case 0:return n=parser_1.parse(new graphql_1.Source(t,"GraphQL/file")),[4,extractImports(e,r,t,n)];case 1:return[2,n=a.sent()]}}))}))}function loadSchema(e,r){return __awaiter(this,void 0,void 0,(function(){var t,n,a,i,s;return __generator(this,(function(o){switch(o.label){case 0:return t=null,r.schema?(pify(e.resolve),[4,findFileInTree(e,e.context,r.schema)]):[3,4];case 1:return n=o.sent(),e.addDependency(n),[4,stat(e,n)];case 2:return a=o.sent(),i=a.mtime.getTime(),[4,readFile(e,n)];case 3:if(s=o.sent(),cachedSchemas[n]&&i<=cachedSchemas[n].mtime)return[2,cachedSchemas[n].schema];t=graphql_1.buildClientSchema(JSON.parse(s)),cachedSchemas[n]={schema:t,mtime:i},o.label=4;case 4:if(!t)throw new Error("schema option must be passed if validate is true");return[2,t]}}))}))}function loadOptions(e){return __awaiter(this,void 0,void 0,(function(){var r,t;return __generator(this,(function(n){switch(n.label){case 0:return r=__assign({},loaderUtils.getOptions(e)),t=void 0,r.validate?[4,loadSchema(e,r)]:[3,2];case 1:t=n.sent(),n.label=2;case 2:return[2,{schema:t,output:r.output&&"string"!==r.output?"document":"string",removeUnusedFragments:r.removeUnusedFragments,minify:r.minify,codegen:r.codegen,emitDefaultExport:r.emitDefaultExport}]}}))}))}function findFileInTree(e,r,t){return __awaiter(this,void 0,void 0,(function(){var n,a,i;return __generator(this,(function(s){switch(s.label){case 0:n=r,s.label=1;case 1:0,a=path_1.join(n,t),s.label=2;case 2:return s.trys.push([2,4,,5]),[4,stat(e,a)];case 3:return s.sent().isFile()?[2,a]:[3,5];case 4:return s.sent(),[3,5];case 5:if((i=path_1.dirname(n))===n)throw new Error("Could not find schema file '"+t+" from any parent of '"+r+"'");return n=i,[3,1];case 6:return[2]}}))}))}function loader(e){return __awaiter(this,void 0,void 0,(function(){var r,t,n,a,i,s,o,c,u,l,f=this;return __generator(this,(function(h){switch(h.label){case 0:if(this.cacheable(),!(r=this.async()))throw new Error("Loader does not support synchronous processing");t=[],h.label=1;case 1:return h.trys.push([1,6,,7]),[4,loadOptions(this)];case 2:return n=h.sent(),[4,loadSource(this,this.context,e)];case 3:if(a=h.sent(),i=null,n.codegen&&n.codegen.typescript){if(!n.schema)throw new Error("schema option must be passed if codegen is specified");i=codegen_1.default(n.schema,a)}return transforms_1.removeDuplicateFragments(a),transforms_1.removeSourceLocations(a),n.removeUnusedFragments&&transforms_1.removeUnusedFragments(a),n.schema&&(t=validate_1.validate(n.schema,a)).length>0&&t.forEach((function(e){return f.emitError(e)})),s=JSON.stringify("document"===n.output?a:printer_1.print(a)),o="string"===n.output&&n.minify?minifyDocumentString(s):s,c=n.emitDefaultExport?"export default ":"module.exports = ",u=""+c+o,i?(u="const documentOutput = "+o+";\n"+i[0]+"\n"+c+"spec;",[4,pify(fs_1.writeFile)(this.resourcePath+".d.ts",i[1])]):[3,5];case 4:h.sent(),h.label=5;case 5:return r(null,u),[3,7];case 6:return l=h.sent(),r(l),[3,7];case 7:return[2]}}))}))}function minifyDocumentString(e){return e.replace(/#.*/g,"").replace(/\\n/g," ").replace(/\s\s+/g," ").replace(/\s*({|}|\(|\)|\.|:|,)\s*/g,"$1")}exports.default=loader;var transforms_2=require("./transforms");exports.removeDuplicateFragments=transforms_2.removeDuplicateFragments,exports.removeSourceLocations=transforms_2.removeSourceLocations,exports.removeUnusedFragments=transforms_2.removeUnusedFragments;
//# sourceMappingURL=/sm/88d1aa96b38aa4b8470d50cf3a7f668d9da751b189ace0b86959f6cf6e281985.map