-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graphql subscription? #431
Comments
Hi @justdvl, it does work. Here is an example we have import { ApolloLink, NextLink, Operation } from '@apollo/client/link/core'
import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
import { getMainDefinition, hasDirectives } from '@apollo/client/utilities'
import { createClient } from 'graphql-ws'
import { createHttpLink } from './httpLink'
export class GatewayLink extends ApolloLink {
wsLink: ApolloLink
httpLink: ApolloLink
constructor(env: Envs, clientName: string) {
super()
this.wsLink = new GraphQLWsLink(
createClient({
url: YOUR URL HERE,
lazy: true,
})
)
this.httpLink = createHttpLink({
uri: YOUR URI HERE,
headers: {
'X-Request-From': clientName,
},
})
}
public request(operation: Operation, forward?: NextLink) {
if (hasDirectives(['rest'], operation.query)) {
return forward?.(operation) ?? null
}
const definition = getMainDefinition(operation.query)
if (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
) {
return this.wsLink.request(operation, forward)
}
return this.httpLink.request(operation, forward)
}
} |
@jean9696 It is also worth noting that it is needed to check for
Otherwise I get this:
|
Thank you @jean9696. I assume I need to create 2 instances of GatewayLink, one for each BE service I connect to (as I need to maintain websocket with both services)? Currently I have:
Thanks. |
Hello, it seems your library allows for using
subscriptions-transport-ws
to establish graphql subscription, which is not maintained anymore and is not recommended to be used.Is there a way to make your library work with
graphql-ws
?To be clear, I just want to use
subscription
next to already usingquery
andmutation
using this library. Is there an example how apollo-multi-endpoint-link can be used with graphql subscription?Thank you for any help.
The text was updated successfully, but these errors were encountered: