File tree Expand file tree Collapse file tree 5 files changed +41
-21
lines changed Expand file tree Collapse file tree 5 files changed +41
-21
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ Use [Relay](http://facebook.github.io/relay/) without a GraphQL server.
8
8
### Relay Modern
9
9
10
10
``` js
11
+ import { Environment } from ' react-relay' ;
11
12
import { Network } from ' relay-local-schema' ;
12
13
13
14
import schema from ' ./data/schema' ;
@@ -33,6 +34,20 @@ const environment = new Environment({
33
34
});
34
35
```
35
36
37
+ For more control over the network layer, you can use ` createFetch ` to create just the fetch function.
38
+
39
+ ``` js
40
+ import { Environment , Network } from ' react-relay' ;
41
+ import { createFetch } from ' relay-local-schema' ;
42
+
43
+ import schema from ' ./data/schema' ;
44
+
45
+ const environment = new Environment ({
46
+ network: Network .create (createFetch ({ schema })),
47
+ /* ... */
48
+ });
49
+ ```
50
+
36
51
### Relay Classic
37
52
38
53
``` js
Original file line number Diff line number Diff line change 1
- export { Network } from './modern' ;
1
+ export { createFetch , Network } from './modern' ;
Original file line number Diff line number Diff line change 1
- import { graphql } from 'graphql' ;
2
- import { Network as NetworkBase } from 'relay-runtime' ;
1
+ import { Network } from 'relay-runtime' ;
3
2
4
- export default {
5
- create ( { schema, rootValue, contextValue } ) {
6
- function fetchQuery ( operation , variables ) {
7
- return graphql (
8
- schema ,
9
- operation . text ,
10
- rootValue ,
11
- contextValue ,
12
- variables ,
13
- ) . then ( ( payload ) => {
14
- if ( payload . errors ) {
15
- throw new Error ( payload . errors ) ;
16
- }
17
-
18
- return payload ;
19
- } ) ;
20
- }
3
+ import createFetch from './createFetch' ;
21
4
22
- return NetworkBase . create ( fetchQuery ) ;
5
+ export default {
6
+ create ( options ) {
7
+ return Network . create ( createFetch ( options ) ) ;
23
8
} ,
24
9
} ;
Original file line number Diff line number Diff line change
1
+ import { graphql } from 'graphql' ;
2
+
3
+ export default function createFetch ( { schema, rootValue, contextValue } ) {
4
+ return function fetchQuery ( operation , variables ) {
5
+ return graphql (
6
+ schema ,
7
+ operation . text ,
8
+ rootValue ,
9
+ contextValue ,
10
+ variables ,
11
+ ) . then ( ( payload ) => {
12
+ if ( payload . errors ) {
13
+ throw new Error ( payload . errors ) ;
14
+ }
15
+
16
+ return payload ;
17
+ } ) ;
18
+ } ;
19
+ }
Original file line number Diff line number Diff line change
1
+ export createFetch from './createFetch' ;
1
2
export Network from './Network' ;
You can’t perform that action at this time.
0 commit comments