const Client = () => { const networkInterface = createNetworkInterface({ uri: 'http://localhost:8080/graphql' }) const client = new ApolloClient({ networkInterface }); return ( <ApolloProvider client={client}> <App /> </ApolloProvider>) }
createClient() { return new ApolloClient({ networkInterface: createNetworkInterface({ uri: 'http://api.githunt.com/graphql' }), // Inform Apollo about the id field of our objects. // Apollo will use this field as the key for its caches. dataIdFromObject: o => o.id }); }
function create (initialState) { return new ApolloClient({ initialState, ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once) networkInterface: createNetworkInterface({ uri: 'http://localhost:4000/graphql', // Server URL (must be absolute) opts: { // Additional fetch() options like `credentials` or `headers` credentials: 'same-origin' } }) }) }
var getClient = function getClient(_ref) { var client = _ref.client, clientOptions = _ref.clientOptions; if (client) return client; if (clientOptions) { var networkInterface = clientOptions.networkInterface, uri = clientOptions.uri, options = (0, _objectWithoutProperties3.default)(clientOptions, ['networkInterface', 'uri']); if (networkInterface) { if (networkInterface && uri) { console.error('Warning: You specified a networkInterface and an uri option. uri will be ignored.'); } return new _apolloClient.ApolloClient((0, _extends3.default)({}, options, { networkInterface: networkInterface })); } if (!networkInterface && uri) { options.networkInterface = (0, _apolloClient.createNetworkInterface)({ uri: uri }); } return new _apolloClient.ApolloClient(options); } return new _apolloClient.ApolloClient(); }
createNetworkInterface({ uri: _.get(process.env, "REACT_APP_GRAPHQL_URL") || "http://localhost:4000/graphql", dataIdFromObject: object => object.id })
const _initNetworkInterface = graphql_url => { const networkInterface = createNetworkInterface({ uri: graphql_url, opts: { credentials: 'same-origin' } }) // Authen networkInterface.use([{ applyMiddleware(req, next) { if (!req.options.headers) { req.options.headers = {} // Create the header object if needed. } // get the authentication token from local storage if it exists (async () => { const token = await persist.willGetSessionToken() req.options.headers.authorization = token ? `Bearer ${token}` : null next() })() }