How to use the relay-runtime.Network.create 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 yusinto / relay-compiler-plus / example / src / client / relayEnvironment.js View on Github external
method: 'POST',
    headers: {
      // Add authentication and other headers here
      'content-type': 'application/json'
    },
    body: JSON.stringify({
      queryId: operation.id,
      variables,
    }),
  }).then(response => {
    return response.json();
  });
}

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

export default environment;
github OpenCTI-Platform / opencti / opencti-front / src / relay / environment.js View on Github external
const subscriptionClient = new SubscriptionClient(
    `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;
github relay-tools / relay-hooks / examples / relay-example / todo / js / app.js View on Github external
const response = await fetch('/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      query: operation.text,
      variables,
    }),
  });

  return response.json();
}

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

const rootElement = document.getElementById('root');




if (rootElement) {
  ReactDOM.render(
github zeit / next.js / examples / with-relay-modern / 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 gsasouza / house-automation / packages / web / src / relay / environment.ts View on Github external
const response = await fetch(GRAPHQL_URL, {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
      Authorization: getAccessToken(),
    },
    body: JSON.stringify({
      query: operation.text,
      variables,
    }),
  });
  return await response.json();
};

const network = Network.create(RelayNetworkLogger.wrapFetch(fetchQuery, () => ''), setupSubscription);

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

const env = new Environment({
  network,
  store,
});

export default env;
github relay-tools / relay-compiler-language-typescript / example-hooks / ts / app.tsx View on Github external
return fetch("/graphql", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query: operation.text,
      variables,
    }),
  }).then(response => {
    return response.json()
  })
}

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

ReactDOM.render(
  
    
  ,
  mountNode,
)
github hung-phan / koa-react-isomorphic / app / share / helpers / createApi.js View on Github external
export default () => {
  const fetcher = createFetcher();
  const environment = new Environment({
    network: Network.create(fetcher.fetch.bind(fetcher)),
    store: new Store(new RecordSource())
  });
  const resolver = new Resolver(environment);

  return {
    environment,
    resolver,
    fetcher,
    historyMiddlewares: [queryMiddleware],
    fetchQuery: fetchQuery.bind(undefined, environment),
    commitMutation: commitMutation.bind(undefined, environment),
    commitLocalUpdate: commitLocalUpdate.bind(undefined, environment)
  };
};
github kiwicom / mobile / packages / relay / src / Environment.js View on Github external
networkHeaders[authHeaderKey] = accessToken;
  }

  const fetchQuery = (operation, variables): Promise => {
    return Observable.create(observer => {
      if (operation.operationKind !== 'mutation') {
        asyncStoreRead(observer, operation, variables);
      }
      if (ConnectionManager.isConnected()) {
        fetchFromTheNetwork(networkHeaders, operation, variables, observer);
      }
    });
  };

  return new Environment({
    network: Network.create(fetchQuery),
    store,
  });
}
github taion / relay-todomvc / src / router.js View on Github external
export function createResolver(fetcher) {
  const environment = new Environment({
    network: Network.create((...args) => fetcher.fetch(...args)),
    store: new Store(new RecordSource()),
  });

  return new Resolver(environment);
}
github thibaultboursier / nextjs-with-relay-modern / relay / environment.js View on Github external
export const initEnvironment = ({ records = {} } = {}) => {
  const network = Network.create(fetchQuery);
  const store = new Store(new RecordSource(records));

  if (!process.browser) {
    return new Environment({
      network,
      store
    });
  }

  if (!environment) {
    environment = new Environment({
      network,
      store
    });
  }