How to use the react-relay-network-modern/lib/RelayResponse.createFromGraphQL 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-ssr / src / server.js View on Github external
return next => async (r: any) => {
      const req: RelayRequest = r;
      const cacheKey = getCacheKey(req.operation.name, req.variables);

      const cachedResponse = this.cache.get(cacheKey);
      if (cachedResponse) {
        this.log('Get graphql query from cache', cacheKey);
        return RelayResponse.createFromGraphQL(await cachedResponse);
      }

      this.log('Run graphql query', cacheKey);

      const graphqlArgs: SSRGraphQLArgs = isFunction(args) ? await args() : (args: any);
      const hasSchema = graphqlArgs && graphqlArgs.schema;
      const gqlResponse = new Promise(async (resolve, reject) => {
        const timeout = setTimeout(() => {
          reject(new Error('RelayRequest timeout'));
        }, 30000);

        let payload = null;
        try {
          if (hasSchema) {
            payload = await graphql({
              ...graphqlArgs,
github relay-tools / react-relay-network-modern-ssr / src / server.js View on Github external
} else {
            payload = await next(r);
          }

          clearTimeout(timeout);
          resolve(payload);
        } catch (e) {
          clearTimeout(timeout);
          reject(e);
        }
      });
      this.cache.set(cacheKey, gqlResponse);

      const res = await gqlResponse;
      this.log('Recieved response for', cacheKey, inspect(res, { colors: true, depth: 4 }));
      return RelayResponse.createFromGraphQL(res);
    };
  }