{"name":"@envelop/core","version":"0.1.5-alpha-5e39864.0","sideEffects":false,"peerDependencies":{"graphql":"^14.0.0 || ^15.0.0"},"dependencies":{"@envelop/types":"0.1.4"},"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.cjs.js","module":"index.esm.js","typings":"index.d.ts","typescript":{"definition":"index.d.ts"},"readme":"## `@envelop/core`\r\n\r\nThis is the core package for Envelop. You can find a complete documentation here: https://github.com/dotansimha/envelop\r\n\r\n### Built-in plugins\r\n\r\n#### `useSchema`\r\n\r\nThis plugin is the simplest plugin for specifying your GraphQL schema. You can specify a schema created from any tool that emits `GraphQLSchema` object.\r\n\r\n```ts\r\nimport { envelop, useSchema } from '@envelop/core';\r\nimport { buildSchema } from 'graphql';\r\n\r\nconst mySchema = buildSchema(...);\r\n\r\nconst getEnveloped = envelop({\r\n  plugins: [\r\n    useSchema(mySchema),\r\n    // ... other plugins ...\r\n  ],\r\n});\r\n```\r\n\r\n#### `useErrorHandler`\r\n\r\nThis plugin triggers a custom function every time execution encounter an error.\r\n\r\n```ts\r\nimport { envelop, useErrorHandler } from '@envelop/core';\r\nimport { buildSchema } from 'graphql';\r\n\r\nconst getEnveloped = envelop({\r\n  plugins: [\r\n    useErrorHandler(error => {\r\n      // This callback is called per each GraphQLError emitted during execution phase\r\n    }),\r\n    // ... other plugins ...\r\n  ],\r\n});\r\n```\r\n\r\n> Note: every error is being triggered on it's own. So an execution results will multiple error will yield multiple calls.\r\n\r\n#### `useExtendContext`\r\n\r\nEasily extends the context with custom fields.\r\n\r\n```ts\r\nimport { envelop, useExtendContext } from '@envelop/core';\r\nimport { buildSchema } from 'graphql';\r\n\r\nconst getEnveloped = envelop({\r\n  plugins: [\r\n    useExtendContext(async (contextSoFar) => {\r\n      return {\r\n        myCustomField: { ... }\r\n      }\r\n    }),\r\n    // ... other plugins ...\r\n  ],\r\n});\r\n```\r\n\r\n#### `useLogger`\r\n\r\nLogs paramaters and information about the execution phases. You can easily plug your custom logger.\r\n\r\n```ts\r\nimport { envelop, useLogger } from '@envelop/core';\r\nimport { buildSchema } from 'graphql';\r\n\r\nconst getEnveloped = envelop({\r\n  plugins: [\r\n    useLogger({\r\n      logFn: (eventName, args) => {\r\n        // Event could be `execute-start` / `execute-end` / `subscribe-start` / `subscribe-end`\r\n        // `args` will include the arguments passed to execute/subscribe (in case of \"start\" event) and additional result in case of \"end\" event.\r\n      },\r\n    }),\r\n    // ... other plugins ...\r\n  ],\r\n});\r\n```\r\n\r\n#### `usePayloadFormatter`\r\n\r\nAllow you to format/modify execution result payload before returning it to your consumer.\r\n\r\n```ts\r\nimport { envelop, usePayloadFormatter } from '@envelop/core';\r\nimport { buildSchema } from 'graphql';\r\n\r\nconst getEnveloped = envelop({\r\n  plugins: [\r\n    usePayloadFormatter(result => {\r\n      // Return a modified result here,\r\n      // Or `false`y value to keep it as-is.\r\n    }),\r\n    // ... other plugins ...\r\n  ],\r\n});\r\n```\r\n\r\n#### `useTiming`\r\n\r\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`.\r\n\r\n```ts\r\nimport { envelop, useTiming } from '@envelop/core';\r\nimport { buildSchema } from 'graphql';\r\n\r\nconst getEnveloped = envelop({\r\n  plugins: [\r\n    useTiming({\r\n      // All options are optional. By default it just print it to the log.\r\n      // ResultTiming is an object built with { ms, ns } (milliseconds and nanoseconds)\r\n      onContextBuildingMeasurement: (timing: ResultTiming) => {},\r\n      onExecutionMeasurement: (args: ExecutionArgs, timing: ResultTiming) => {},\r\n      onSubscriptionMeasurement: (args: SubscriptionArgs, timing: ResultTiming) => {},\r\n      onParsingMeasurement: (source: Source | string, timing: ResultTiming) => {},\r\n      onValidationMeasurement: (document: DocumentNode, timing: ResultTiming) => {},\r\n      onResolverMeasurement: (info: GraphQLResolveInfo, timing: ResultTiming) => {},\r\n    }),\r\n    // ... other plugins ...\r\n  ],\r\n});\r\n```\r\n\r\n#### `useMaskedErrors`\r\n\r\nPrevent unexpected error messages from leaking to the GraphQL clients.\r\n\r\n```ts\r\nimport { envelop, useSchema } from '@envelop/core';\r\nimport { useMaskedErrors, EnvelopError } from '@envelop/masked-errors';\r\nimport { makeExecutableSchema } from 'graphql';\r\n\r\nconst schema = makeExecutableSchema({\r\n  typeDefs: /* GraphQL */ `\r\n    type Query {\r\n      something: String!\r\n      somethingElse: String!\r\n      somethingSpecial: String!\r\n    }\r\n  `,\r\n  resolvers: {\r\n    Query: {\r\n      something: () => {\r\n        throw new EnvelopError('Error that is propagated to the clients.');\r\n      },\r\n      somethingElse: () => {\r\n        throw new Error(\"Unsafe error that will be masked as 'Unexpected Error.'.\");\r\n      },\r\n      somethingSpecial: () => {\r\n        throw new EnvelopError('The error will have an extensions field.', {\r\n          code: 'ERR_CODE',\r\n          randomNumber: 123,\r\n        });\r\n      },\r\n    },\r\n  },\r\n});\r\n\r\nconst getEnveloped = envelop({\r\n  plugins: [useSchema(schema), useMaskedErrors()],\r\n});\r\n```\r\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@0.1.5-alpha-5e39864.0","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-CxgB1YxI0ldbMFBspuPk5xgd1yXZy+fJCrZ6chkys8AgXWO0+UmXUZS8Cixva7w+HNxjYSSuKUQMEoSKs8aCpQ==","shasum":"ccbfb18250686446e5420b669f6842f5c9695a3b","tarball":"http://registry-npm.ywwl.com/@envelop/core/download/@envelop/core-0.1.5-alpha-5e39864.0.tgz","fileCount":16,"unpackedSize":136693,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgplV8CRA9TVsSAnZWagAAGvwP/0UqK+Y5iqg/PQ/AWEkN\nCVduv9dxO570dGZ9usiVDlDxpNuVSLpTnZwD2iuxhgtwzfPu5MQ49gFCUwUk\no8CcFyd9ImLrhgDmmSvMo0RUxkuKQGWIjT9UPbKSWqRQsW1qP6cmtirILUEM\n7iNprs0mDJ7GPQByl0fkIMd1YbM+yHp4E6unDOVH8OvmMGOA9+hjqPcifeiv\nskG02IrCQA6N/L1kwYhiccINtScEOnrexhNQ6v0voEUTdVWn4BeNm9/x48rZ\ngKXp3A0UcyCEMmBMcZ2TJ/xuoiV+IjA4nmLlbBsGxZf1IhJQHhbIZvk2uRZJ\nMWSNv6sJlEdla9BHOPJUS4OcxxkOPuC9koxsUZHc1bXS6W7d0JkQah8a3dZK\n5+yuyCrzw8PWF/M2z1TWYPJOhZqrMv6vw2E76zKpI0MU89Kn4kabOZ3ySHvs\nkd//YNjyyCNfEhiqYjaBqKnE+ITKWSdUnmRV5jQ8P+KGiLJsH3fU+y3vaWvi\nHFDRH+0bNmOSl2AzRDz4JAT5he8snPWg8n5tn03rmLcBwP4yBWAX8DUfJgte\ni1lJOPumPg24pZ8als2njto9hv5bIQmg5p+slq6NTzMOA4f3RJ90CFh0xKdO\nL5kny0/Zyd0GfdErIMV3rVicDNnyQ9/XVgXRdezqXpe5zl9vLeNp0mmPvSvP\ngkyA\r\n=Lvwa\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDkW5HzP5wt7eUy0xusGCzJGgPeene64QP4q8Q9m6KuPAiEA8jSPlUZTOVk978z8O/H6O3fbl/1Bx/DadXnQqBXwuwU="}],"size":19769,"noattachment":false,"key":"/@envelop/core/-/@envelop/core-0.1.5-alpha-5e39864.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_0.1.5-alpha-5e39864.0_1621513596404_0.5370164966053013"},"_hasShrinkwrap":false,"publish_time":1621513596611,"_cnpm_publish_time":1621513596611,"dist-tags":{"alpha":"6.0.2-alpha-20261126100851-58d9782f151a975e802f1a545a315263d8d886a7","latest":"6.0.1","rc":"6.0.2-rc-20261124205929-9595907fc2bef8a397343bd288fef4685ab9f508"}}