Use Relay without a GraphQL server.
Use RelayLocalSchema.NetworkLayer
to execute GraphQL queries locally, rather than against a separate GraphQL server.
This is intended for exploratory work, integration tests, demos, and working with local data. This is not generally intended as a substitute for a remote backend, except possibly when using local data as a persistent cache.
import RelayLocalSchema from 'relay-local-schema';
import schema from './data/schema';
Relay.injectNetworkLayer(
new RelayLocalSchema.NetworkLayer({ schema })
);
You can also supply a GraphQL.js rootValue
or an onError
callback to the
constructor:
Relay.injectNetworkLayer(
new RelayLocalSchema.NetworkLayer({
schema,
rootValue: 'foo',
onError: (errors, request) => console.error(errors, request),
})
);