I'm following the documentation of DGS subscriptions and I'm not getting any errors but not getting back any data either.
The setup is very simple. In the schema.graphqls file I have defined the subscription:
type Subscription {
ratings: Rating
}
type Rating {
stars: Int
}
And the Java code is as follows:
@DgsComponent
public class SubscriptionDataFetcher {
@DgsData(parentType = "Subscription", field = "ratings")
public Publisher<Rating> ratings() {
return Flux.interval(Duration.ofSeconds(1)).map(t -> new Rating(4));
}
}
If I now connect a websocket to my backend it connects just fine but not getting back any data as expected (doesn't matter how I do it, also tried using JavaScript, also connects just fine but not getting any data).
For example using curl to connect (but using JavaScript the result is the same, connects but no data):
curl -o - --http1.1 \
--include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: localhost:8443" \
--header "Origin: https://localhost:8443" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
https://localhost:8443/subscriptions\?query\=ewoicXVlcnkiOiAic3Vic2NyaXB0aW9uIHsgIHN0b2NrcyB7bmFtZX0gfSIKfQ==
I have tried connecting via the Graphiql interface as well but that gives an error:
subscription {
ratings {
stars
}
}
Error message:
{
"message": "response is not defined",
"stack": "ReferenceError: response is not defined\n at https://localhost:8443/graphiql:46:35\n at async Object.onRun (https://unpkg.com/graphiql/graphiql.min.js:1:540500)"
}
Another thing that's not clear to me from the examples in the link is how to actually manage subscriptions. So for example let's say I want to publish a notification if a mutation takes place. Any pointers how that would be done using the Netflix DGS framework would also be much appreciated.