{"bin":{"graphql-binding":"./dist/bin.js"},"bugs":{"url":"https://github.com/graphcool/graphql-binding/issues"},"dist":{"shasum":"f0e7dbbae7e8b1e11c72d5d5d8beb7118711ad8d","tarball":"https://registry.npmjs.org/graphql-binding/-/graphql-binding-1.4.0-beta.19.tgz","fileCount":63,"integrity":"sha512-q18sxuCATU1EAXwBAl/UxYTNbHZiiw9cysdimH2YEhGthiVWfIn8V4i72V1tZDyRdo7nYZKrEe2BsGSK2zPT6w==","signatures":[{"sig":"MEUCIAk+2k6tF2FdJn6dZDG9Ktft5uW4RjVpRiKbSVmm6hVAAiEA1p4U0NtLmvVnF9hPW0NbTx42glLfIt3l9/IXPYlGGrI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":121673,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa7BTzCRA9TVsSAnZWagAAU/sQAJa8ndTIszU85M74tz2/\npcmSfUQ0z3FPRed07J0SZSPE0b1/LQCr1DlvrliLQbZIb3aCYwhlG0c43TIW\nj/MQoVqsKiup6PJmNFESX+B9i3dltTnBm9JDS6JgFFRgzD0CsU5SdGvbw7Pt\neiSjCG4w4Rbfy3qShOebqMz4tTzK8SLdY+VmGPHojkb3FEbjMMh+TZ9fNkE3\nY80KG/EOfP5yfH6MkC6s0eTA8C9HVur4y46aXbOtlhFgGD3z3Dr6F2LYBuJc\nj1hTALoXa9hJQMn8Vk6d7Pa65r61E5y8vctejogQK5JCaTzzhQmwszk8NTi1\nL9fJMU0wolzp7/8eGqL1z6mKKFyeTNs5q4FM3XV1ODHmm4w353OSyFBWPA3g\nybwUEqvAKmTsy2280EBkiBqTsYgceTV9H4WSoKRYapMO25R4CGmnz9LUgGbo\n7h7rVB9FgrFfrS/SVb+bwCWJdmjUAVJjxEtRUQCphzcC/tO1NRSC0sd6Iwvd\n5PAOCVnLocAHmh458/2XgAGmwPk3tQUIaXPHYrvLfYnJs39svkbTHmqe92WB\nUZ5Ax+Inx9JFZalnam83Mm+WDMOJNWi8N34LbVdWxhEAKH5LIfVw5PbxquRq\nKujS1PSqthT0nXari+ogAhCmnjddaWCCga0+VRyLzW3ym77KmFEiQ7vFYmPJ\nz64R\r\n=2kYH\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":"45013f9c9e91f368f4fbe93827bf840ef0435c4d","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.19_1525421298385_0.8779928646382182","host":"s3://npm-registry-packages"},"_id":"graphql-binding@1.4.0-beta.19","version":"1.4.0-beta.19"}