Miss any of our Open RFC calls?Watch the recordings here! »


1.2.16 • Public • Published


npm version npm downloads npm npm

Custom relay compiler which supports persisted queries :bowtie:

Note: This is still unstable! A stable release is coming soon.


yarn add relay-compiler-plus


  1. Add this npm command to your package.json.

        "relay-compiler-plus""relay-compiler-plus --schema <SCHEMA_FILE_PATH> --src <SRC_DIR_PATH>",

    where <SCHEMA_FILE_PATH> is the path to your schema.graphql or schema.json file.

    This should generate:

    • root query files (*.graphql.js) containing query ids and null query text.
    • A queryMap.json file under <SRC_DIR_PATH>/queryMap.json. This file can be consumed by the server to map the query ids to actual queries.
  2. On the server, use matchQueryMiddleware prior to express-graphql to match queryIds to actual queries. Note that queryMap.json is auto-generated by relay-compiler-plus at step 1.

    import Express from 'express';
    import expressGraphl from 'express-graphql';
    import {matchQueryMiddleware} from 'relay-compiler-plus'; // do this
    import queryMapJson from '../queryMap.json'; // do this
    const app = Express();
      matchQueryMiddleware(queryMapJson), // do this
        schema: graphqlSchema,
        graphiql: true,
  3. On the client, modify your relay network fetch implementation to pass a queryId parameter in the request body instead of a query parameter.

    function fetchQuery(operation, variables,) {
      return fetch('/graphql', {
        method: 'POST',
        headers: {
          'content-type': 'application/json'
        body: JSON.stringify({
          queryId: operation.id, // do this
      }).then(response => {
        return response.json();


Check the example for a fully working demo.