Skip to content
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

Fix MSTGQLStore.subscribe() when a DocumentNode is passed as query #396

Merged
merged 3 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "yarn@3.2.1",
"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
Loading