How to use the react-relay-network-modern.graphqlBatchHTTPWrapper function in react-relay-network-modern

To help you get started, we’ve selected a few react-relay-network-modern examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github relay-tools / react-relay-network-modern / examples / dataLoaderPerBatchRequest.js View on Github external
graphiql: true,
  formatError,
  pretty: true,
  context: {
    request: req, // just for example, pass request to context
    dataLoaders: initDataLoaders(),
  },
});

// Declare route for batch query

// `graphqlBatchHTTPWrapper` and `graphqlHTTP` return arrow functions.
// For performance reasons, declare it once outside (req, res, next) => {} block,
// rather than for every request. Otherwise, it will result in the garbage collector
// being invoked way more than necessary.
const graphqlBatchMiddleware = graphqlBatchHTTPWrapper(
  graphqlHTTP(req => req.graphqlServerSettings)
);
server.use(
  '/graphql/batch', // NB: should be before `server.use('/graphql', ...)`
  bodyParser.json(),
  (req, res, next) => {
    req.graphqlServerSettings = graphqlSettingsPerRequest(req); // eslint-disable-line
    graphqlBatchMiddleware(req, res, next);
  }
);

// Declare standard graphql route
server.use(
  '/graphql', // NB: should be after `server.use('/graphql/batch', ...)`)
  graphqlHTTP(graphqlSettingsPerRequest)
);