relay-runtime
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/relay-runtime package

16.2.0 • Public • Published

Relay Runtime

A set of Relay APIs responsible for data fetching, reading and normalization of the GraphQL data.

Example:

// @flow strict-local

import type {FetchFunction} from 'relay-runtime';

const {
  Environment,
  Network,
  Observable,
  RecordSource,
  Store,
  fetchQuery,
  graphql,
} = require('relay-runtime');

const fetchFn: FetchFunction = function (request, variables) {
  return new Observable.create(source => {
    fetch('/my-graphql-api', {
      method: 'POST',
      body: JSON.stringify({
        text: request.text,
        variables,
      }),
    })
      .then(response => response.json())
      .then(data => source.next(data));
  });
};

const network = Network.create(fetchFn);
const store = new Store(new RecordSource());
const environment = new Environment({
  network,
  store,
});

fetchQuery(
  environment,
  graphql`
    query AppQuery($id: ID!) {
      user(id: $id) {
        name
      }
    }
  `,
  {id: 'my-node-id'},
).subscribe({
  error: error => {
    console.error(error);
  },
  next: data => {
    console.log(data);
  },
});

For complete API reference, visit https://relay.dev/.

Readme

Keywords

Package Sidebar

Install

npm i relay-runtime

Homepage

relay.dev

Weekly Downloads

2,760,010

Version

16.2.0

License

MIT

Unpacked Size

1.81 MB

Total Files

243

Last publish

Collaborators

  • alunyov
  • sugarpirate
  • fb
  • yuzhi
  • kassens
  • xiaobu
  • relay-bot