entria / ReactNavigationRelayModern

React Navigation integration with Relay
173 stars 23 forks source link

Remote server configuration #8

Closed shahankit closed 7 years ago

shahankit commented 7 years ago

In your demo app where and how should I do Remote server initialization. In previous Relay there was a call in react-relay for this: Relay.injectNetworkLayer. Can you please provide example with remote server configuration.

sibelius commented 7 years ago

it is much simple in Relay Modern

check the remote server configuration here: https://github.com/sibelius/ReactNavigationRelayModern/blob/master/src/createRelayEnvironment.js#L14

// Define a function that fetches the results of an operation (query/mutation/etc)
// and returns its results as a Promise:
function fetchQuery(operation, variables, cacheConfig, uploadables) {
  return fetch('http://localhost:5000/graphql', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    }, // Add authentication and other headers here
    body: JSON.stringify({
      query: operation.text, // GraphQL text from input
      variables,
    }),
  }).then(response => {
    return response.json();
  });
}
shahankit commented 7 years ago

@sibelius Thanks for reply. Do I need separate fetch function for mutation or the same fetchQuery works for both query and mutation?

sibelius commented 7 years ago

the same fetchQuery

https://facebook.github.io/relay/docs/network-layer.html

shahankit commented 7 years ago

Okay thanks On Thu, 4 May 2017 at 6:04 PM, Sibelius Seraphini notifications@github.com wrote:

the same fetchQuery

https://facebook.github.io/relay/docs/network-layer.html

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sibelius/ReactNavigationRelayModern/issues/8#issuecomment-299172077, or mute the thread https://github.com/notifications/unsubscribe-auth/AEhSn9Dx4IOjMNyisaK-HlI0zpL5_LkGks5r2cXSgaJpZM4NQVB7 .