Questions tagged [apollo-link]
34 questions
21
votes
1 answer
How to correctly redirect after catching authentication failure with Apollo and React
I'm writing a react app that uses apollo-client and I'm using apollo-link-error to catch authentication errors globally. I'm using createBrowserHistory for browser history manipulation and redux to manage my app state.
On authentication error I want…

bpylearner
- 507
- 4
- 12
7
votes
1 answer
Multiple ApolloLink based on context
I want to implement a way to switch over different links based on the context set in graphql query. What I did so far is something like this which is working fine but doesn't seem to be a nice solution over time.
const link = ApolloLink.from([
…

Siamak Motlagh
- 5,028
- 7
- 41
- 65
5
votes
7 answers
`Cannot use e "__Schema" from another module or realm.` and `Duplicate "graphql" modules` using ApolloClient
I have a React application with ApolloClient with Apollo-Link-Schema. The application works fine locally but in our staging environment (using GOCD), we get the following error:
Uncaught Error: Cannot use e "__Schema" from another module or…

laij84
- 261
- 2
- 8
5
votes
1 answer
Handling firebase initialization delay and id tokens for custom apollo graphql backend
Currently, when I authenticate a user with firebase, I store their auth token in localStorage to be used later to connect to my backend like so:
const httpLink = new HttpLink({uri: 'http://localhost:9000/graphql'})
const authMiddleware = new…

Davis Mariotti
- 574
- 1
- 4
- 23
4
votes
1 answer
Chaining apollo retryLink and errorLink
Should Apollo retryLink come before or after the errorLink? Some examples show it as before https://medium.com/@joanvila/productionizing-apollo-links-4cdc11d278eb#3249 while some show it after…

sguha
- 2,057
- 1
- 22
- 36
4
votes
0 answers
Updating dynamically endpoint used by Apollo client
Is there a way to dynamically change the URI used by the client retrieved with getTenantEndpoint?
const httpLink = new HttpLink({
uri: `${getTenantEndpoint()}/graphql`,
fetch
});
const authMiddleware = new ApolloLink(
(operation: Operation,…

dbrrt
- 2,275
- 4
- 18
- 35
4
votes
0 answers
How to solve Apollo subscriptions "Error during WebSocket handshake: Unexpected response code: 400"
I have a legacy application working with React and subscribing to a GraphQL backend. Today, I upgraded all my packages especially thoses (I suppopse that they are the origin of my problem but I'm not sure):
react-apollo from ^2.4.0 to…

Ala Eddine JEBALI
- 7,033
- 6
- 46
- 65
4
votes
1 answer
How to dynamically change Apollo Web Socket Link URI?
Currently I've set up Apollo's web socket link like so:
const wsLink = new WebSocketLink({
uri: `ws://example.com/graphql?token=${getToken()}`,
options: {
reconnect: true,
connectionParams(): ConnectionParams {
return {
…

aryzing
- 4,982
- 7
- 39
- 42
3
votes
1 answer
Use apollo-link to fetch a query upon any mutation
I am working on an application where there are projects with a nested tree of assets. In the backend, the changed-date of the project is updated when one of the children of grandchildren (or grand-grand-children) is updated.
In react-apollo, I have…

ErikRtvl
- 326
- 1
- 7
3
votes
0 answers
Pass context from useQuery to Apollo client
I'm building an next.js app in which I intend to consume several graphql-apis. I would like to pass a context when using the useQuery from @apollo/react-hooks in my components. At the moment my client looks like this:
import { ApolloClient } from…

N1mbus
- 61
- 1
- 5
2
votes
1 answer
How to Fix Bug in Apollo-link for GraphQL Error
In here, I can both graphQLErrors and networkError:
const errorLink = onError(({ operation, graphQLErrors, networkError, forward }) => {
if (process.env.NODE_ENV !== 'production') {
if (networkError) {
console.log(`[Network…

Mohammad Fallah
- 976
- 11
- 14
2
votes
2 answers
refresh token for angular using graphql and apollo client
I'm trying to set up a refresh token strategy to refresh JWT in angular 9 with GraphQL and apollo client when my first request returns a 401.
I have set up a new angular module for graphql where I'm creating my apolloclient. Everything works great…

Blair Holmes
- 1,521
- 2
- 22
- 35
2
votes
2 answers
How to return error response in apollo link?
I'm using apollo link in schema stitching as an access control layer. I'm not quite sure how to make the link return error response if a user does not have permissions to access a particular operation. I know about such packages as graphql-shield…

Le garcon
- 7,197
- 9
- 31
- 46
1
vote
0 answers
Error: Cannot use namespace 'Observable' as a type. (apollo-link, typescript)
i am trying to create a graphql subcription with hasura, follow this example: Boilerplate to test GraphQL subscriptions using nodejs, just added types for trypescript, if i run it directly with nodemon works fine, and gets me the data i want but if…

Solus
- 31
- 2
1
vote
1 answer
How to catch errors with ApolloProvider globally
I'm trying to catch all my graphQLErrors with the onError method from apollo client.
My goal is to have only one catch block for all of my API calls.
const errorLink = onError(({ graphQLErrors, networkError ,operation}) => {
if (graphQLErrors &&…

Ar26
- 949
- 1
- 12
- 29