Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
const errorLink = 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}`)
}
})
const link = errorLink.concat(split(
({ query }) => {
const definition = getMainDefinition(query)
return definition.kind === 'OperationDefinition' && definition.operation === 'subscription'
},
wsLink,
httpLink
))
const apolloClient = new ApolloClient({
cache: new InMemoryCache(),
defaultOptions: {
query: { fetchPolicy: 'network-only' },
watchQuery: { fetchPolicy: 'network-only' }
},
link
})
uri: `${APP_SERVER}/subscriptions`,
options: {
reconnect: true,
lazy: true,
connectionParams: async () => {
const token = await getToken();
return {
headers: {
authorization: token ? `Bearer ${token}` : '',
},
};
},
},
});
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLink,
authLink.concat(httpLink),
);
const client = new ApolloClient({
link,
cache,
onError: e => console.log(e),
});
export default client;
headers: {
authorization: token ? `Bearer ${token}` : null,
},
});
const wsLink = new WebSocketLink({
uri: `ws://${API_ROOT}`,
options: {
reconnect: true,
connectionParams: {
authToken: token,
},
},
});
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === "OperationDefinition" && operation === "subscription";
},
wsLink,
httpLinkWithAuthToken,
);
const client = new ApolloClient({
link,
cache: new InMemoryCache({
dataIdFromObject: object => object.id,
}),
});
ReactDOM.render(
headers: {
...context.headers,
authorization: localStorage.getItem('token')
}
}))
return forward(operation)
})
const httpAuthLink = authLink.concat(httpLink)
const wsLink = new WebSocketLink({
uri: `ws://localhost:4000/graphql`,
options: { reconnect: true }
})
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query)
return kind === 'OperationDefinition' && operation === 'subscription'
},
wsLink,
httpAuthLink
)
const client = new ApolloClient({
cache,
link
})
render(