{"bin":{"graphql-binding":"./dist/bin.js"},"bugs":{"url":"https://github.com/graphcool/graphql-binding/issues"},"dist":{"shasum":"057987752d915fac9520d9b369b6819ed893d9df","tarball":"https://registry.npmjs.org/graphql-binding/-/graphql-binding-1.4.0-beta.20.tgz","fileCount":63,"integrity":"sha512-oSfpJCmdnwZSdQiPShi9AswoXNZHC4fPCFAyaZQbI+ii3LmiUrXGO8Twwrcx4DlD3UfRBx/cKlPiM7a+XaGKqg==","signatures":[{"sig":"MEYCIQDswkD8QnyZ+iGur0Fxmb6qNP+04fYpP6Dcc+fCqyZj6wIhALfPGY8emEZagXt4MLTh3nR8KrKn5WdKoDjYamV+9z9R","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":121860,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa7C4GCRA9TVsSAnZWagAAhgEP/1bkuv/7UR3WZEVE8qLS\nw9IQE7RAH2W7HuqzRmRESRodbOVFnb0e7Q8Ie1boW2QYOSEixBaosbQb4R29\naxlsbsGneCSq3iys5+l7116r7TtNw76wlg7uBTQ2qYN/wSeWPSwlyVzGtVZG\nRcBkmF9y5CP+TrtyU+uziUSpk/qXg0Xy6u26B/ekk8u8QWUfbHKUennC0DTE\nxQPRy8hkBOOCz+iJLn6zdaLbIowAsKV2JMmq3vPfuOhtIr24EacDxFUon9ff\nGVG3d6/nC7qmw1Q9fYiMowUO7RnczARCB+betkxd/06VcHntQkJujrLJQwpz\nseGUW4/Mw7kjxktohKkX/jSUITlkZ0JeuE04Rb3ULfqUpociqVIfug5y9CSl\n1pZvexxLTGdndxHtQlkGd7H8eZa7PvA3uhx/obPSY5vIdmtuFdCJEj70uBYI\n0ww5rA2HeveG4Set0MM+4dftKSRaAMwqTsez/9Qv+shlZm32P8TZeXh0rQbf\nNI2nRrEAZb8M0TYuWhs0o9Bz/1EeyYaoZSA23A2jpVki5R3fpnJNffLH0C5y\n0CwE7UkDsaHu/ZSgbIK/PnzTNnuGpkPDBYhw31MkLQrSZlDHtJMoWph9E5Vx\nqlN3DGAfRFGngZv26xAQ+dfu7hDaXwdlustuO3K2y4Dt98tUdUcdD2KqTiaT\nGrKP\r\n=Dm6d\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":"1d8786e479dd08153c51a9f2570911b0ea19df8e","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 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","graphql-tag":"^2.9.2","@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.20_1525427718435_0.7769097933287323","host":"s3://npm-registry-packages"},"_id":"graphql-binding@1.4.0-beta.20","version":"1.4.0-beta.20"}