How to use the react-relay-network-modern/node8.urlMiddleware 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
} catch (error) {
    console.warn("Browser does not support i18n API, not setting TZ header.")
  }

  const network =
    relayNetwork ||
    new RelayNetworkLayer([
      // TODO: Better introspection around if this is a SearchBar query,
      // or further refactoring to extract `addMiddlewareToEnvironment(environment)`,
      // to be used in the SearchBar QueryRenderer (for example).
      next => req => {
        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)
github artsy / emission / src / lib / relay / createEnvironment.ts View on Github external
export default function createEnvironment() {
  const network = new RelayNetworkLayer([
    cacheMiddleware(),
    urlMiddleware({
      url: metaphysicsURL,
      headers: {
        "Content-Type": "application/json",
        "User-Agent": Emission.userAgent,
        "X-USER-ID": Emission.userID,
        "X-ACCESS-TOKEN": Emission.authenticationToken,
        "X-TIMEZONE": Constants.LocalTimeZone,
      },
    }),
    loggerMiddleware(),
    errorMiddleware({
      disableServerMiddlewareTip: true,
    }),
    metaphysicsExtensionsLoggerMiddleware(),
    timingMiddleware(),
  ])