<commit_before>/* @flow */
/* eslint better/no-ifs:0, import/no-commonjs:0, fp/no-class:0 */
/* global LEGACY:false, API:false */

import React from 'react';
import Relay from 'react-relay';
import Router from 'react-router-dom/BrowserRouter';
import { stringify } from 'query-string';
import md5 from 'blueimp-md5';

import { viewerQuery } from '@ncigdc/routes/queries';
import {
  RelayNetworkLayer,
  urlMiddleware,
  // batchMiddleware,
  loggerMiddleware,
  gqErrorsMiddleware,
  perfMiddleware,
  retryMiddleware,
} from 'react-relay-network-layer';

const stringifyQuery = (query) => (
  stringify(query, { strict: false })
);

// $FlowIgnore
const Container = LEGACY ? require('./Legacy').default : require('./Portal').default;

// Don't inject everytime file is hot-reloaded
if (!Relay.Store._storeData._networkLayer._implementation) {
  Relay.injectNetworkLayer(
    new RelayNetworkLayer([
      urlMiddleware({
        url: (req) => `${API}graphql`,
      }),
      // batchMiddleware({
      //   batchUrl: (reqestMap) => `${API}graphql/batch`,
      // }),
      loggerMiddleware(),
      gqErrorsMiddleware(),
      perfMiddleware(),
      retryMiddleware({
        fetchTimeout: 15000,
        retryDelays: (attempt) => Math.pow(2, attempt + 4) * 100, // or simple array [3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600],
        forceRetry: (cb, delay) => { window.forceRelayRetry = cb; console.log(`call \`forceRelayRetry()\` for immediately retry! Or wait ${delay} ms.`); },
        statusCodes: [500, 503, 504],
      }),
      // Add hash id to request
      next => req => {
        const hash = md5([req.relayReqObj._printedQuery.text, JSON.stringify(req.relayReqObj._printedQuery.variables)].join(':'));
        req.url = `${req.url}?hash=${hash}`;
        return next(req);
      },
    ])
  );
}

class Route extends Relay.Route {
  static routeName = 'RootRoute';
  static queries = viewerQuery;
}

const Root = (props: mixed) => (<commit_msg>🐛 only append hash to url once (#1584)<commit_after>/* @flow */
/* eslint better/no-ifs:0, import/no-commonjs:0, fp/no-class:0 */
/* global LEGACY:false, API:false */

import React from 'react';
import Relay from 'react-relay';
import Router from 'react-router-dom/BrowserRouter';
import { stringify, parse } from 'query-string';
import md5 from 'blueimp-md5';

import { viewerQuery } from '@ncigdc/routes/queries';
import {
  RelayNetworkLayer,
  urlMiddleware,
  // batchMiddleware,
  loggerMiddleware,
  gqErrorsMiddleware,
  perfMiddleware,
  retryMiddleware,
} from 'react-relay-network-layer';

const stringifyQuery = (query) => (
  stringify(query, { strict: false })
);

// $FlowIgnore
const Container = LEGACY ? require('./Legacy').default : require('./Portal').default;

// Don't inject everytime file is hot-reloaded
if (!Relay.Store._storeData._networkLayer._implementation) {
  Relay.injectNetworkLayer(
    new RelayNetworkLayer([
      urlMiddleware({
        url: (req) => `${API}graphql`,
      }),
      // batchMiddleware({
      //   batchUrl: (reqestMap) => `${API}graphql/batch`,
      // }),
      loggerMiddleware(),
      gqErrorsMiddleware(),
      perfMiddleware(),
      retryMiddleware({
        fetchTimeout: 15000,
        retryDelays: (attempt) => Math.pow(2, attempt + 4) * 100, // or simple array [3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600],
        forceRetry: (cb, delay) => { window.forceRelayRetry = cb; console.log(`call \`forceRelayRetry()\` for immediately retry! Or wait ${delay} ms.`); },
        statusCodes: [500, 503, 504],
      }),
      // Add hash id to request
      next => req => {
        const [url, search = ''] = req.url.split('?');
        const hash = parse(search).hash || md5([
          req.relayReqObj._printedQuery.text,
          JSON.stringify(req.relayReqObj._printedQuery.variables),
        ].join(':'));

        req.url = `${url}?hash=${hash}`; // eslint-disable-line no-param-reassign, fp/no-mutation
        return next(req);
      },
    ])
  );
}

class Route extends Relay.Route {
  static routeName = 'RootRoute';
  static queries = viewerQuery;
}

const Root = (props: mixed) => (
{'fraction_non_alphanumeric': 0.15855421686746987, 'fraction_numerical': 0.0327710843373494, 'mean_word_length': 3.2574358974358972, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3005800', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1348, 'n_words': 306}