How to use the react-relay-network-modern/node8.cacheMiddleware 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 artsy / reaction / src / Artsy / Relay / createRelaySSREnvironment.ts View on Github external
if (req.id === "SearchBarSuggestQuery" && req.variables.term === "")
          return Promise.resolve({ data: { viewer: {} } })
        return next(req)
      },
      urlMiddleware({
        url: METAPHYSICS_ENDPOINT,
        headers: !!user
          ? {
              ...headers,
              "X-USER-ID": user && user.id,
              "X-ACCESS-TOKEN": user && user.accessToken,
            }
          : headers,
      }),
      relaySSRMiddleware.getMiddleware(),
      cacheMiddleware({
        size: 100, // max 100 requests
        ttl: 900000, // 15 minutes
        onInit: queryResponseCache => {
          if (!isServer) {
            hydrateCacheFromSSR(queryResponseCache)
          }
        },
      }),

      // TODO: This has been moved over from `Utils/metaphysics` but can eventually
      // be replaced by error / retry middleware
      next => async req => {
        const response = await next(req)
        if (!checkStatus || (response.status >= 200 && response.status < 300)) {
          return response
        } else {