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.
88### Relay Modern
99
1010``` js
11+ import { Environment } from ' react-relay' ;
1112import { Network } from ' relay-local-schema' ;
1213
1314import schema from ' ./data/schema' ;
@@ -33,6 +34,20 @@ const environment = new Environment({
3334});
3435```
3536
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+
3651### Relay Classic
3752
3853``` 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' ;
32
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' ;
214
22- return NetworkBase . create ( fetchQuery ) ;
5+ export default {
6+ create ( options ) {
7+ return Network . create ( createFetch ( options ) ) ;
238 } ,
249} ;
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' ;
12export Network from './Network' ;
You can’t perform that action at this time.
0 commit comments