{"bin":{"graphql-binding":"./dist/bin.js"},"bugs":{"url":"https://github.com/graphcool/graphql-binding/issues"},"dist":{"shasum":"bb742c4eedf3bc665e9c905ea7af2ff19e1c9b97","tarball":"https://registry.npmjs.org/graphql-binding/-/graphql-binding-1.4.0-beta.18.tgz","fileCount":63,"integrity":"sha512-g/6ev6gxRka3jpuhm+SDDOvseTVcCkfExIECEZzURYi3KOe86r4BC0WyIeb5jdNcYVDPH+YDDHPkcveX4CwmHg==","signatures":[{"sig":"MEYCIQCeICCCYv1cA+UkeSMXeMO+0hzn7Sx+6nq15PSDVaC36AIhAIAdgFkDyvj9CoA9RoOvnR0GXDzDsnUhHaGxw7fkK9KS","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":121675,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa6z39CRA9TVsSAnZWagAAFHsP/jtIltC0ZP+a+ZLShIor\nFH6M9go1DmzesBAKUFj64YcUmDfEDiEobsNAtlaHo0X3w/mWqVDssX64XATF\nJCfHg9Z3Vg4HFuWhHeKcORtlwdmPaitw9w4/KkjW6bOgATukEFg8my+eYx9J\nBefGK6vbRH+fP0VI6TCuIw0Cfn15aOuJGgt+W60TmLIzRgxkkpK2uxZLgv6N\nq7ae9FTQ0TS/VPVOAbQC2IOrM3PGoNfXwXp8LBuSotALFBpcj4eBf06HorE9\nxbqHT7NQY8srUbfiehKV9ntBC6oonbqW3MlwMrXUoPrTS70SiGCLvE59Ro4N\nWq2m15g5UTadhBxG/R0K1X5ft1vsRWp0CEd3ZFyQL6NmMgOMP/Leg3LcAiw3\ngQ9+cZUJuLoKEKa+XEVWoaYz8nH6GQrbJGvrW7JLembhMg+5227Qmto+fjL7\nm8Q0rt0IkrwI5gpyfG0DEVhmkMuBN7LqHGeLXZoGmQcuH4OW4IuoK32KVBi8\nSNdDdN1Z8N4o3tHsrceXIjL4lHjFe33eLenyADJ0LEiQTNVLodL92A1Bw6OM\nMwR6Q5wzxpB9SmxhuAO5ts6U10zzxjJOywAegbjZWc4tSDdzXwGmxYi2RRdG\ndLAz/FoYZb17S7xJBdtP2EmUUZ9VyNiBPvIxBVkDWLykNgRcmZ3NC21tWrzv\nIkyr\r\n=yK1Z\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.18_1525366268889_0.9397569822602374","host":"s3://npm-registry-packages"},"_id":"graphql-binding@1.4.0-beta.18","version":"1.4.0-beta.18"}