graphqlEnvironment.ts 541 B

123456789101112131415161718192021
  1. import {Environment, Network, RecordSource, Store} from 'relay-runtime';
  2. function fetchQuery(operation, variables): Promise<void> {
  3. return fetch('/api/graphql', {
  4. method: 'POST',
  5. headers: {
  6. 'Content-Type': 'application/json',
  7. },
  8. body: JSON.stringify({
  9. query: operation.text,
  10. variables,
  11. }),
  12. }).then((response): Promise<void> => response.json());
  13. }
  14. const environment = new Environment({
  15. network: Network.create(fetchQuery),
  16. store: new Store(new RecordSource()),
  17. });
  18. export default environment;