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

Conversation

beepsoft
Copy link
Collaborator

The MSTGQLStore.subscribe() fails when a DocumentNode is passed as query, ie. when an object created using graphql-tag is passed.

The problem is that query.toString() doesn't work here, because graphql doesn't implement it
to convert the DocumentNode to a graphql string representation. Instead, print(query) has to be used.

mst-gql has no tests for subscriptions, but this fix can be tested in a project using mst-gql using

    "mst-gql": "https://github.com/beepsoft/mst-gql#mst-gql-v0.17.1-subscription-fix-gitpkg",

in package.json

jesse-savary and others added 2 commits July 19, 2022 21:18
* fix: use Pinst to disable Husky in published NPM package

* fix: ensure we always publish to the correct repository

* chore: bump version, update CHANGELOG.md

* fix: ignore peer dependencies when running Syncpack

* refactor: move format check step to only run on CI

* refactor: always format w/ `pretty-quick` for consistency

* refactor: run Syncpack directly instead of using `yarn dlx`

* chore: de-duplicate yarn.lock

* chore: update yarn.lock with weird changes from tests

* refactor: move CRA test into dedicated/isolated directory

* refactor: remove cra-test from root worktree

* ci: temporarily disable CRA test until we can improve it
query.toString() doesn't work here, because graphql doesn't implement it
to convert the DocumentNode to a graphql string representation. Instead,
print(query) has to be used.
@beepsoft
Copy link
Collaborator Author

Until this is merged the workaround is to use print() in your code when calling subscribe. eg:

import { print } from 'graphql/language/printer'

gqlStore.subscribe(print(gql`...some graphql query`), ...)

# Conflicts:
#	.gitignore
#	CHANGELOG.md
#	package.json
#	tests/cra-test/test-cra.sh
#	yarn.lock
@beepsoft beepsoft merged commit df92fb5 into mobxjs:development Feb 3, 2024
1 check failed
@beepsoft beepsoft mentioned this pull request Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants