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B,CAAC,IAGtB,IAAK,MAAM,KAAe,EACxB,EAAe,cAAc,EAAY,EAAe,QAE5D,EAEI,EAAK,WACP,EAAe,gBAAgB,EAAK,WAGlC,EAAK,SACP,EAAe,cAAc,EAAK,SAGhC,EAAK,kBACP,EAAe,gBAAgB,EAAK,iBA0HxC,GAAG,CACD,KAAM,YACN,QAAS,UAGX,OAAO,eAAiB,eACxB,OAAO,sBAAwB,sBAC/B,OAAO,uBAAyB,uBAChC,OAAO,sBAAwB,sBAC/B,OAAO,WAAa,WAEpB,OAAO,QAAU","file":"/npm/mercurius-temp-dante@6.5.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/mercurius-temp-dante@6.5.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","'use strict'\n\nconst fp = require('fastify-plugin')\nconst LRU = require('tiny-lru')\nconst routes = require('./lib/routes')\nconst { compileQuery } = require('graphql-jit')\nconst { Factory } = require('single-user-cache')\nconst {\n  parse,\n  buildSchema,\n  getOperationAST,\n  GraphQLObjectType,\n  GraphQLScalarType,\n  GraphQLEnumType,\n  GraphQLInterfaceType,\n  GraphQLUnionType,\n  GraphQLSchema,\n  extendSchema,\n  validate,\n  validateSchema,\n  specifiedRules,\n  execute\n} = require('graphql')\nconst { buildExecutionContext } = require('graphql/execution/execute')\nconst queryDepth = require('./lib/queryDepth')\nconst buildFederationSchema = require('./lib/federation')\nconst buildGateway = require('./lib/gateway')\nconst mq = require('mqemitter')\nconst { PubSub, withFilter } = require('./lib/subscriber')\nconst persistedQueryDefaults = require('./lib/persistedQueryDefaults')\nconst {\n  ErrorWithProps,\n  defaultErrorFormatter,\n  MER_ERR_GQL_INVALID_SCHEMA,\n  MER_ERR_GQL_GATEWAY,\n  MER_ERR_GQL_VALIDATION,\n  MER_ERR_INVALID_OPTS,\n  MER_ERR_METHOD_NOT_ALLOWED,\n  MER_ERR_INVALID_METHOD\n} = require('./lib/errors')\n\nconst kLoaders = Symbol('mercurius.loaders')\nconst kFactory = Symbol('mercurius.loadersFactory')\n\nfunction buildCache (opts) {\n  if (Object.prototype.hasOwnProperty.call(opts, 'cache')) {\n    const isBoolean = typeof opts.cache === 'boolean'\n    const isNumber = typeof opts.cache === 'number'\n\n    if (isBoolean && opts.cache === false) {\n      // no cache\n      return null\n    } else if (isNumber) {\n      // cache size as specified\n      return LRU(opts.cache)\n    } else if (!isBoolean && !isNumber) {\n      throw new MER_ERR_INVALID_OPTS('Cache type is not supported')\n    }\n  }\n\n  // default cache, 1024 entries\n  return LRU(1024)\n}\n\nconst plugin = fp(async function (app, opts) {\n  const lru = buildCache(opts)\n  const lruErrors = buildCache(opts)\n  const lruGatewayResolvers = buildCache(opts)\n\n  const minJit = opts.jit || 0\n  const queryDepthLimit = opts.queryDepth\n  const errorFormatter = typeof opts.errorFormatter === 'function' ? opts.errorFormatter : defaultErrorFormatter\n\n  if (opts.persistedQueries) {\n    if (opts.onlyPersisted) {\n      opts.persistedQueryProvider = persistedQueryDefaults.preparedOnly(opts.persistedQueries)\n\n      // Disable GraphiQL and GraphQL Playground\n      opts.graphiql = false\n      opts.ide = false\n    } else {\n      opts.persistedQueryProvider = persistedQueryDefaults.prepared(opts.persistedQueries)\n    }\n  } else if (opts.onlyPersisted) {\n    throw new MER_ERR_INVALID_OPTS('onlyPersisted is true but there are no persistedQueries')\n  }\n\n  if (opts.persistedQueryProvider) {\n    if (opts.persistedQueryProvider.getHash) {\n      if (!opts.persistedQueryProvider.getQueryFromHash) {\n        throw new MER_ERR_INVALID_OPTS('persistedQueryProvider: getQueryFromHash is required when getHash is provided')\n      }\n    } else {\n      throw new MER_ERR_INVALID_OPTS('persistedQueryProvider: getHash is required')\n    }\n\n    if (opts.persistedQueryProvider.getHashForQuery) {\n      if (!opts.persistedQueryProvider.saveQuery) {\n        throw new MER_ERR_INVALID_OPTS('persistedQueryProvider: saveQuery is required when getHashForQuery is provided')\n      }\n    }\n  }\n\n  if (typeof minJit !== 'number') {\n    throw new MER_ERR_INVALID_OPTS('the jit option must be a number')\n  }\n\n  const root = {}\n  let schema = opts.schema\n  let gateway = opts.gateway\n  const subscriptionOpts = opts.subscription\n  let emitter\n\n  let subscriber\n  let verifyClient\n  let subscriptionContextFn\n  let onConnect\n\n  if (typeof subscriptionOpts === 'object') {\n    if (subscriptionOpts.pubsub) {\n      subscriber = subscriptionOpts.pubsub\n    } else {\n      emitter = subscriptionOpts.emitter || mq()\n      subscriber = new PubSub(emitter)\n    }\n    verifyClient = subscriptionOpts.verifyClient\n    subscriptionContextFn = subscriptionOpts.context\n    onConnect = subscriptionOpts.onConnect\n  } else if (subscriptionOpts === true) {\n    emitter = mq()\n    subscriber = new PubSub(emitter)\n  }\n\n  if (subscriptionOpts) {\n    fastifyGraphQl.pubsub = subscriber\n  }\n\n  if (gateway && (schema || opts.resolvers || opts.loaders)) {\n    throw new MER_ERR_INVALID_OPTS('Adding \"schema\", \"resolvers\" or \"loaders\" to plugin options when plugin is running in gateway mode is not allowed')\n  }\n\n  if (Array.isArray(schema)) {\n    schema = schema.join('\\n')\n  }\n\n  if (typeof schema === 'string') {\n    if (opts.federationMetadata) {\n      schema = buildFederationSchema(schema)\n    } else {\n      schema = buildSchema(schema)\n    }\n  } else if (!opts.schema && !gateway) {\n    schema = new GraphQLSchema({\n      query: new GraphQLObjectType({\n        name: 'Query',\n        fields: {}\n      }),\n      mutation: opts.defineMutation ? new GraphQLObjectType({\n        name: 'Mutation',\n        fields: {}\n      }) : undefined\n    })\n  }\n\n  let entityResolversFactory\n  if (gateway) {\n    gateway = await buildGateway(gateway, app)\n\n    schema = gateway.schema\n    entityResolversFactory = gateway.entityResolversFactory\n\n    let gatewayInterval = null\n\n    if (gateway.pollingInterval !== undefined) {\n      if (typeof gateway.pollingInterval === 'number') {\n        gatewayInterval = setInterval(async () => {\n          const schema = await gateway.refresh()\n          if (schema !== null) {\n            fastifyGraphQl.replaceSchema(schema)\n          }\n        }, gateway.pollingInterval)\n      } else {\n        app.log.warn(`Expected a number for 'gateway.pollingInterval', received: ${typeof gateway.pollingInterval}`)\n      }\n    }\n\n    app.onClose((fastify, next) => {\n      gateway.close()\n      if (gatewayInterval !== null) {\n        clearInterval(gatewayInterval)\n      }\n      setImmediate(next)\n    })\n\n    fastifyGraphQl.gateway = gateway\n  }\n\n  fastifyGraphQl.schema = schema\n\n  app.addHook('onReady', async function () {\n    const schemaValidationErrors = validateSchema(fastifyGraphQl.schema)\n    if (schemaValidationErrors.length === 1) {\n      throw schemaValidationErrors[0]\n    } else if (schemaValidationErrors.length > 1) {\n      const err = new MER_ERR_GQL_INVALID_SCHEMA()\n      err.errors = schemaValidationErrors\n      throw err\n    }\n  })\n\n  const graphqlCtx = Symbol('ctx')\n\n  if (opts.routes !== false) {\n    const optsIde = opts.graphiql || opts.ide\n    app.register(routes, {\n      errorHandler: opts.errorHandler,\n      errorFormatter: opts.errorFormatter,\n      ide: optsIde,\n      ideSettings: opts.playgroundSettings,\n      prefix: opts.prefix,\n      path: opts.path,\n      context: opts.context,\n      persistedQueryProvider: opts.persistedQueryProvider,\n      allowBatchedQueries: opts.allowBatchedQueries,\n      subscriber,\n      verifyClient,\n      onConnect,\n      lruGatewayResolvers,\n      entityResolversFactory,\n      subscriptionContextFn\n    })\n  }\n\n  app.decorateReply(graphqlCtx, null)\n\n  app.decorateReply('graphql', function (source, context, variables, operationName) {\n    context = Object.assign({ reply: this, app }, context)\n    if (app[kFactory]) {\n      this[kLoaders] = factory.create(context)\n    }\n\n    return app.graphql(source, context, variables, operationName)\n  })\n\n  app.decorate('graphql', fastifyGraphQl)\n\n  fastifyGraphQl.replaceSchema = function (s) {\n    if (!s || typeof s !== 'object') {\n      throw new MER_ERR_INVALID_OPTS('Must provide valid Document AST')\n    }\n\n    fastifyGraphQl.schema = s\n\n    lru.clear()\n    lruErrors.clear()\n    lruGatewayResolvers.clear()\n  }\n\n  fastifyGraphQl.extendSchema = function (s) {\n    if (gateway) {\n      throw new MER_ERR_GQL_GATEWAY('Calling extendSchema method when plugin is running in gateway mode is not allowed')\n    }\n    if (opts.federationMetadata) {\n      throw new MER_ERR_INVALID_METHOD('Calling extendSchema method when federationMetadata is enabled is not allowed')\n    }\n\n    if (typeof s === 'string') {\n      s = parse(s)\n    } else if (!s || typeof s !== 'object') {\n      throw new MER_ERR_INVALID_OPTS('Must provide valid Document AST')\n    }\n\n    fastifyGraphQl.schema = extendSchema(fastifyGraphQl.schema, s)\n  }\n\n  fastifyGraphQl.defineResolvers = function (resolvers) {\n    if (gateway) {\n      throw new MER_ERR_GQL_GATEWAY('Calling defineResolvers method when plugin is running in gateway mode is not allowed')\n    }\n\n    for (const name of Object.keys(resolvers)) {\n      const type = fastifyGraphQl.schema.getType(name)\n\n      if (typeof resolvers[name] === 'function') {\n        root[name] = resolvers[name]\n      } else if (type instanceof GraphQLObjectType) {\n        const fields = type.getFields()\n        const resolver = resolvers[name]\n        if (resolver.isTypeOf) {\n          type.isTypeOf = resolver.isTypeOf\n          delete resolver.isTypeOf\n        }\n        for (const prop of Object.keys(resolver)) {\n          if (name === 'Subscription') {\n            fields[prop] = {\n              ...fields[prop],\n              ...resolver[prop]\n            }\n          } else if (prop === '__resolveReference') {\n            type.resolveReference = resolver[prop]\n          } else if (fields[prop]) {\n            fields[prop].resolve = resolver[prop]\n          } else {\n            throw new MER_ERR_INVALID_OPTS(`Cannot find field ${prop} of type ${type}`)\n          }\n        }\n      } else if (type instanceof GraphQLScalarType || type instanceof GraphQLEnumType) {\n        const resolver = resolvers[name]\n        for (const prop of Object.keys(resolver)) {\n          type[prop] = resolver[prop]\n        }\n      } else if (type instanceof GraphQLInterfaceType || type instanceof GraphQLUnionType) {\n        const resolver = resolvers[name]\n        type.resolveType = resolver.resolveType\n      } else {\n        throw new MER_ERR_INVALID_OPTS(`Cannot find type ${name}`)\n      }\n    }\n  }\n\n  let factory\n\n  fastifyGraphQl.defineLoaders = function (loaders) {\n    if (gateway) {\n      throw new MER_ERR_GQL_GATEWAY('Calling defineLoaders method when plugin is running in gateway mode is not allowed')\n    }\n\n    // set up the loaders factory\n    if (!factory) {\n      factory = new Factory()\n      app.decorateReply(kLoaders)\n      app.decorate(kFactory, factory)\n    }\n\n    function defineLoader (name) {\n      // async needed because of throw\n      return async function (obj, params, { reply }) {\n        if (!reply) {\n          throw new MER_ERR_INVALID_OPTS('loaders only work via reply.graphql()')\n        }\n        return reply[kLoaders][name]({ obj, params })\n      }\n    }\n\n    const resolvers = {}\n    for (const typeKey of Object.keys(loaders)) {\n      const type = loaders[typeKey]\n      resolvers[typeKey] = {}\n      for (const prop of Object.keys(type)) {\n        const name = typeKey + '-' + prop\n        resolvers[typeKey][prop] = defineLoader(name)\n        if (typeof type[prop] === 'function') {\n          factory.add(name, type[prop])\n        } else {\n          factory.add(name, type[prop].opts, type[prop].loader)\n        }\n      }\n    }\n    fastifyGraphQl.defineResolvers(resolvers)\n  }\n\n  fastifyGraphQl.transformSchema = function (schemaTransforms) {\n    if (!Array.isArray(schemaTransforms)) {\n      schemaTransforms = [schemaTransforms]\n    }\n\n    for (const transformFn of schemaTransforms) {\n      fastifyGraphQl.replaceSchema(transformFn(fastifyGraphQl.schema))\n    }\n  }\n\n  if (opts.resolvers) {\n    fastifyGraphQl.defineResolvers(opts.resolvers)\n  }\n\n  if (opts.loaders) {\n    fastifyGraphQl.defineLoaders(opts.loaders)\n  }\n\n  if (opts.schemaTransforms) {\n    fastifyGraphQl.transformSchema(opts.schemaTransforms)\n  }\n\n  async function fastifyGraphQl (source, context, variables, operationName) {\n    context = Object.assign({ app: this, lruGatewayResolvers }, context)\n    const reply = context.reply\n\n    // Parse, with a little lru\n    const cached = lru !== null && lru.get(source)\n    let document = null\n    if (!cached) {\n      // We use two caches to avoid errors bust the good\n      // cache. This is a protection against DoS attacks\n      const cachedError = lruErrors !== null && lruErrors.get(source)\n\n      if (cachedError) {\n        // this query errored\n        const err = new MER_ERR_GQL_VALIDATION()\n        err.errors = cachedError.validationErrors\n        throw err\n      }\n\n      try {\n        document = parse(source)\n      } catch (syntaxError) {\n        const err = new MER_ERR_GQL_VALIDATION()\n        err.errors = [syntaxError]\n        throw err\n      }\n\n      // Validate\n      let validationRules = []\n      if (opts.validationRules) {\n        if (Array.isArray(opts.validationRules)) {\n          validationRules = opts.validationRules\n        } else {\n          validationRules = opts.validationRules({ source, variables, operationName })\n        }\n      }\n      const validationErrors = validate(fastifyGraphQl.schema, document, [...specifiedRules, ...validationRules])\n\n      if (validationErrors.length > 0) {\n        if (lruErrors) {\n          lruErrors.set(source, { document, validationErrors })\n        }\n        const err = new MER_ERR_GQL_VALIDATION()\n        err.errors = validationErrors\n        throw err\n      }\n\n      if (queryDepthLimit) {\n        const queryDepthErrors = queryDepth(document.definitions, queryDepthLimit)\n\n        if (queryDepthErrors.length > 0) {\n          const err = new MER_ERR_GQL_VALIDATION()\n          err.errors = queryDepthErrors\n          throw err\n        }\n      }\n\n      if (lru) {\n        lru.set(source, { document, validationErrors, count: 1, jit: null })\n      }\n    } else {\n      document = cached.document\n    }\n\n    if (reply && reply.request.raw.method === 'GET') {\n      // let's validate we cannot do mutations here\n      const operationAST = getOperationAST(document, operationName)\n      if (operationAST.operation !== 'query') {\n        const err = new MER_ERR_METHOD_NOT_ALLOWED()\n        err.errors = [new Error('Operation cannot be performed via a GET request')]\n        throw err\n      }\n    }\n\n    // minJit is 0 by default\n    if (cached && cached.count++ === minJit) {\n      cached.jit = compileQuery(fastifyGraphQl.schema, document, operationName)\n    }\n\n    if (cached && cached.jit !== null) {\n      const execution = await cached.jit.query(root, context, variables || {})\n\n      return maybeFormatErrors(execution, context)\n    }\n\n    // Validate variables\n    if (variables !== undefined) {\n      const executionContext = buildExecutionContext(fastifyGraphQl.schema, document, root, context, variables, operationName)\n      if (Array.isArray(executionContext)) {\n        const err = new MER_ERR_GQL_VALIDATION()\n        err.errors = executionContext\n        throw err\n      }\n    }\n\n    const execution = await execute(\n      fastifyGraphQl.schema,\n      document,\n      root,\n      context,\n      variables,\n      operationName\n    )\n\n    return maybeFormatErrors(execution, context)\n  }\n\n  function maybeFormatErrors (execution, context) {\n    if (execution.errors) {\n      const { reply } = context\n      const { statusCode, response: { data, errors } } = errorFormatter(execution, context)\n      execution.data = data\n      execution.errors = errors\n      if (reply) {\n        reply.code(statusCode)\n      }\n    }\n    return execution\n  }\n}, {\n  name: 'mercurius',\n  fastify: '>=3.x'\n})\n\nplugin.ErrorWithProps = ErrorWithProps\nplugin.defaultErrorFormatter = defaultErrorFormatter\nplugin.persistedQueryDefaults = persistedQueryDefaults\nplugin.buildFederationSchema = buildFederationSchema\nplugin.withFilter = withFilter\n\nmodule.exports = plugin\n"]}