parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

GraphQL Subscriptions

Open davimacedo opened this issue 4 years ago • 5 comments
trafficstars

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: https://github.com/parse-community/parse-server/issues/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
  • [ ] ...

davimacedo avatar Feb 25 '21 07:02 davimacedo

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

Generated by :no_entry_sign: dangerJS

ghost avatar Feb 25 '21 07:02 ghost

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%) :arrow_down:
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%) :arrow_down:
src/GraphQL/ParseGraphQLSchema.js 93.30% <30.76%> (-4.15%) :arrow_down:
src/GraphQL/ParseGraphQLServer.js 72.61% <48.78%> (-20.57%) :arrow_down:
src/cli/parse-server.js 33.33% <50.00%> (+0.52%) :arrow_up:
src/ParseServer.js 89.14% <75.00%> (-0.46%) :arrow_down:
... 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.

codecov[bot] avatar Feb 25 '21 07:02 codecov[bot]

⚠️ 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!

mtrezza avatar Sep 03 '21 00:09 mtrezza

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

Moumouls avatar Mar 24 '22 10:03 Moumouls

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

Moumouls avatar Mar 24 '22 10:03 Moumouls