How to use the react-relay-network-modern/node8.RelayNetworkLayer 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
* See https://bugs.chromium.org/p/chromium/issues/detail?id=571722
     */
    "User-Agent": USER_AGENT,
  }

  let timeZone
  try {
    timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
    headers["X-TIMEZONE"] = timeZone
  } 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,
            }
github Bastiani / bastiani-blog / lib / createEnvironment / client.ts View on Github external
createEnvironment: (relayData: any) => {
    if (storeEnvironment) {
      return storeEnvironment;
    }

    storeEnvironment = new Environment({
      store,
      network: new RelayNetworkLayer([
        cacheMiddleware({
          size: 100,
          ttl: 60 * 1000
        }),
        new RelaySSR(relayData).getMiddleware({
          lookup: false
        }),
        urlMiddleware({
          url: () => ''
        }),
        next => async req => {
          req.fetchOpts.headers.Authorization = relayData
            ? relayData.token
            : '';
          const res = await next(req);
          return res;
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(),
github zeit / next.js / examples / with-react-relay-network-modern / lib / createEnvironment / client.js View on Github external
createEnvironment: relayData => {
    if (storeEnvironment) return storeEnvironment

    storeEnvironment = new Environment({
      store,
      network: new RelayNetworkLayer([
        cacheMiddleware({
          size: 100,
          ttl: 60 * 1000,
        }),
        new RelaySSR(relayData).getMiddleware({
          lookup: false,
        }),
        urlMiddleware({
          url: req => process.env.RELAY_ENDPOINT,
        }),
      ]),
    })

    return storeEnvironment
  },
}
github zeit / next.js / examples / with-react-relay-network-modern / lib / createEnvironment / server.js View on Github external
initEnvironment: () => {
    const source = new RecordSource()
    const store = new Store(source)
    const relaySSR = new RelaySSR()

    return {
      relaySSR,
      environment: new Environment({
        store,
        network: new RelayNetworkLayer([
          urlMiddleware({
            url: req => process.env.RELAY_ENDPOINT,
          }),
          relaySSR.getMiddleware(),
        ]),
      }),
    }
  },
  createEnvironment: (relayData, key) => {
github Bastiani / bastiani-blog / lib / createEnvironment / server.ts View on Github external
initEnvironment: () => {
    const source = new RecordSource();
    const store = new Store(source);
    const relaySSR = new RelaySSR();

    return {
      relaySSR,
      environment: new Environment({
        store,
        network: new RelayNetworkLayer([
          urlMiddleware({
            url: () =>
              process.env.RELAY_ENDPOINT_SERVER ||
              'http://localhost:3000/graphql'
          }),
          relaySSR.getMiddleware()
        ])
      })
    };
  },
  createEnvironment: (relayData: any, key: any) => {