How to use the react-relay-network-modern.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 damassi / isomorphic-relay-app / relay-modern-found / src / lib / isomorphic-relay / relayEnvironment.js View on Github external
relaySSRMiddleware.debug = false

  const network = new RelayNetworkLayer([
    relaySSRMiddleware.getMiddleware({
      lookup: true,
    }),
    cacheMiddleware({
      size: 100, // max 100 requests
      ttl: 900000, // 15 minutes
      onInit: cache => {
        // TODO: Handle this cache
        // console.log(cache)
      },
    }),
    urlMiddleware({
      url: process.env.METAPHYSICS_BASE_URL,
    }),
    // loggerMiddleware(),
  ])

  const source = new RecordSource()
  const store = new Store(source)
  const environment = new Environment({
    network,
    store,
  })
  environment.relaySSRMiddleware = relaySSRMiddleware

  return environment
}
github nodkz / relay-northwind-app / src / clientStores / RelayStore.js View on Github external
_createRelayNetworkLayer() {
    return new RelayNetworkLayer(
      [
        // batchMiddleware({
        //   batchUrl: '/graphql/batch',
        //   batchTimeout: 20,
        // }),
        cacheMiddleware({
          size: 100,
          ttl: 15 * 60 * 1000, // 15 minutes
          onInit: cache => (this._cache = cache),
        }),
        urlMiddleware({
          url: this.endpoint,
        }),
        __DEV__ ? loggerMiddleware() : null,
        // __DEV__ ? perfMiddleware() : null,
        !__DEV__
          ? retryMiddleware({
              // [3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, ...],
              retryDelays: attempt => 2 ** (attempt + 4) * 100,
              forceRetry: (cb, delay) => {
                window.forceRelayRetry = cb;
                // eslint-disable-next-line
                console.log(`call 'forceRelayRetry()' for immediately retry! Or wait ${delay} ms.`);
              },
            })
          : null,
        __DEV__ ? gqlErrorsMiddleware() : null,
github damassi / isomorphic-relay-app / relay-modern-found / src / lib / isomorphic-relay / getRelayEnvironment.js View on Github external
export function getRelayEnvironment(records) {
  // if (environment && resolver) {
  //   return {
  //     environment,
  //     resolver,
  //   }
  // }

  const relaySSRMiddleware =
    typeof window === 'undefined'
      ? new RelayServerSSR()
      : new RelayClientSSR(window.relayData)

  const network = new RelayNetworkLayer([
    relaySSRMiddleware.getMiddleware(),
    urlMiddleware({ url: process.env.METAPHYSICS_BASE_URL }),
    // next => async req => {
    //   const res = await next(req)
    //   // Store SSR payloads here
    //   console.log(await RelayResponse.createFromFetch(res))
    //   // console.log('RelayResponse', res)
    // },
    // relayServerSSR.getMiddleware({
    //   schema,
    //   contextValue: {},
    // }),
    // loggerMiddleware(),
    // gqlErrorsMiddleware({
    //   disableServerMiddlewareTip: true,
    // }),
    // perfMiddleware(),
  ])
github damassi / react-relay-network-modern-ssr-example / src / relayEnvironment.js View on Github external
export function createRelayEnvironment(cache) {
  const isServer = typeof window === 'undefined'

  const relaySSRMiddleware = isServer
    ? new RelayServerSSR()
    : new RelayClientSSR(cache)

  relaySSRMiddleware.debug = false

  const network = new RelayNetworkLayer([
    relaySSRMiddleware.getMiddleware(),
    // loggerMiddleware(),
    urlMiddleware({
      url: process.env.GRAPHQL_ENDPOINT,
    }),
  ])

  const source = new RecordSource()
  const store = new Store(source)
  const environment = new Environment({
    network,
    store,
  })
  environment.relaySSRMiddleware = relaySSRMiddleware

  return environment
}
github relay-tools / found-relay / src / createRelayEnvironment.js View on Github external
export default function createRelayEnvironment(relaySsr, url) {
  return new Environment({
    network: new RelayNetworkLayer([
      relaySsr.getMiddleware(),
      urlMiddleware({ url }),
    ]),
    store: new Store(new RecordSource()),
  });
}