You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We do this in our other projects in order to make it easier to consistently deal
with long lines (often happens with lines containing links), so we may as well
do it here too.
This is a library to allow the easy creation of Relay-compliant servers using
4
-
the [GraphQL.js](https://github.com/graphql/graphql-js) reference implementation
5
-
of a GraphQL server.
3
+
This 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.
A basic understanding of GraphQL and of the GraphQL.js implementation is needed
13
-
to provide context for this library.
10
+
A basic understanding of GraphQL and of the GraphQL.js implementation is needed to provide context for this library.
14
11
15
-
An overview of GraphQL in general is available in the
16
-
[README](https://github.com/facebook/graphql/blob/master/README.md) for the
17
-
[Specification for GraphQL](https://github.com/facebook/graphql).
12
+
An overview of GraphQL in general is available in the [README](https://github.com/facebook/graphql/blob/master/README.md) for the [Specification for GraphQL](https://github.com/facebook/graphql).
This library is designed to work with the [GraphQL.js](https://github.com/graphql/graphql-js) reference implementation of a GraphQL server.
22
15
23
-
An overview of the functionality that a Relay-compliant GraphQL server should
24
-
provide is in the [GraphQL Relay Specification](https://facebook.github.io/relay/docs/graphql-relay-specification.html)
25
-
on the [Relay website](https://facebook.github.io/relay/). That overview
26
-
describes a simple set of examples that exist as [tests](src/__tests__) in this
27
-
repository. A good way to get started with this repository is to walk through
28
-
that documentation and the corresponding tests in this library together.
16
+
An overview of the functionality that a Relay-compliant GraphQL server should provide is in the [GraphQL Relay Specification](https://facebook.github.io/relay/docs/graphql-relay-specification.html) on the [Relay website](https://facebook.github.io/relay/). 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.
29
17
30
18
## Using Relay Library for GraphQL.js
31
19
@@ -35,36 +23,21 @@ Install Relay Library for GraphQL.js
35
23
npm install graphql-relay
36
24
```
37
25
38
-
When building a schema for [GraphQL.js](https://github.com/graphql/graphql-js),
39
-
the provided library functions can be used to simplify the creation of Relay
40
-
patterns.
26
+
When 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.
41
27
42
28
### Connections
43
29
44
-
Helper functions are provided for both building the GraphQL types
45
-
for connections and for implementing the `resolve` method for fields
46
-
returning those types.
47
-
48
-
-`connectionArgs` returns the arguments that fields should provide when they
49
-
return a connection type that supports bidirectional pagination.
50
-
-`forwardConnectionArgs` returns the arguments that fields should provide
51
-
when they return a connection type that only supports forward pagination.
52
-
-`backwardConnectionArgs` returns the arguments that fields should provide
53
-
when they return a connection type that only supports backward pagination.
54
-
-`connectionDefinitions` returns a `connectionType` and its associated
55
-
`edgeType`, given a node type.
56
-
-`connectionFromArray` is a helper method that takes an array and the
57
-
arguments from `connectionArgs`, does pagination and filtering, and returns
58
-
an object in the shape expected by a `connectionType`'s `resolve` function.
59
-
-`connectionFromPromisedArray` is similar to `connectionFromArray`, but
60
-
it takes a promise that resolves to an array, and returns a promise that
61
-
resolves to the expected shape by `connectionType`.
62
-
-`cursorForObjectInConnection` is a helper method that takes an array and a
63
-
member object, and returns a cursor for use in the mutation payload.
64
-
-`offsetToCursor` takes the index of a member object in an array and
65
-
returns an opaque cursor for use in the mutation payload.
66
-
-`cursorToOffset` takes an opaque cursor (created with `offsetToCursor`)
67
-
and returns the corresponding array index.
30
+
Helper functions are provided for both building the GraphQL types for connections and for implementing the `resolve` method for fields returning those types.
31
+
32
+
-`connectionArgs` returns the arguments that fields should provide when they return a connection type that supports bidirectional pagination.
33
+
-`forwardConnectionArgs` returns the arguments that fields should provide when they return a connection type that only supports forward pagination.
34
+
-`backwardConnectionArgs` returns the arguments that fields should provide when they return a connection type that only supports backward pagination.
35
+
-`connectionDefinitions` returns a `connectionType` and its associated `edgeType`, given a node type.
36
+
-`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.
37
+
-`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`.
38
+
-`cursorForObjectInConnection` is a helper method that takes an array and a member object, and returns a cursor for use in the mutation payload.
39
+
-`offsetToCursor` takes the index of a member object in an array and returns an opaque cursor for use in the mutation payload.
40
+
-`cursorToOffset` takes an opaque cursor (created with `offsetToCursor`) and returns the corresponding array index.
68
41
69
42
An example usage of these methods from the [test schema](src/__tests__/starWarsSchema.js):
70
43
@@ -86,29 +59,17 @@ var factionType = new GraphQLObjectType({
86
59
});
87
60
```
88
61
89
-
This shows adding a `ships` field to the `Faction` object that is a connection.
90
-
It uses `connectionDefinitions({nodeType: shipType})` to create the connection
91
-
type, adds `connectionArgs` as arguments on this function, and then implements
92
-
the resolve function by passing the array of ships and the arguments to
93
-
`connectionFromArray`.
62
+
This 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`.
94
63
95
64
### Object Identification
96
65
97
-
Helper functions are provided for both building the GraphQL types
98
-
for nodes and for implementing global IDs around local IDs.
99
-
100
-
-`nodeDefinitions` returns the `Node` interface that objects can implement,
101
-
and returns the `node` root field to include on the query type. To implement
102
-
this, it takes a function to resolve an ID to an object, and to determine
103
-
the type of a given object.
104
-
-`toGlobalId` takes a type name and an ID specific to that type name,
105
-
and returns a "global ID" that is unique among all types.
106
-
-`fromGlobalId` takes the "global ID" created by `toGlobalID`, and returns
107
-
the type name and ID used to create it.
66
+
Helper functions are provided for both building the GraphQL types for nodes and for implementing global IDs around local IDs.
67
+
68
+
-`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.
69
+
-`toGlobalId` takes a type name and an ID specific to that type name, and returns a "global ID" that is unique among all types.
70
+
-`fromGlobalId` takes the "global ID" created by `toGlobalID`, and returns the type name and ID used to create it.
108
71
-`globalIdField` creates the configuration for an `id` field on a node.
109
-
-`pluralIdentifyingRootField` creates a field that accepts a list of
110
-
non-ID identifiers (like a username) and maps them to their corresponding
111
-
objects.
72
+
-`pluralIdentifyingRootField` creates a field that accepts a list of non-ID identifiers (like a username) and maps them to their corresponding objects.
112
73
113
74
An example usage of these methods from the [test schema](src/__tests__/starWarsSchema.js):
114
75
@@ -139,22 +100,13 @@ var queryType = new GraphQLObjectType({
139
100
});
140
101
```
141
102
142
-
This uses `nodeDefinitions` to construct the `Node` interface and the `node`
143
-
field; it uses `fromGlobalId` to resolve the IDs passed in the implementation
144
-
of the function mapping ID to object. It then uses the `globalIdField` method to
145
-
create the `id` field on `Faction`, which also ensures implements the
146
-
`nodeInterface`. Finally, it adds the `node` field to the query type, using the
147
-
`nodeField` returned by `nodeDefinitions`.
103
+
This 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`.
148
104
149
105
### Mutations
150
106
151
-
A helper function is provided for building mutations with
152
-
single inputs and client mutation IDs.
107
+
A helper function is provided for building mutations with single inputs and client mutation IDs.
153
108
154
-
-`mutationWithClientMutationId` takes a name, input fields, output fields,
155
-
and a mutation method to map from the input fields to the output fields,
156
-
performing the mutation along the way. It then creates and returns a field
157
-
configuration that can be used as a top-level field on the mutation type.
109
+
-`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.
158
110
159
111
An example usage of these methods from the [test schema](src/__tests__/starWarsSchema.js):
160
112
@@ -201,14 +153,9 @@ var mutationType = new GraphQLObjectType({
201
153
});
202
154
```
203
155
204
-
This code creates a mutation named `IntroduceShip`, which takes a faction
205
-
ID and a ship name as input. It outputs the `Faction` and the `Ship` in
206
-
question. `mutateAndGetPayload` then gets an object with a property for
207
-
each input field, performs the mutation by constructing the new ship, then
208
-
returns an object that will be resolved by the output fields.
156
+
This 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.
209
157
210
-
Our mutation type then creates the `introduceShip` field using the return
211
-
value of `mutationWithClientMutationId`.
158
+
Our mutation type then creates the `introduceShip` field using the return value of `mutationWithClientMutationId`.
212
159
213
160
## Contributing
214
161
@@ -218,16 +165,13 @@ After cloning this repo, ensure dependencies are installed by running:
218
165
npm install
219
166
```
220
167
221
-
This library is written in ES6 and uses [Babel](http://babeljs.io/) for ES5
222
-
transpilation and [Flow](http://flowtype.org/) for type safety. Widely
223
-
consumable JavaScript can be produced by running:
168
+
This library is written in ES6 and uses [Babel](http://babeljs.io/) for ES5 transpilation and [Flow](http://flowtype.org/) for type safety. Widely consumable JavaScript can be produced by running:
224
169
225
170
```sh
226
171
npm run build
227
172
```
228
173
229
-
Once `npm run build` has run, you may `import` or `require()` directly from
230
-
node.
174
+
Once `npm run build` has run, you may `import` or `require()` directly from node.
231
175
232
176
After developing, the full test suite can be evaluated by running:
233
177
@@ -241,7 +185,6 @@ While actively developing, we recommend running
241
185
npm run watch
242
186
```
243
187
244
-
in a terminal. This will watch the file system run lint, tests, and type
245
-
checking automatically whenever you save a js file.
188
+
in a terminal. This will watch the file system run lint, tests, and type checking automatically whenever you save a js file.
246
189
247
190
To lint the JS files and run type interface checks run `npm run lint`.
0 commit comments