-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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 not working #6617
Comments
They are actually not implemented yet. I've started doing this but turned out never finishing. I will try to push something soon if nobody beats me and push it before. |
Great! Thank you @davimacedo ! |
For those interested in a workaround while waiting for the GraphQL subscription, here is some code to refresh data on the page using useQuery from @apollo/react-hooks and the option pollInterval:
My project uses Gatsby and @apollo/react-hooks to display live data. I spent a whole day looking for a solution to configure Gatsby to make it work with parse-server. If anyone interested in how I did it, let me know. |
Thank you for your effort! Subscriptions would be great for my project. How difficult is it to implement into parse-server? Should I be holding my breath? |
+1 It could be useful on my project |
+1 If I could be helpful, please let me know. |
@davimacedo do you have an idea about a simple implementation ? After reading the LiveQueryServer and Apollo Server Sub docs i'm not sure how to implement the feature ? |
Yes. The easiest way will be using the code we already have in place for the Live Query. I worked on a draft long time ago but turned out never finishing. I will organize what I have here and push to a new branch so we can continue the discussion from there. BTW, it would be good we agree in the API that we want for that. @Moumouls you are the guy for that :) Do you have any suggestion? |
Yes no problem @davimacedo , i will try to make an API suggestion during the week. I already have an idea to get something easy to use and to understand. |
So @davimacedo here our spec for Sub API, what do you think about this one ? @mstephano, @TheTyrius, @FNPCMDs, @raajon Do you have a feedback on this proposal ? # Schema Parse GraphQL Subscription Proposal
# GraphQL enum support description: https://graphql.org/graphql-js/type/#graphqlenumtype
# So we can use it for better documentation
enum EventKindEnum {
# When a Node is created and fulfill the where query
create
# When a Node existed and now fulfill the where query
enter
# When a Node is updated and fulfill the where query
update
# When a Node existed and now do not fulfill the where query
leave
# When a Node is deleted and fulfill the where query
delete
# When a Node match any of the events above
all
}
# Subscribe to updates
type Subscription {
# Listen event on Comment class
comment(on: [EventKindEnum!], $where: CommentWhereInput){
# Kind of event triggered
event: EventKindEnum
node: Comment
}
# Listen event on Post class
post(on: [EventKindEnum!], $where: PostWhereInput){
# Kind of event triggered
event: EventKindEnum
node: Post
}
}
# Note:
# We should use "on" with array of events to support multi event subscription, and avoid unnecessary complexity
# for developers
# We need to investigate if we can use the same "WhereInput" as the main query,
# 2 years ago i used intensively LiveQueries and i remember that some complex queries were not supported
# otherwise a specific "SubscriptionWhereInput" will do the job to avoid developers to get unwanted behavior # Usage example
subscription watchComments {
comment(on: [create, update, delete], where: { content: { equalTo: "GraphQL Spec" } }){
event
node {
id
content
}
}
} |
@Moumouls looks like exacly what I need :-) |
It looks good to me. I liked the idea of having a single subscription for all event types. |
Having EventKindEnum is very interesting for us to be able to have multiple subscriptions with one or multiple event kind. I should also be able to serve you as a tester for this functionality. Thank again again @davimacedo @Moumouls for your hard work! |
Following the current implementation of GraphQL getting multiple objects (https://docs.parseplatform.org/graphql/guide/#where), I presume the usage example from @Moumouls should be something like this? (comments with edges) # Usage example
subscription watchComments {
comments(on: [create, update, delete], where: { content: { equalTo: "GraphQL Spec" } }){
event
edges {
node {
id
content
}
}
}
} |
@mstephano here we do not have |
Following my example of react-hooks query with pollInterval, I would have hoped to only replace the word "useQuery" for "useSubscription" + remove pollInterval, and my page would refresh automatically with the updated list of objects: import React from 'react'
import { useSubscription } from '@apollo/react-hooks'
import gql from 'graphql-tag'
const SUBSCRIPTION_TODOS = gql`
subscription todos {
todos {
edges {
node {
objectId
name
createdAt
updatedAt
}
}
}
}
`
const MyTodoPage = () => {
const { loading, error, data } = useSubscription(SUBSCRIPTION_TODOS)
if (loading) return <p>Loading ...</p>
if (error) return <p>Error! ${error.message}</p>
return (
<div>
<ul>
{data.todos.edges.map(({ node: todo }) => ( // node is the object returned by GraphQL, todo is an alias used in the code here
<li key={todo.objectId}>{todo.name}</li>
))}
</ul>
</div>
)
}
export default MyTodoPage Question: If there is no subscription.on('create', (todo) => {
todos.push(todo) //add object to internal list
}); |
TLDR: Parse can't return edges for subscription, but Apollo currently has a system designed to handle your use case: https://www.apollographql.com/docs/react/data/subscriptions/#subscribing-to-updates-for-a-query @mstephano , yes parse server cannot return a list of object, so you need to have the query and the subscription. Then you can combine the subscription result with an Apollo Cache Update: https://www.apollographql.com/docs/react/caching/cache-interaction/ Note: On update event, Apollo will do the magic without any code since apollo watch the subscription result and then try to update directly the cache if the object already exist in the cache. |
Great! Thank you @Moumouls for your explanation. I can't wait to test the functionality on update event! |
Are there any updates on how to use the subscription on the client and the playground? is there any specific config I should do on the server? errors: |
Hi @amkarkhi this feature is still "up for grabs", graphql subscriptions are not currently supported. |
Hi @Moumouls Do we support graphql subscription now? |
Hi @thphuc GraphQL subscription is not yet supported. A draft PR #7227 is still open. Currently the only alternative is to use a Parse SDK, but it will also add a new dependency in you project. We are also open for contributions, i believe that's a nice feature and will help the community to design real time apps using GQL. Note: If your app do not need super fast real time, you can also use |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as duplicate.
This comment was marked as duplicate.
Hi @Vildnex unfortunately not, do you want to submit a PR ? 🙂 |
This would be a great addition |
Issue Description
Based on the Parse-Server documentation at https://docs.parseplatform.org/graphql/guide/#graphql, I am wondering if GraphQL subscriptions work out-of-the-box. So far in my testing, it doesn't work.
Steps to reproduce
Expected Results
Once the subscription query is executed and running, every mutation result (related to the class in the subscription query) should be displayed on the result side of the console.
Actual Outcome
An error is displayed in the result side of the GraphQL console:
If I uncomment the following 2 lines in my docker-compose file (see at the end), I am not getting the above error, but just a console running and not displaying any result after a mutation:
Environment Setup
Server
Database
Logs/Trace
Docker logs of my parse-server container:
My docker-compose.yml file:
The text was updated successfully, but these errors were encountered: