function createClient(headers, token, initialState) { let accessToken = token; (async () => { // eslint-disable-next-line no-param-reassign accessToken = token || (await persist.willGetAccessToken()); })(); const authLink = new ApolloLink((operation, forward) => { operation.setContext({ headers: { authorization: accessToken } }); return forward(operation); }).concat(httpLink); return new ApolloClient({ headers, link: authLink, connectToDevTools: process.browser, ssrMode: !process.browser, cache: new InMemoryCache().restore(initialState || {}) }); }
return response; }); }).concat( createHttpLink({ uri: 'http://localhost:13377/graphql',
const requestLink = ({ queryOrMutationLink, subscriptionLink }) => ApolloLink.split( ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === 'OperationDefinition' && operation === 'subscription'; }, subscriptionLink, queryOrMutationLink, )
const queryOrMutationLink = (config = {}) => // turn on CDN support via GET createPersistedQueryLink({ useGETForHashedQueries: true }).concat( new HttpLink({ ...config, credentials: 'same-origin', }) )
ApolloLink.from([ onError(({ graphQLErrors, networkError }) => { if (graphQLErrors) graphQLErrors.map(({ message, locations, path }) => console.log( `[GraphQL error]: Message:, ${message}, Location:, ${locations}, Path:, ${path}`, ), ); if (networkError) console.log(`[Network error]: ${networkError}`); }), new HttpLink({ uri: `http://localhost:${GraphqlPort}/graphql`, }) ])
split( ({ query }) => { const { kind, operation } = getMainDefinition(query) return kind === 'OperationDefinition' && operation === 'subscription' }, wsLink, authLink.concat(httpLink) )
const requestLink = ({ queryOrMutationLink, subscriptionLink }) => ApolloLink.split( ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === 'OperationDefinition' && operation === 'subscription'; }, subscriptionLink, queryOrMutationLink, )
const requestLink = ({ queryOrMutationLink, subscriptionLink }) => ApolloLink.split( ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === 'OperationDefinition' && operation === 'subscription'; }, subscriptionLink, queryOrMutationLink )
split( ({ query }) => { const { kind, operation } = getMainDefinition(query) return kind === 'OperationDefinition' && operation === 'subscription' }, wsLink, authLink.concat(httpLink), )
ApolloLink.from([ apolloLocalStateSetup, onError(({ graphQLErrors, networkError }) => { if (graphQLErrors) graphQLErrors.map(({ message, locations, path }) => console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`), ) if (networkError) console.log(`[Network error]: ${networkError}`) }), new HttpLink({ uri: 'http://localhost:4000', credentials: 'same-origin', }), ])
const requestLink = ({ queryOrMutationLink, subscriptionLink }) => /* This link checks if the operation is a subscription. If it is, we use our subscription link to retrieve data over WebSockets. If it is a query or mutation, we retrieve data over HTTP. */ ApolloLink.split( ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === 'OperationDefinition' && operation === 'subscription'; }, subscriptionLink, queryOrMutationLink )
ApolloLink.from([ onError(({ graphQLErrors, networkError }) => { if (graphQLErrors) graphQLErrors.map(({ message, locations, path }) => console.log( `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`, ), ); if (networkError) console.log(`[Network error]: ${networkError}`); }), new HttpLink({ uri: 'https://us1.prisma.sh/public-luckox-377/reservation-graphql-backend/dev', credentials: 'same-origin' }) ])