{"name":"graphql-relay","version":"0.3.3","description":"A library to help construct a graphql-js server supporting react-relay.","contributors":[{"name":"Daniel Schafer","email":"dschafer@fb.com"}],"license":"BSD-3-Clause","homepage":"https://github.com/graphql/graphql-relay-js","bugs":{"url":"https://github.com/graphql/graphql-relay-js/issues"},"repository":{"type":"git","url":"git+ssh://git@github.com/graphql/graphql-relay-js.git"},"main":"lib/index.js","directories":{"lib":"./lib"},"files":["lib","README.md","LICENSE","PATENTS"],"options":{"mocha":"--require scripts/mocha-bootload src/**/__tests__/**/*.js"},"babel":{"optional":["runtime","es7.asyncFunctions","es7.objectRestSpread"]},"scripts":{"prepublish":"npm test && npm run build","test":"npm run lint && npm run check && mocha $npm_package_options_mocha","testonly":"mocha $npm_package_options_mocha","lint":"eslint src","check":"flow check","build":"rm -rf lib/* && babel src --ignore __tests__ --optional runtime --out-dir lib","watch":"babel --optional runtime scripts/watch.js | node","cover":"babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha","cover:lcov":"babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha"},"dependencies":{"babel-runtime":"~5.8.3"},"peerDependencies":{"graphql":"~0.4.2"},"devDependencies":{"babel":"5.8.3","babel-core":"5.8.3","babel-eslint":"4.0.5","chai":"3.0.0","chai-as-promised":"5.1.0","coveralls":"2.11.3","eslint":"0.24.0","flow-bin":"0.13.1","graphql":"0.4.2","isparta":"3.0.3","mocha":"2.2.5","sane":"1.1.3"},"gitHead":"5a0e5c37517255198db25fc218e8783c3aa2dd89","_id":"graphql-relay@0.3.3","_shasum":"a58095b5fc2ac619f66247fd973e3d0fa40d49e4","_from":".","_npmVersion":"2.14.6","_nodeVersion":"4.1.2","_npmUser":{"name":"wincent","email":"greg@hurrell.net"},"dist":{"shasum":"a58095b5fc2ac619f66247fd973e3d0fa40d49e4","tarball":"http://registry-npm.ywwl.com/graphql-relay/download/graphql-relay-0.3.3.tgz","integrity":"sha512-W7QhAZLzZYNvvmFX6WffV5kxLF5BRiLKpkYikuc8YG7u/SoiHgQEAdoiQSw/Pk2Hp5Jje+r4GcSgf/ahzRPXrA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDpYpOqVfoTQ5gMV83584+QOt+Xkfr5mnIXmjbnEeyXUgIhAMQW28sjFokXz2xv7sFIBGQ20EuiocgiokSRiNorl9zP"}],"size":11305,"noattachment":false,"key":"/graphql-relay/-/graphql-relay-0.3.3.tgz"},"maintainers":[{"name":"dschafer","email":"dschafer@fb.com"},{"name":"fb","email":"opensource+npm@fb.com"},{"name":"josephsavona","email":"joesavona@fb.com"},{"name":"kassens","email":"jkassens@fb.com"},{"name":"leebyron","email":"lee@leebyron.com"},{"name":"schrockn","email":"schrockn@gmail.com"},{"name":"steveluscher","email":"steveluscher@fb.com"},{"name":"wincent","email":"greg@hurrell.net"},{"name":"yungsters","email":"yungsters@gmail.com"},{"name":"yuzhi","email":"yuzhi.z@gmail.com"},{"name":"zpao","email":"paul@oshannessy.com"}],"readme":"# Relay Library for GraphQL.js\n\nThis is a library to allow the easy creation of Relay-compliant servers using the [GraphQL.js](https://github.com/graphql/graphql-js) reference implementation of a GraphQL server.\n\n[![Build Status](https://github.com/graphql/graphql-relay-js/workflows/CI/badge.svg?branch=main)](https://github.com/graphql/graphql-relay-js/actions?query=branch%3Amain)\n[![Coverage Status](https://codecov.io/gh/graphql/graphql-relay-js/branch/master/graph/badge.svg)](https://codecov.io/gh/graphql/graphql-relay-js)\n\n## Getting Started\n\nA basic understanding of GraphQL and of the GraphQL.js implementation is needed to provide context for this library.\n\nAn overview of GraphQL in general is available in the [README](https://github.com/graphql/graphql-spec/blob/master/README.md) for the [Specification for GraphQL](https://github.com/graphql/graphql-spec).\n\nThis library is designed to work with the [GraphQL.js](https://github.com/graphql/graphql-js) reference implementation of a GraphQL server.\n\nAn overview of the functionality that a Relay-compliant GraphQL server should provide is in the [GraphQL Relay Specification](https://relay.dev/docs/guides/graphql-server-specification/) on the [Relay website](https://relay.dev/). That overview describes a simple set of examples that exist as [tests](src/__tests__) in this repository. A good way to get started with this repository is to walk through that documentation and the corresponding tests in this library together.\n\n## Using Relay Library for GraphQL.js\n\nInstall Relay Library for GraphQL.js\n\n```sh\nnpm install graphql graphql-relay\n```\n\nWhen building a schema for [GraphQL.js](https://github.com/graphql/graphql-js), the provided library functions can be used to simplify the creation of Relay patterns.\n\n### Connections\n\nHelper functions are provided for both building the GraphQL types for connections and for implementing the `resolve` method for fields returning those types.\n\n- `connectionArgs` returns the arguments that fields should provide when they return a connection type that supports bidirectional pagination.\n- `forwardConnectionArgs` returns the arguments that fields should provide when they return a connection type that only supports forward pagination.\n- `backwardConnectionArgs` returns the arguments that fields should provide when they return a connection type that only supports backward pagination.\n- `connectionDefinitions` returns a `connectionType` and its associated `edgeType`, given a node type.\n- `connectionFromArray` is a helper method that takes an array and the arguments from `connectionArgs`, does pagination and filtering, and returns an object in the shape expected by a `connectionType`'s `resolve` function.\n- `connectionFromPromisedArray` is similar to `connectionFromArray`, but it takes a promise that resolves to an array, and returns a promise that resolves to the expected shape by `connectionType`.\n- `cursorForObjectInConnection` is a helper method that takes an array and a member object, and returns a cursor for use in the mutation payload.\n- `offsetToCursor` takes the index of a member object in an array and returns an opaque cursor for use in the mutation payload.\n- `cursorToOffset` takes an opaque cursor (created with `offsetToCursor`) and returns the corresponding array index.\n\nAn example usage of these methods from the [test schema](src/__tests__/starWarsSchema.ts):\n\n```js\nvar { connectionType: ShipConnection } = connectionDefinitions({\n  nodeType: shipType,\n});\nvar factionType = new GraphQLObjectType({\n  name: 'Faction',\n  fields: () => ({\n    ships: {\n      type: ShipConnection,\n      args: connectionArgs,\n      resolve: (faction, args) =>\n        connectionFromArray(\n          faction.ships.map((id) => data.Ship[id]),\n          args,\n        ),\n    },\n  }),\n});\n```\n\nThis shows adding a `ships` field to the `Faction` object that is a connection. It uses `connectionDefinitions({nodeType: shipType})` to create the connection type, adds `connectionArgs` as arguments on this function, and then implements the resolve function by passing the array of ships and the arguments to `connectionFromArray`.\n\n### Object Identification\n\nHelper functions are provided for both building the GraphQL types for nodes and for implementing global IDs around local IDs.\n\n- `nodeDefinitions` returns the `Node` interface that objects can implement, and returns the `node` root field to include on the query type. To implement this, it takes a function to resolve an ID to an object, and to determine the type of a given object.\n- `toGlobalId` takes a type name and an ID specific to that type name, and returns a \"global ID\" that is unique among all types.\n- `fromGlobalId` takes the \"global ID\" created by `toGlobalID`, and returns the type name and ID used to create it.\n- `globalIdField` creates the configuration for an `id` field on a node.\n- `pluralIdentifyingRootField` creates a field that accepts a list of non-ID identifiers (like a username) and maps them to their corresponding objects.\n\nAn example usage of these methods from the [test schema](src/__tests__/starWarsSchema.ts):\n\n```js\nvar { nodeInterface, nodeField } = nodeDefinitions(\n  (globalId) => {\n    var { type, id } = fromGlobalId(globalId);\n    return data[type][id];\n  },\n  (obj) => {\n    return obj.ships ? factionType : shipType;\n  },\n);\n\nvar factionType = new GraphQLObjectType({\n  name: 'Faction',\n  fields: () => ({\n    id: globalIdField(),\n  }),\n  interfaces: [nodeInterface],\n});\n\nvar queryType = new GraphQLObjectType({\n  name: 'Query',\n  fields: () => ({\n    node: nodeField,\n  }),\n});\n```\n\nThis uses `nodeDefinitions` to construct the `Node` interface and the `node` field; it uses `fromGlobalId` to resolve the IDs passed in the implementation of the function mapping ID to object. It then uses the `globalIdField` method to create the `id` field on `Faction`, which also ensures implements the `nodeInterface`. Finally, it adds the `node` field to the query type, using the `nodeField` returned by `nodeDefinitions`.\n\n### Mutations\n\nA helper function is provided for building mutations with single inputs and client mutation IDs.\n\n- `mutationWithClientMutationId` takes a name, input fields, output fields, and a mutation method to map from the input fields to the output fields, performing the mutation along the way. It then creates and returns a field configuration that can be used as a top-level field on the mutation type.\n\nAn example usage of these methods from the [test schema](src/__tests__/starWarsSchema.ts):\n\n```js\nvar shipMutation = mutationWithClientMutationId({\n  name: 'IntroduceShip',\n  inputFields: {\n    shipName: {\n      type: new GraphQLNonNull(GraphQLString),\n    },\n    factionId: {\n      type: new GraphQLNonNull(GraphQLID),\n    },\n  },\n  outputFields: {\n    ship: {\n      type: shipType,\n      resolve: (payload) => data['Ship'][payload.shipId],\n    },\n    faction: {\n      type: factionType,\n      resolve: (payload) => data['Faction'][payload.factionId],\n    },\n  },\n  mutateAndGetPayload: ({ shipName, factionId }) => {\n    var newShip = {\n      id: getNewShipId(),\n      name: shipName,\n    };\n    data.Ship[newShip.id] = newShip;\n    data.Faction[factionId].ships.push(newShip.id);\n    return {\n      shipId: newShip.id,\n      factionId: factionId,\n    };\n  },\n});\n\nvar mutationType = new GraphQLObjectType({\n  name: 'Mutation',\n  fields: () => ({\n    introduceShip: shipMutation,\n  }),\n});\n```\n\nThis code creates a mutation named `IntroduceShip`, which takes a faction ID and a ship name as input. It outputs the `Faction` and the `Ship` in question. `mutateAndGetPayload` then gets an object with a property for each input field, performs the mutation by constructing the new ship, then returns an object that will be resolved by the output fields.\n\nOur mutation type then creates the `introduceShip` field using the return value of `mutationWithClientMutationId`.\n\n## Contributing\n\nAfter cloning this repo, ensure dependencies are installed by running:\n\n```sh\nnpm install\n```\n\nThis library is written in ES6 and uses [Babel](https://babeljs.io/) for ES5 transpilation and [TypeScript](https://www.typescriptlang.org/) for type safety. Widely consumable JavaScript can be produced by running:\n\n```sh\nnpm run build\n```\n\nOnce `npm run build` has run, you may `import` or `require()` directly from node.\n\nAfter developing, the full test suite can be evaluated by running:\n\n```sh\nnpm test\n```\n\n## Opening a PR\n\nWe actively welcome pull requests. Learn how to [contribute](./.github/CONTRIBUTING.md).\n\nThis repository is managed by EasyCLA. Project participants must sign the free ([GraphQL Specification Membership agreement](https://preview-spec-membership.graphql.org) before making a contribution. You only need to do this one time, and it can be signed by [individual contributors](https://individual-spec-membership.graphql.org/) or their [employers](https://corporate-spec-membership.graphql.org/).\n\nTo initiate the signature process please open a PR against this repo. The EasyCLA bot will block the merge if we still need a membership agreement from you.\n\nYou can find [detailed information here](https://github.com/graphql/graphql-wg/tree/main/membership). If you have issues, please email [operations@graphql.org](mailto:operations@graphql.org).\n\nIf your company benefits from GraphQL and you would like to provide essential financial support for the systems and people that power our community, please also consider membership in the [GraphQL Foundation](https://foundation.graphql.org/join).\n\n## Changelog\n\nChanges are tracked as [GitHub releases](https://github.com/graphql/graphql-js/releases).\n\n## License\n\ngraphql-relay-js is [MIT licensed](./LICENSE).\n","publish_time":1444923709310,"_cnpm_publish_time":1444923709310,"dist-tags":{"latest":"0.11.0","next":"0.11.0"}}