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

GraphQL Subscriptions #7227

Draft
wants to merge 2 commits into
base: alpha
Choose a base branch
from

Conversation

davimacedo
Copy link
Member

New Pull Request Checklist

  • [ X ] I am not disclosing a vulnerability.
  • [ X ] I am creating this PR in reference to an issue.

Issue Description

This PR add subscription support to the GraphQL API.

Related issue: #6617

Approach

We are basically taking a ride with the existing Live Query implementation. In order to use subscriptions, the allowed class names needs to be listed in the liveQuery configuration. A Live Query server is not needed though. We are simulating a ws adapter in order to connect directly to the live query implementation without actually creating sockets (which would not make sense).

With something like the following, the GraphQL API, Subscriptions, and Playground will be mounted and can be tested via this PR:

./bin/parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --liveQuery '{"classNames": ["MyClass"]}' --mountGraphQL --mountSubscriptions --mountPlayground

It is still a work in progress. We need to improve the where input (since most of operations are not available at Live Query), and test/improve the node/originalNode output. We still need to create/fix test-cases.

But overall it is working and can be tested.

@Moumouls any feedback?

TODOs before merging

  • Add test cases
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK
  • ...

@ghost
Copy link

ghost commented Feb 25, 2021

Danger run resulted in 1 warning; to find out more, see the checks page.

Generated by 🚫 dangerJS

@davimacedo davimacedo marked this pull request as draft February 25, 2021 07:43
@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Merging #7227 (a733d24) into master (91a0108) will decrease coverage by 0.63%.
The diff coverage is 48.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7227      +/-   ##
==========================================
- Coverage   94.01%   93.38%   -0.64%     
==========================================
  Files         172      173       +1     
  Lines       12873    13047     +174     
==========================================
+ Hits        12103    12184      +81     
- Misses        770      863      +93     
Impacted Files Coverage Δ
src/Controllers/index.js 96.66% <ø> (ø)
src/LiveQuery/QueryTools.js 93.19% <0.00%> (-1.49%) ⬇️
src/Options/Definitions.js 100.00% <ø> (ø)
src/Options/index.js 100.00% <ø> (ø)
src/GraphQL/loaders/parseClassSubscriptions.js 16.07% <16.07%> (ø)
src/Controllers/ParseGraphQLController.js 90.32% <30.76%> (-5.52%) ⬇️
src/GraphQL/ParseGraphQLSchema.js 93.30% <30.76%> (-4.15%) ⬇️
src/GraphQL/ParseGraphQLServer.js 72.61% <48.78%> (-20.57%) ⬇️
src/cli/parse-server.js 33.33% <50.00%> (+0.52%) ⬆️
src/ParseServer.js 89.14% <75.00%> (-0.46%) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91a0108...29ab765. Read the comment docs.

connectReject = reject;
});

const liveQuery = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really clever!

@@ -242,6 +242,11 @@ function matchesKeyConstraints(object, key, constraints) {
return false;
}
break;
case '$eq':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this case already handled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Currently, { "field": "value" } works but { "field": { "$eq": "value" } } does not work for live query. It could actually even be a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just supporting what @davimacedo mentioned about $eq not working for LiveQuery is true. @dplewis if you recall, I was using $eq in ParseSwift and asked you about it here #7113 (comment). I then made a change to ParseSwift to not use $eq anymore here parse-community/Parse-Swift#49

@mtrezza
Copy link
Member

mtrezza commented Sep 3, 2021

⚠️ Important change for merging PRs from Parse Server 5.0 onwards!

We are planning to release the first beta version of Parse Server 5.0 in October 2021.

If a PR contains a breaking change and is not merged before the beta release of Parse Server 5.0, it cannot be merged until the end of 2022. Instead it has to follow the Deprecation Policy and phase-in breaking changes to be merged during the course of 2022.

One of the most voiced community feedbacks was the demand for predictability in breaking changes to make it easy to upgrade Parse Server. We have made a first step towards this by introducing the Deprecation Policy in February 2021 that assists to phase-in breaking changes, giving developers time to adapt. We will follow-up with the introduction of Release Automation and a branch model that will allow breaking changes only with a new major release, scheduled for the beginning of each calendar year.

We understand that some PRs are a long time in the making and we very much appreciate your contribution. We want to make it easy for PRs that contain a breaking change and were created before the introduction of the Deprecation Policy. These PRs can be merged with a breaking change without being phased-in before the beta release of Parse Server 5.0. We are making this exception because we appreciate that this is a time of transition that requires additional effort from contributors to adapt. We encourage everyone to prepare their PRs until the end of September and account for review time and possible adaptions.

If a PR contains a breaking change and should be merged before the beta release, please mention @parse-community/server-maintenance and we will coordinate with you to merge the PR.

Thanks for your contribution and support during this transition to Parse Server release automation!

@Moumouls
Copy link
Member

It seems here that we need to move from subscriptions-transport-ws (not maintained) to https://github.com/enisdenjo/graphql-ws

@Moumouls
Copy link
Member

I don't know enough about websocket systems to give useful feedback:

My questions would be more generalized:

  • Does this implementation will support multi instance (with Redis) ?
  • I'm not sure to see where the subscription server will resolve the graphql query (fields/subfields etc...)

As i understand the main goal is to reuse the livequery server, we internally forward subscriptions to the Livequery server and then the LivequeryServer will "push" updates through the GraphQL subscriptionServer.

Also as you said we need to create a dedicated MyClassSubscriptionWhereInput to cover usable subscriptions.

@davimacedo

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.

5 participants