How to use the relay-runtime.Store function in relay-runtime

To help you get started, weโ€™ve selected a few relay-runtime 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 tslater / reactnative-relay-offline / relay / Environment.js View on Github external
const {
  Environment,
  Network,
  RecordSource,
  Store,
} = require('relay-runtime')
import '../global'

import { graphql, printSchema } from 'graphql'
import schema from '../graphql/relay-schema/index.js'

// console.log('schemmmas',printSchema(schema))

const store = new Store(new RecordSource())
const network = Network.create((operation, variables) =>
  graphql(schema, operation.text, null, {}, variables)
)

const environment = new Environment({
  network,
  store,
})

export default environment
github kiwicom / mobile / app / relay / src / Environment.js View on Github external
query: operation.text,
        variables,
      }),
    })).json();

    if (!jsonPayload.errors) {
      // always save the valid response (probably not needed during cache "force")
      await cache.set(query, variables, jsonPayload);
    }
    return jsonPayload;
  };

  return new PartialErrorsEnvironment(
    {
      network: Network.create(fetchQuery),
      store: new Store(new RecordSource()),
    },
    onPartialError,
  );
}
github OpenCTI-Platform / opencti / opencti-front / src / relay / environment.js View on Github external
`ws${window.location.protocol === 'https:' ? 's' : ''}://${
      window.location.host
    }/graphql`,
    {
      reconnect: true,
    },
  );
  const subscriptionLink = new WebSocketLink(subscriptionClient);
  networkSubscriptions = (operation, variables) => execute(subscriptionLink, {
    query: operation.text,
    variables,
  });
}
export const environment = new Environment({
  network: Network.create(networkFetch, networkSubscriptions),
  store: new Store(new RecordSource()),
});

// Components
export class QueryRenderer extends Component {
  render() {
    const {
      variables, query, render, managedErrorTypes,
    } = this.props;
    return (
       {
          const { error } = data;
          const types = error ? map(e => e.name, error) : [];
github episodeyang / ml_logger / ml-dash-client / src / data / index.js View on Github external
// Update cache on queries
        if (isQuery && json) {
          cache.set(queryID, variables, json);
        }
        // Clear cache on mutations
        if (isMutation) {
          cache.clear();
        }

        return json;
      });
}

export const modernEnvironment = new Environment({
  network: Network.create(fetchQuery),
  store: new Store(new RecordSource()),
});
github zeit / next.js / examples / with-relay-modern-server-express / lib / createRelayEnvironment.js View on Github external
export default function initEnvironment({ records = {} } = {}) {
  // Create a network layer from the fetch function
  const network = Network.create(fetchQuery)
  const store = new Store(new RecordSource(records))

  // Make sure to create a new Relay environment for every server-side request so that data
  // isn't shared between connections (which would be bad)
  if (typeof window === 'undefined') {
    return new Environment({
      network,
      store,
    })
  }

  // reuse Relay environment on client-side
  if (!relayEnvironment) {
    relayEnvironment = new Environment({
      network,
      store,
    })
github damassi / isomorphic-relay-app / _found-relay / src / lib / isomorphic-relay / getRelayEnvironment.js View on Github external
export function getRelayEnvironment(records) {
  if (environment) {
    return environment
  }

  const source = new RecordSource(records)
  const store = new Store(source)

  environment = new Environment({
    network,
    store,
  })

  return environment
}
github aws-samples / aws-appsync-relay / src / environment.js View on Github external
import { API, graphqlOperation } from 'aws-amplify';
import { Environment, Network, RecordSource, Store } from 'relay-runtime';


function fetchQuery(operation, variables) {
  return API.graphql(graphqlOperation(operation.text, variables));
}

function subscribe(operation, variables) {
  return API.graphql(graphqlOperation(operation.text, variables)).map(({value})=>value);
}

const environment = new Environment({
  network: Network.create(fetchQuery, subscribe),
  store: new Store(new RecordSource()),
});

export default environment;
github artsy / reaction / src / DevTools / RelayStubProvider.ts View on Github external
interface Props {
  relay?: RelayProp
}

export class RelayStubProvider extends Component {
  static propTypes = {
    children: PropTypes.node.isRequired,
    relay: PropTypes.object,
  }

  static defaultProps = {
    relay: {
      environment: new Environment({
        network: Network.create(x => x),
        store: new Store(new RecordSource()),
      }),
      variables: {},
    },
  }

  static childContextTypes = {
    relay: PropTypes.object.isRequired,
  }

  getChildContext() {
    return {
      relay: this.props.relay,
    }
  }

  render() {
github krzysztofzuraw / blog-projects / blog_django_graphql_react_relay / film_ui / src / Environment.js View on Github external
import { Environment, Network, RecordSource, Store } from "relay-runtime";

const store = new Store(new RecordSource());

const network = Network.create((operation, variables) => {
  return fetch("http://127.0.0.1:8000/graphql/", {
    method: "POST",
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      query: operation.text,
      variables
    })
  }).then(response => {
    return response.json();
  });
});