How to use the react-relay-network-modern.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 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__
github sensu / sensu-go / dashboard / src / environment.js View on Github external
import {
  RelayNetworkLayer,
  loggerMiddleware,
  errorMiddleware,
  perfMiddleware,
  retryMiddleware,
  authMiddleware,
} from "react-relay-network-modern";
import { getAccessToken } from "./utils/authentication";

// Create a record source & instantiate store
const source = new RecordSource();
const store = new Store(source);

// Create a network layer from the fetch function
const network = new RelayNetworkLayer([
  ...(process.env.NODE_ENV !== "production"
    ? [loggerMiddleware(), errorMiddleware(), perfMiddleware()]
    : []),
  authMiddleware({
    token: getAccessToken,
  }),
  retryMiddleware({
    statusCodes: code => code >= 200 && code < 400,
  }),
]);

// Create an environment using this network:
const environment = new Environment({
  network,
  source,
  store,
github OpenCTI-Platform / opencti / opencti-platform / opencti-front / src / relay / environment.js View on Github external
const loc = window.location;
  const isSecure = loc.protocol === 'https:' ? 's' : '';
  const subscriptionClient = new SubscriptionClient(
    `ws${isSecure}://${loc.host}${APP_BASE_PATH}/graphql`,
    {
      reconnect: true,
    },
  );
  const subscriptionLink = new WebSocketLink(subscriptionClient);
  networkSubscriptions = (operation, variables) => execute(subscriptionLink, {
    query: operation.text,
    variables,
  });
}

const network = new RelayNetworkLayer(
  [
    urlMiddleware({
      url: `${APP_BASE_PATH}/graphql`,
      credentials: 'same-origin',
    }),
    uploadMiddleware(),
  ],
  { subscribeFn: networkSubscriptions },
);

const store = new Store(new RecordSource());
// Activate the read from store then network
// store.holdGC();
export const environment = new Environment({
  network,
  store,
github damassi / isomorphic-relay-app / relay-modern / src / lib / isomorphic-relay / getRelayEnvironment.js View on Github external
import 'regenerator-runtime/runtime'
import { Environment, RecordSource, Store } from 'relay-runtime'
import RelayServerSSR from 'react-relay-network-modern-ssr/lib/server'
// import schema from '../../../../graphql/metaphysics/data/schemaj'

// const relayServerSSR = new RelayServerSSR()

import {
  RelayNetworkLayer,
  urlMiddleware,
  // loggerMiddleware,
  // gqlErrorsMiddleware,
  // perfMiddleware,
} from 'react-relay-network-modern'

const network = new RelayNetworkLayer([
  urlMiddleware({ url: process.env.METAPHYSICS_BASE_URL }),
  // relayServerSSR.getMiddleware({
  //   schema,
  //   contextValue: {},
  // }),
  // loggerMiddleware(),
  // gqlErrorsMiddleware({
  //   disableServerMiddlewareTip: true,
  // }),
  // perfMiddleware(),
])

let environment

export function getRelayEnvironment(records) {
  if (environment) {
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()),
  });
}
github BadrIT / bractal / src / modules / core / utils / relayHelpers / RelayProvider.js View on Github external
type: AlertTypes.error,
                });

                this.props.saveCurrentPath(PathRedirectKeysMapper.showSuccess);
                this.props.invalidateUser();
                navigateToModal(this.props.history, '/accountManagement/login');
              }
            }
          }
        }

        return response;
      },
    ];

    const network = new RelayNetworkLayer(middlewaresArray);

    return network;
  };