How to use the react-relay.injectNetworkLayer function in react-relay

To help you get started, we’ve selected a few react-relay 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 eyston / relay-composite-network-layer / test / index.js View on Github external
});
    }
    return this.layer.sendMutation(mutationRequest);
  }

  supports(...options) {
    return this.layer.supports(...options);
  }
}

const withLogging = (name, layer) => {
  return new RelayLoggingNetworkLayer(name, layer);
}

// SUT
Relay.injectNetworkLayer(withLogging('composite', new RelayCompositeNetworkLayer({
  ...config,
  layers: {
    server: withLogging('server', new RelayLocalSchema.NetworkLayer({schema: serverSchema})),
    local: withLogging('local', new RelayLocalSchema.NetworkLayer({schema: localSchema}))
  }
})));

describe('RelayCompositeNetworkLayer', () => {

  it('it can query a single schemas', async () => {

    const node = Relay.QL`
      query {
        viewer {
          name
        }
github blackwall-eng / mobile / src / root.js View on Github external
render() {

    const { token } = this.state;

    if (token) {
      const config = {
        fetchTimeout: 5000,   // Timeout after 5s.
        retryDelays: [1000, 3000, 5000, 15000, 30000],   // Retry after 1s, 3s, 5s, 15s and 30s
        headers: {
          Authorization: `Bearer ${token}`
        }
      };

      Relay.injectNetworkLayer(
        new LoggingNetworkLayer('https://api.blackwall.co/backend/cerebro/graphql', config)
        //new LoggingNetworkLayer('http://localhost:3000/graphql', config)
      );

      const renderApp = ({done, error, props, retry, stale}) => {
        if (error) {
          console.log('error', error);
          return ;
        } else if (props) {
          return ;
        } else {
          return ;
        }
      }

      return (
github ticruz38 / Ambrosia / client / desktop.js View on Github external
import StartSubmit from './components/start/submit';
import Board from './components/board/board';
import BoardTimeLine from './components/board/timeline';
import BoardCardIndex from './components/board/cardindex';
import BoardCard from './components/board/card';
import BoardSettings from './components/board/settings';
import Ordering from './components/ordering';
import Profile from './components/profile';
import React from 'react';
import ReactDom from 'react-dom';
import {createHistory} from 'history';
import Relay from 'react-relay';
// import rootQuery from '../indexroute.js';
import { RelayRouter } from 'react-router-relay';

Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer('/graphql', {
    credentials: 'same-origin'
  })
);

const ViewerQuery = {
  user: () => Relay.QL `query { root }`
};

const RestaurantQuery = {
  restaurant: () => Relay.QL `query {root (id: $id)}`
};

const RestaurantsQuery = {
  restaurant: () => Relay.QL `query {root}`
};
github lenaten / react-native-relay / index.ios.js View on Github external
/* @flow */
'use strict';

import React from 'react-native';
import Relay from 'react-relay';
import FixApp from './src/components/FixApp';
import ViewerRoute from './src/routes/ViewerRoute';
import config from './config';

Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer(config.graphqlURL)
);

var {
  AppRegistry,
} = React;

class fix extends React.Component {
  render() {
    var viewerRoute = new ViewerRoute();
    return (
        
    );
github youshido-php / GraphQL / examples / js-relay / js / app.js View on Github external
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import Relay from 'react-relay';
import StarWarsApp from './components/StarWarsApp';
import StarWarsAppHomeRoute from './routes/StarWarsAppHomeRoute';

// for PHP tests
Relay.injectNetworkLayer(
    new Relay.DefaultNetworkLayer('http://localhost:8000/graphql')
);

ReactDOM.render(
    ,
    document.getElementById('root')
);
github mattias800 / react-native-relay-facebook-neo4j-starter-kit / app / src / network / RelayNetworkConfig.js View on Github external
import Relay from "react-relay";
import {EnhancedRelayNetworkLayer} from "./EnhancedRelayNetworkLayer";
import {graphqlEndpoint} from "../config/ServerEndpoint";

let authTokenUsedByRelay = undefined;
let currentUserId = undefined;

console.log(`Using GraphQL endpoints: ${graphqlEndpoint}`);

Relay.injectNetworkLayer(new EnhancedRelayNetworkLayer(
    graphqlEndpoint,
    undefined,
    () => Promise.resolve({authentication: authTokenUsedByRelay}))
);

export function setRelaySession(token: string, userId: string) {
    authTokenUsedByRelay = token;
    currentUserId = userId;
}

export function clearRelaySession() {
    authTokenUsedByRelay = undefined;
    currentUserId = undefined;
}

export function getAuthTokenUsedByRelay() {
github vslinko / ripster / src / frontend / initApp.js View on Github external
export default async function initApp() {
  try {
    Relay.injectNetworkLayer(
      new Relay.DefaultNetworkLayer('/graphql', {
        credentials: 'same-origin',
      })
    );

    const store = createStore();

    await store.dispatch(init());

    const history = createHistory();
    syncReduxAndRouter(history, store);

    const component = (
github artsy / reaction / src / Relay / config.ts View on Github external
export function artsyRelayEnvironment() {
  Relay.injectNetworkLayer(artsyNetworkLayer())
}
github reindexio / reindex-examples / react-native-gallery / Main.js View on Github external
import Reindex from 'reindex-js';
import { fromCallback } from 'bluebird';

import Auth0Lock from 'react-native-lock';
import Spinner from 'react-native-loading-spinner-overlay';

import Config from './config';
import { STREAM_ROUTE } from './Routes';
import SceneWrapper from './routes/SceneWrapper';
import AddPictureRoute from './routes/AddPictureRoute';
import PictureRoute from './routes/PictureRoute';
import StreamRoute from './routes/StreamRoute';
import MyPicturesRoute from './routes/MyPicturesRoute';

const reindex = new Reindex(Config.REINDEX_URL);
Relay.injectNetworkLayer(reindex.getRelayNetworkLayer());

export default class Main extends Component {
  constructor() {
    super();
    this.state = {
      loading: true,
    };
  }

  componentDidMount() {
    this._checkLogin();
  }

  componentDidUpdate() {
    this._checkLogin();
  }