{"bin":{"graphql-binding":"./dist/bin.js"},"bugs":{"url":"https://github.com/graphcool/graphql-binding/issues"},"dist":{"shasum":"8403f222ac5fb8f8fe363e0c1130ed41ff71850b","tarball":"https://registry.npmjs.org/graphql-binding/-/graphql-binding-1.4.0-beta.6.tgz","fileCount":54,"integrity":"sha512-Rmfw6oDwxq4a8ly8nb/EEOGp3jQDJP1AE9m6TEEPM1n3EuoRqMjNlkEO/A2m/9KVv7zHqWF3Z+DbgGfBytckcQ==","signatures":[{"sig":"MEUCIAFbn/0diG5bgrJ5YY46IOfCMcAwtSsnbkuiEZ8HjHW5AiEA0k2YqbM53mVYirItZg4k70NNWpjpI6edd46v0woRx2s=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":113681,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa6eGqCRA9TVsSAnZWagAAZgAP/0gLRcDYeRLlJjskYuSb\nFJbNbBFblmyPJtaHK8nrjWhQiJutHX74IDfRNfJVCUfKyhie2ENvb4Biew+E\nILC8BWLwz9NtlBgDU14ejDe4gOGE0BQ8hNpDSuPi4LD18IB4pDMk4M9Q3hSO\nLrxdfxr7Jnf4f3wcYm4uvsnwI/Q9IHn60UloGSoTyCiQbbqXrAZeP1wElMqh\ntQjgR/FuapxE3vH5X3O82g8+ImelemPB/2MufU83Vb9WejtO6GsKRuErub/v\nVdZJjHTKxaOUOiWE8KKOufV/zsmtM+TWiRMBrEIjLk5RYMbGll9UctIGsNv7\n69vMV0mb+SKEKSwsCsVjlicB7XaiuBpG6JpY8ARTZMjK6srgJSR8OrOcluD9\nga2MWTDpfzAuTTmalc64DtEpDdQHBqHwTbCwCKFCAWdcnbS+KV1pwvouK22G\n6CJPyIQ0XJZhENWCWyMLmysKNXu9KMSoyLkL4NgKBGNI8cB/n4TovlSmxqJj\nretLlr/fdXvtNMK5z/4hBNbUIPxdiS3vQ6MBjyIZS5qscfDoJw5kcr/0cgLB\nFVBrI3G5UBu6YumIevFsbUvA/RW0ByIBP/su4unV5j9Q4NRLy3vrr5e+JbHr\nIomwDWoJ7VRr9VoF6mj5h3NuHMc0QzrcSr+TKSy2NWXAnWIf2jwAnlv/y4no\nUrth\r\n=rzH1\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","name":"graphql-binding","files":["dist"],"author":{"name":"Johannes Schickling","email":"johannes@graph.cool"},"readme":"# graphql-binding\n\n[![CircleCI](https://circleci.com/gh/graphql-binding/graphql-binding.svg?style=shield)](https://circleci.com/gh/graphql-binding/graphql-binding) [![npm version](https://badge.fury.io/js/graphql-binding.svg)](https://badge.fury.io/js/graphql-binding)\n\n## Overview\n\n🔗 GraphQL bindings are **modular building blocks** that allow to embed existing GraphQL APIs into your own GraphQL server. Think about it as turning (parts of) GraphQL APIs into reusable LEGO building blocks.\n\n> The idea of GraphQL bindings is introduced in detail in this blog post: [Reusing & Composing GraphQL APIs with GraphQL Bindings](https://blog.graph.cool/80a4aa37cff5)\n\n## Install\n\n```sh\nyarn add graphql-binding\n```\n\n## API\n\n### `Binding`\n\n#### `constructor(options: BindingOptions): Binding`\n\n[`BindingOptions`](./src/types.ts#L27) has the following properties:\n\n| Key                    | Required | Type                   | Default             | Note                                                                                                                                                                                                                           |\n| ---------------------- | -------- | ---------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `schema`               | Yes      | `GraphQLSchema`        | -                   | The executable [GraphQL schema](https://blog.graph.cool/ac5e2950214e) for binding                                                                                                                                              |\n| `fragmentReplacements` | No       | `FragmentReplacements` | `{}`                | A list of GraphQL fragment definitions, specifying fields that are required for the resolver to function correctly                                                                                                             |\n| `before`               | No       | `() => void`           | `(() => undefined)` | A function that will be executed before a query/mutation is sent to the GraphQL API                                                                                                                                            |\n| `handler`              | No       | `any`                  | `null`              | The [`handler`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler) object from [JS Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) |\n| `subscriptionHandler`  | No       | `any`                  | `null`              | ...                                                                                                                                                                                                                            |\n\n#### `binding.query.<rootField>(): Promise<any>` & `binding.mutation.<rootField>(): Promise<any>`\n\nA binding object exposes two properties which can be used to send queries and mutations to the API: `binding.query` and `binding.mutation`.\n\nBoth are of type [`QueryMap`](src/types.ts#L11) and will expose methods that are named after the schema's root fields on the `Query` and `Mutation` types.\n\nThese methods take three arguments:\n\n| Name      | Required | Type                                 | Note                                                                                                                                                                                                                                         |\n| --------- | -------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `args`    | No       | `[key: string]: any`                 | An object that contains the arguments of the root field                                                                                                                                                                                      |\n| `context` | No       | `[key: string]: any`                 | The `context` object that's passed down the GraphQL resolver chain; every resolver can read from and write to that object                                                                                                                    |\n| `info`    | No       | `GraphQLResolveInfo` &#124; `string` | The `info` object (which contains an AST of the incoming query/mutation) that's passed down the GraphQL resolver chain or a string containing a [selection set](https://medium.com/front-end-developers/graphql-selection-sets-d588f6782e90) |\n\n##### Example\n\nAssume the following schema:\n\n```graphql\ntype Query {\n  user(id: ID!): User\n}\n\ntype Mutation {\n  createUser(): User!\n}\n```\n\nIf there is a `binding` for a GraphQL API that implements this schema, you can invoke the following methods on it:\n\n```js\nbinding.query.user({ id: 'abc' })\nbinding.mutation.createUser()\n```\n\nWhen using the binding in a resolver implementation, it can be used as follows:\n\n```js\nfindUser(parent, args, context, info) {\n  return binding.user({ id: args.id }, context, info)\n}\n\nnewUser(parent, args, context, info) {\n  return binding.createUser({}, context, info)\n}\n```\n\n#### `binding.subscription.<rootField>(...): AsyncIterator<any> | Promise<AsyncIterator<any>>`\n\nThe `binding.subscription` property follows the same idea as `query` and `mutation`, but rather than returning a single value using a `Promise`, it returns a _stream_ of values using `AsyncIterator`.\n\nIt is of type [`SubscriptionMap`](./src/types.ts#L19) and will expose methods that are named after the schema's root fields on the `Subscription` type.\n\nThese methods take same three arguments as the generated methods on `query` and `mutation`, see above for the details.\n\n#### `binding.getAbstractResolvers(filterSchema?: GraphQLSchema | string): IResolvers`\n\nIn order to have support for custom abstract Types like `Interface` or `Union`, the `getAbstractResolvers` method can be used.\nThe returned resolver then have to be included in the resolvers of the application:\n\n```ts\nconst typeDefs = importSchema('app.graphql')\nconst resolvers = {\n  Query: {\n    hello: (parent, { name }) => `Hello ${name || 'World'}!`,\n  },\n  // the following is needed to make interfaces, unions & custom scalars work\n  ...binding.getAbstractResolvers(typeDefs),\n}\n```\n\n### `utils`\n\n#### `addFragmentToInfo(info: GraphQLResolverInfo, fragment: string): GraphQLResolverInfo`\n\nCan be used to ensure that specific fields are included in the `info` object passed into the bindings.\n\n##### Example\n\n```ts\nimport {addFragmentToInfo} from 'graphql-binding'\n\nasync findUser(parent, args, context, info) {\n  const user = await binding.user({ id: args.id }, context, addFragmentToInfo(info, 'fragment EnsureEmail on User { email }'))\n\n  if (blackList.includes(user.email)) {\n    throw new Error('This user is blocked')\n  }\n\n  return user\n}\n```\n\n## Example\n\n### Minimal example\n\n```js\nconst { makeExecutableSchema } = require('graphql-tools')\nconst { Binding } = require('graphql-binding')\n\nconst users = [\n  {\n    name: 'Alice',\n  },\n  {\n    name: 'Bob',\n  },\n]\n\nconst typeDefs = `\n  type Query {\n    findUser(name: String!): User\n  }\n  type User {\n    name: String!\n  }\n`\n\nconst resolvers = {\n  Query: {\n    findUser: (parent, { name }) => users.find(u => u.name === name),\n  },\n}\n\nconst schema = makeExecutableSchema({ typeDefs, resolvers })\n\nconst findUserBinding = new Binding({\n  schema,\n})\n\nfindUserBinding.findUser({ name: 'Bob' }).then(result => console.log(result))\n```\n\n## Public GraphQL bindings\n\nYou can find practical, production-ready examples here:\n\n* [`graphql-binding-github`](https://github.com/graphcool/graphql-binding-github)\n* [`prisma-binding`](https://github.com/graphcool/prisma-binding)\n\n> Note: If you've created your own GraphQL binding based on this package, please add it to this list via a PR 🙌\n\nIf you have any questions, share some ideas or just want to chat about GraphQL bindings, join the [`#graphql-bindings`](https://graphcool.slack.com/messages/graphql-bindings) channel in our [Slack](https://slack.graph.cool/).\n","gitHead":"adaac1e74b85fca72f65a93af2752894c1532e20","license":"MIT","scripts":{"test":"tslint src/**/*.ts && npm run test-only","build":"rm -rf dist && tsc -d","test-only":"npm run build && ava --verbose dist/**/*.test.js","prepublish":"npm run build"},"typings":"dist/index.d.ts","_npmUser":{"name":"timsuchanek","email":"tim.suchanek@gmail.com"},"homepage":"https://github.com/graphcool/graphql-binding#readme","repository":{"url":"git+ssh://git@github.com/graphcool/graphql-binding.git","type":"git"},"typescript":{"definition":"dist/index.d.ts"},"_npmVersion":"5.6.0","description":"[![CircleCI](https://circleci.com/gh/graphql-binding/graphql-binding.svg?style=shield)](https://circleci.com/gh/graphql-binding/graphql-binding) [![npm version](https://badge.fury.io/js/graphql-binding.svg)](https://badge.fury.io/js/graphql-binding)","directories":{},"maintainers":[{"name":"schickling","email":"schickling.j@gmail.com"},{"name":"timsuchanek","email":"tim.suchanek@gmail.com"}],"_nodeVersion":"8.9.4","contributors":[{"name":"Kim Brandwijk","email":"kim.brandwijk@gmail.com"},{"name":"Tim Suchanek","email":"suchanek@prisma.io"}],"dependencies":{"yargs":"^11.0.0","iterall":"1.2.2","ts-node":"^6.0.2","resolve-cwd":"^2.0.0","graphql-tools":"3.0.0","graphql-import":"^0.5.0","object-path-immutable":"^1.0.1"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"ava":"0.25.0","tslint":"5.9.1","graphql":"0.13.2","typescript":"2.8.3","@types/node":"10.0.2","apollo-link":"1.2.1","@types/graphql":"0.13.0","tslint-config-standard":"7.0.0"},"peerDependencies":{"graphql":"^0.11.0 || ^0.12.0 || ^0.13.0"},"_npmOperationalInternal":{"tmp":"tmp/graphql-binding_1.4.0-beta.6_1525277098012_0.8522419900474323","host":"s3://npm-registry-packages"},"_id":"graphql-binding@1.4.0-beta.6","version":"1.4.0-beta.6"}