Skip to content

Commit

Permalink
Merge pull request #396 from beepsoft/fix/subscribe-gql-tag
Browse files Browse the repository at this point in the history
Fix MSTGQLStore.subscribe() when a DocumentNode is passed as query
  • Loading branch information
beepsoft authored Feb 3, 2024
2 parents 511f375 + d509376 commit df92fb5
Show file tree
Hide file tree
Showing 4 changed files with 12,882 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/MSTGQLStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { deflateHelper } from "./deflateHelper"
import { mergeHelper } from "./mergeHelper"
import { Query, QueryHttpClientOptions, QueryOptions } from "./Query"
import { getFirstValue } from "./utils"
import { print } from "graphql/language/printer"

type RequestOptions = {
document: string
Expand Down Expand Up @@ -154,7 +155,11 @@ export const MSTGQLStore = types
if (self.graphqlWsClient) {
cleanup = self.graphqlWsClient.subscribe(
{
query: query ? query.toString() : "",
query: query
? typeof query === "string"
? query
: print(query)
: "",
variables: variables
},
{
Expand All @@ -181,7 +186,11 @@ export const MSTGQLStore = types
if (!self.gqlWsClient) throw new Error("No WS client available")
const sub = self.gqlWsClient
.request({
query: query ? query.toString() : "",
query: query
? typeof query === "string"
? query
: print(query) // Here we could actually pass query as is, gqlWsClient can work with DocumentNode
: "",
variables
})
.subscribe({
Expand Down
1 change: 1 addition & 0 deletions tests/cra-test/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
16 changes: 16 additions & 0 deletions tests/cra-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "cra-test",
"packageManager": "[email protected]",
"private": true,
"workspaces": [
"cra-tmp/cra-app"
],
"dependencies": {
"graphql": "16.5.0",
"graphql-request": "4.3.0",
"graphql-tag": "2.12.6",
"mobx": "6.6.1",
"mobx-react": "7.5.2",
"mobx-state-tree": "5.1.5"
}
}
Loading

0 comments on commit df92fb5

Please sign in to comment.