{"name":"@envelop/core","version":"1.0.1-alpha-65d6f6f.0","sideEffects":false,"peerDependencies":{"graphql":"^14.0.0 || ^15.0.0"},"dependencies":{"@envelop/types":"1.0.1-alpha-65d6f6f.0"},"repository":{"type":"git","url":"git+https://github.com/dotansimha/envelop.git","directory":"packages/core"},"keywords":["gql","graphql","server","framework","node","nodejs","typescript"],"author":{"name":"Dotan Simha","email":"dotansimha@gmail.com"},"license":"MIT","main":"index.js","module":"index.mjs","typings":"index.d.ts","typescript":{"definition":"index.d.ts"},"exports":{".":{"require":"./index.js","import":"./index.mjs"},"./*":{"require":"./*.js","import":"./*.mjs"}},"readme":"## `@envelop/core`\n\nThis is the core package for Envelop. You can find a complete documentation here: https://github.com/dotansimha/envelop\n\n### Built-in plugins\n\n#### `useSchema`\n\nThis plugin is the simplest plugin for specifying your GraphQL schema. You can specify a schema created from any tool that emits `GraphQLSchema` object.\n\n```ts\nimport { envelop, useSchema } from '@envelop/core';\nimport { buildSchema } from 'graphql';\n\nconst mySchema = buildSchema(...);\n\nconst getEnveloped = envelop({\n  plugins: [\n    useSchema(mySchema),\n    // ... other plugins ...\n  ],\n});\n```\n\n#### `useAsyncSchema`\n\nSame as `useSchema`, but you can provide a `Promise<GraphQLSchema>` to load the actual schema.\n\n#### `useLazyLoadedSchema`\n\nSame as `useSchema`, but you can provide a `(initialContext) => GraphQLSchema` function to load the actual schema.\n\n#### `useErrorHandler`\n\nThis plugin triggers a custom function every time execution encounter an error.\n\n```ts\nimport { envelop, useErrorHandler } from '@envelop/core';\nimport { buildSchema } from 'graphql';\n\nconst getEnveloped = envelop({\n  plugins: [\n    useErrorHandler(error => {\n      // This callback is called per each GraphQLError emitted during execution phase\n    }),\n    // ... other plugins ...\n  ],\n});\n```\n\n> Note: every error is being triggered on it's own. So an execution results will multiple error will yield multiple calls.\n\n#### `useExtendContext`\n\nEasily extends the context with custom fields.\n\n```ts\nimport { envelop, useExtendContext } from '@envelop/core';\nimport { buildSchema } from 'graphql';\n\nconst getEnveloped = envelop({\n  plugins: [\n    useExtendContext(async (contextSoFar) => {\n      return {\n        myCustomField: { ... }\n      }\n    }),\n    // ... other plugins ...\n  ],\n});\n```\n\n#### `useLogger`\n\nLogs paramaters and information about the execution phases. You can easily plug your custom logger.\n\n```ts\nimport { envelop, useLogger } from '@envelop/core';\nimport { buildSchema } from 'graphql';\n\nconst getEnveloped = envelop({\n  plugins: [\n    useLogger({\n      logFn: (eventName, args) => {\n        // Event could be `execute-start` / `execute-end` / `subscribe-start` / `subscribe-end`\n        // `args` will include the arguments passed to execute/subscribe (in case of \"start\" event) and additional result in case of \"end\" event.\n      },\n    }),\n    // ... other plugins ...\n  ],\n});\n```\n\n#### `usePayloadFormatter`\n\nAllow you to format/modify execution result payload before returning it to your consumer.\n\n```ts\nimport { envelop, usePayloadFormatter } from '@envelop/core';\nimport { buildSchema } from 'graphql';\n\nconst getEnveloped = envelop({\n  plugins: [\n    usePayloadFormatter(result => {\n      // Return a modified result here,\n      // Or `false`y value to keep it as-is.\n    }),\n    // ... other plugins ...\n  ],\n});\n```\n\n#### `useTiming`\n\nSimple time metric collection, for every phase in your execution. You can easily customize the behaviour of each timing measurement. By default, the timing is printed to the log, using `console.log`.\n\n```ts\nimport { envelop, useTiming } from '@envelop/core';\nimport { buildSchema } from 'graphql';\n\nconst getEnveloped = envelop({\n  plugins: [\n    useTiming({\n      // All options are optional. By default it just print it to the log.\n      // ResultTiming is an object built with { ms, ns } (milliseconds and nanoseconds)\n      onContextBuildingMeasurement: (timing: ResultTiming) => {},\n      onExecutionMeasurement: (args: ExecutionArgs, timing: ResultTiming) => {},\n      onSubscriptionMeasurement: (args: SubscriptionArgs, timing: ResultTiming) => {},\n      onParsingMeasurement: (source: Source | string, timing: ResultTiming) => {},\n      onValidationMeasurement: (document: DocumentNode, timing: ResultTiming) => {},\n      onResolverMeasurement: (info: GraphQLResolveInfo, timing: ResultTiming) => {},\n    }),\n    // ... other plugins ...\n  ],\n});\n```\n\n#### `useMaskedErrors`\n\nPrevent unexpected error messages from leaking to the GraphQL clients.\n\n```ts\nimport { envelop, useSchema, useMaskedErrors, EnvelopError } from '@envelop/core';\nimport { makeExecutableSchema } from 'graphql';\n\nconst schema = makeExecutableSchema({\n  typeDefs: /* GraphQL */ `\n    type Query {\n      something: String!\n      somethingElse: String!\n      somethingSpecial: String!\n    }\n  `,\n  resolvers: {\n    Query: {\n      something: () => {\n        throw new EnvelopError('Error that is propagated to the clients.');\n      },\n      somethingElse: () => {\n        throw new Error(\"Unsafe error that will be masked as 'Unexpected Error.'.\");\n      },\n      somethingSpecial: () => {\n        throw new EnvelopError('The error will have an extensions field.', {\n          code: 'ERR_CODE',\n          randomNumber: 123,\n        });\n      },\n    },\n  },\n});\n\nconst getEnveloped = envelop({\n  plugins: [useSchema(schema), useMaskedErrors()],\n});\n```\n","readmeFilename":"README.md","description":"This is the core package for Envelop. You can find a complete documentation here: https://github.com/dotansimha/envelop","bugs":{"url":"https://github.com/dotansimha/envelop/issues"},"homepage":"https://github.com/dotansimha/envelop#readme","_id":"@envelop/core@1.0.1-alpha-65d6f6f.0","_nodeVersion":"14.17.3","_npmVersion":"6.14.13","dist":{"integrity":"sha512-kk7Sawq9QAjOihM1Cpe7cxf+bzWH8cm0IO31kKEU8rWO7DH7R4wBafZ7csdafTV+mtwQacYBBd/nPyo6ZJ0MwA==","shasum":"dbcc25b43c264eda3d242453222cc484d241a191","tarball":"http://registry-npm.ywwl.com/@envelop/core/download/@envelop/core-1.0.1-alpha-65d6f6f.0.tgz","fileCount":20,"unpackedSize":224741,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg+d+BCRA9TVsSAnZWagAAFQUP+wacWGyuRkrxGkFMXjQp\nwMae+MO02LDH1/pZ6WBglQYh3VAV9h8gMsHZuicGmqTRsKWfuNDXqxU6IBw/\nPHa66iMmySbMQx/Irx9gJpMxJWlxBY1oVIUOtq26q3DuexAHeV9SOXwd3J0Z\nzvj/g6Q/ABjaYTi2kZ5qMDcmsAoWE6CHRgO/yScB5ZuS1GAQ61Qlih1P3IrJ\nydKOQAp0sMsPa3cowNeo2SKcOGSeeJWvc30kQ4GrQRIcgxuuYkeuWUTSdKRP\nwZt3r2/VYVv7jJ2q3xNpzdSZc65ME4NtA39mbtRaXYq75O47XYVGM541fbDZ\n3qWqG9qBaF7Dxr2neqZ8qsDo55NcHhJmrmevedY40IkoRB6YoH7krw12G/tI\nucFIZ4RQ5HQAtpIECCHlgkQr5XkgbnHjVxvY6tC+xZXpOYmFla/fAZBPAyRr\ndnnWOcWsOMeYVLJKhGxwfOUCnznpeUZRCsDALlYzjyknOm1jupn2OPJS0Mpj\n71Ql2ab5/1J9Wbhi5Lulq9vTphMwscAUCfs6ui6UAMd00PfEsKT6Yz2UY8pq\ne1kzKRuJHe/A2dcFVKqk+A4pyN51SiE8J7uMbDoXzGEkBDLUu8eU0Wbq35wD\ngTXjtw8HgxaaFQXvN5kmyHPHFpscv9zH2SEIbYHpN9xxc+OsezYbnfFuoeh1\n9mFb\r\n=zfCA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF1msGkmjRz/PgHH2v5o5R6xxoekG0xIylo+CojZJhD/AiBz9ueo2bHKJeAA4wcJ5Yn6AnoD1Aa9K7nNbfe7s3qi7w=="}],"size":38987,"noattachment":false,"key":"/@envelop/core/-/@envelop/core-1.0.1-alpha-65d6f6f.0.tgz"},"_npmUser":{"name":"dotansimha","email":"dotansimha@gmail.com"},"directories":{},"maintainers":[{"name":"dotansimha","email":"dotansimha@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/core_1.0.1-alpha-65d6f6f.0_1626988417465_0.7889927111645822"},"_hasShrinkwrap":false,"publish_time":1626988417638,"_cnpm_publish_time":1626988417638,"dist-tags":{"alpha":"6.0.2-alpha-20261126100851-58d9782f151a975e802f1a545a315263d8d886a7","latest":"6.0.1","rc":"6.0.2-rc-20261124205929-9595907fc2bef8a397343bd288fef4685ab9f508"}}