Skip to content

Instantly share code, notes, and snippets.

@Yassir4
Created October 16, 2022 17:26
Show Gist options
  • Save Yassir4/a2da0bfeac25cae37ce4a627c350e60b to your computer and use it in GitHub Desktop.
Save Yassir4/a2da0bfeac25cae37ce4a627c350e60b to your computer and use it in GitHub Desktop.
Setup multiple graphql endpoint in apollo
//Declare your endpoints
const endpoint1 = new HttpLink({
uri: 'https://api.hashnode.com/graphql',
...
})
const endpoint2 = new HttpLink({
uri: 'endpoint2/graphql',
...
})
//pass them to apollo-client config
const client = new ApolloClient({
link: ApolloLink.split(
operation => operation.getContext().clientName === 'endpoint2',
endpoint2, //if above
endpoint1
)
...
})
//pass client name in query/mutation
useQuery(QUERY, {variables, context: {clientName: 'endpoint2'}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment