0.6.3 • Published 6 years ago

relay-local-schema-nodonisko v0.6.3

Weekly downloads
5
License
CC0-1.0
Repository
github
Last release
6 years ago

Relay Local Schema Travis npm

Use Relay without a GraphQL server.

Discord

Usage

Relay Modern

import { Environment } from 'react-relay';
import { Network } from 'relay-local-schema';

import schema from './data/schema';

const environment = new Environment({
  network: Network.create({ schema }),
  /* ... */
});

This will execute queries against the specified schema locally, rather than against a separate GraphQL server.

You can also specify a GraphQL.js rootValue or contextValue:

const environment = new Environment({
  network: Network.create({
    schema,
    rootValue: 'foo',
    contextValue: 'bar',
  }),
  /* ... */
});

For more control over the network layer, you can use createFetch to create just the fetch function.

import { Environment, Network } from 'react-relay';
import { createFetch } from 'relay-local-schema';

import schema from './data/schema';

const environment = new Environment({
  network: Network.create(createFetch({ schema })),
  /* ... */
});

Relay Classic

import RelayLocalSchema from 'relay-local-schema/lib/classic';

import schema from './data/schema';

Relay.injectNetworkLayer(
  new RelayLocalSchema.NetworkLayer({ schema })
);

This will execute queries against the specified schema locally, rather than against a separate GraphQL server.

You can also supply a GraphQL.js rootValue or contextValue, or an onError callback:

Relay.injectNetworkLayer(
  new RelayLocalSchema.NetworkLayer({
    schema,
    rootValue: 'foo',
    contextValue: 'bar',
    onError: (errors, request) => console.error(errors, request),
  })
);

Caveat

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 GraphQL back end in production.