|
@@ -15,6 +15,7 @@ import errorLink from './link/error.ts'
|
|
|
import setAuthorizationLink from './link/setAuthorization.ts'
|
|
|
import testFlagsLink from './link/testFlags.ts'
|
|
|
import getBatchContext from './utils/getBatchContext.ts'
|
|
|
+import getWebsocketContext from './utils/getWebsocketContext.ts'
|
|
|
|
|
|
import type { Operation } from '@apollo/client/core'
|
|
|
import type { FragmentDefinitionNode, OperationDefinitionNode } from 'graphql'
|
|
@@ -49,19 +50,6 @@ const operationIsLoginLogout = (
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-// TODO: Maybe we can also add a generic solution with the query context to exclude operation for batching or
|
|
|
-// run operations over websocket.
|
|
|
-const operationIsFormUpdater = (
|
|
|
- definition: OperationDefinitionNode | FragmentDefinitionNode,
|
|
|
-) => {
|
|
|
- return !!(
|
|
|
- definition.kind === 'OperationDefinition' &&
|
|
|
- definition.operation === 'query' &&
|
|
|
- definition.name?.value &&
|
|
|
- definition.name?.value === 'formUpdater'
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
const requiresBatchLink = (op: Operation) => {
|
|
|
if (!enableBatchLink) return false
|
|
|
|
|
@@ -74,15 +62,19 @@ const httpLink = ApolloLink.split(requiresBatchLink, batchLink, noBatchLink)
|
|
|
|
|
|
const requiresHttpLink = (op: Operation) => {
|
|
|
const definition = getMainDefinition(op.query)
|
|
|
+
|
|
|
+ const websocketContext = getWebsocketContext(op)
|
|
|
+
|
|
|
if (!enableQueriesOverWebsocket) {
|
|
|
// Only subscriptions over websocket.
|
|
|
return (
|
|
|
!(
|
|
|
definition.kind === 'OperationDefinition' &&
|
|
|
definition.operation === 'subscription'
|
|
|
- ) && !operationIsFormUpdater(definition)
|
|
|
+ ) && !websocketContext.active
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
// Everything over websocket except login/logout as that changes cookies.
|
|
|
return operationIsLoginLogout(definition)
|
|
|
}
|