split( ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === 'OperationDefinition' && operation === 'subscription'; }, wsLink, httpLink )
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 || {}) }); }
}); apolloClient = new ApolloClient({ link: split( ({ query }) => { const { kind, operation } = getMainDefinition(query);
const apolloClient = new ApolloClient({ link: new ApolloLink((operation, forward) => { return forward(operation).map(response => { const context = operation.getContext(); const { response: { headers }, return response; }); }).concat( createHttpLink({ uri: 'http://localhost:13377/graphql',
.then(oper => request(oper)) .then(() => { handle = forward(operation).subscribe({ next: observer.next.bind(observer), error: observer.error.bind(observer),
const terminatingLink = split( ({ query }) => { const { kind, operation } = getMainDefinition(query); link: ApolloLink.from([errorLink, authLink, terminatingLink]), cache, });
operation.setContext( ( { headers = {} } ) => ( { headers: { "woocommerce-session": `Session ${ session }` } } ) );
operation.setContext(({ headers = {} }) => ({ headers: { ...headers, 'meteor-login-token': getUserToken() } }))
split( ({ query }) => { let definition = getMainDefinition(query); return ( definition.kind === "OperationDefinition" && definition.operation === "subscription" ); }, wsLink, httpLink )
split( ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === "OperationDefinition" && operation === "subscription"; }, wsLink, authLink.concat(httpLink) )
.then(oper => request(oper)) .then(() => { handle = forward(operation).subscribe({ next: observer.next.bind(observer), error: observer.error.bind(observer),
const terminatingLink = split( ({ query }) => { const { kind, operation } = getMainDefinition(query); link: ApolloLink.from([errorLink, authLink, terminatingLink]), cache, });
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, httpLinkWithMiddleware )
split( ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === 'OperationDefinition' && operation === 'subscription'; }, wsLink, httpLink )