{"version":3,"sources":["jsdelivr-header.js","/npm/@gridsome/source-graphql@0.1.0/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,WAAE,YAAe,QAAQ,wBACzB,SAAE,UAAa,QAAQ,oBACvB,MAAQ,QAAQ,eAEhB,iBACJ,iBAAgB,2BAChB,2BAA0B,gBAC1B,gBAAe,YACf,aACE,QAAQ,kBAEN,6BACJ,6BAA4B,uBAC5B,wBACE,QAAQ,gBAEZ,MAAM,cACJ,qBAAO,GACL,MAAO,CACL,SAAK,EACL,eAAW,EACX,cAAU,EACV,QAAS,CAAC,EAEd,CAEA,WAAA,CAAa,EAAK,GAChB,MAAM,IAAE,EAAG,UAAE,EAAS,QAAE,GAAY,EACpC,IAAI,EAAW,EAAQ,SAIvB,IAAK,EACH,MAAM,IAAI,MAAM,uBAGlB,IAAK,EACH,MAAM,IAAI,MAAM,6BAKb,IACH,EAAW,GAIb,EAAI,cAAa,OAAS,gBACxB,MAAM,QAAqB,KAAK,0BAA0B,EAAK,GAO/D,QAN+B,KAAK,gBAClC,EACA,EACA,GAGwB,GAE9B,CAEA,+BAAM,CAA2B,EAAK,GACpC,MAAM,EAAO,IAAI,SAAS,CAAE,MAAK,cAC3B,EAAO,YAAW,KAAM,CAAG,cAAY,OAAO,GAC9C,QAAqB,iBAAiB,GAE5C,OAAO,2BAA2B,CAChC,OAAQ,EACR,QAEJ,CAEA,eAAA,CAAiB,EAAQ,EAAW,GAClC,OAAO,gBAAgB,EAAQ,CAC7B,IAAI,uBACJ,IAAI,aAAY,GAAQ,GAAG,KAAY,MACvC,IAAI,6BAA6B,EAAU,IAE/C,EAGF,OAAO,QAAU","file":"/npm/@gridsome/source-graphql@0.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@gridsome/source-graphql@0.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const { setContext } = require('apollo-link-context')\nconst { HttpLink } = require('apollo-link-http')\nconst fetch = require('node-fetch')\n\nconst {\n  introspectSchema,\n  makeRemoteExecutableSchema,\n  transformSchema,\n  RenameTypes\n} = require('graphql-tools')\n\nconst {\n  NamespaceUnderFieldTransform,\n  StripNonQueryTransform\n} = require(`./transforms`)\n\nclass GraphQLSource {\n  static defaultOptions () {\n    return {\n      url: undefined,\n      fieldName: undefined,\n      typeName: undefined,\n      headers: {}\n    }\n  }\n\n  constructor (api, options) {\n    const { url, fieldName, headers } = options\n    let typeName = options.typeName\n\n    // Make sure all required props are passed\n\n    if (!url) {\n      throw new Error(`Missing url option.`)\n    }\n\n    if (!fieldName) {\n      throw new Error(`Missing fieldName option.`)\n    }\n\n    // If typeName isn't defined, default to fieldName\n\n    if (!typeName) {\n      typeName = fieldName\n    }\n\n    // Fetch schema, namespace it, and merge it into local schema\n    api.createSchema(async ({ addSchema }) => {\n      const remoteSchema = await this.getRemoteExecutableSchema(url, headers)\n      const namespacedSchema = await this.namespaceSchema(\n        remoteSchema,\n        fieldName,\n        typeName\n      )\n\n      addSchema(namespacedSchema)\n    })\n  }\n\n  async getRemoteExecutableSchema (uri, headers) {\n    const http = new HttpLink({ uri, fetch })\n    const link = setContext(() => ({ headers })).concat(http)\n    const remoteSchema = await introspectSchema(link)\n\n    return makeRemoteExecutableSchema({\n      schema: remoteSchema,\n      link\n    })\n  }\n\n  namespaceSchema (schema, fieldName, typeName) {\n    return transformSchema(schema, [\n      new StripNonQueryTransform(),\n      new RenameTypes(name => `${typeName}_${name}`),\n      new NamespaceUnderFieldTransform(typeName, fieldName)\n    ])\n  }\n}\n\nmodule.exports = GraphQLSource\n"]}