question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[server side] How do I implement and expose subscriptions?

See original GitHub issue

As mentioned in the question above. As far as I can tell, the resolvers for subscriptions should be implemented with the reactivestreams Publisher, but that does not seem to be the type shown in the generated interface. For example, I have

type Subscription {
    testSub: Boolean!
}

If my understanding is correct, I’m expecting to implement a Publisher<Boolean>, but right now I’m simply getting a normal Boolean return type on the interface method.

Another related question: how do I expose the necessary websockets on the server side for these subscriptions? I have tried .subscriptionExecutionStrategy(new SubscriptionExecutionStrategy()) from here but it doesn’t seem to do anything different.

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jxnu-liguobincommented, Aug 4, 2020

Sorry, at first I thought you just needed to return async type.

in sbt plugin you can use option apiAsyncReturnType such as

generateAsyncApi := true
apiAsyncReturnType := "scala.concurrent.Future" //your type: Publisher

also can use in gradle plugin

generateAsyncApi = true
apiAsyncReturnType = "scala.concurrent.Future"

if resultType is Collection , use apiAsyncReturnListType

but if you want use in subscription

you can use subscriptionReturnType

like

subscriptionReturnType := Some("org.reactivestreams.Publisher")

also can use in gradle plugin

subscriptionReturnType = "org.reactivestreams.Publisher"

when you exec task, will generate java code

public interface SubscriptionResolver {

    @javax.validation.constraints.NotNull
    org.reactivestreams.Publisher<Boolean> testSub() throws Exception;

}
0reactions
fnatiqcommented, Aug 13, 2020

hi @kobylynskyi apologies for the very late reply, but thanks, I did implement the GraphQLSubscriptionResolver similarly for my testing. may I know if the websocket exposure needs to be implemented explicitly? If I understand Java correctly, websockets are implemented through http anyway, so I should think there is no further need to do anything else, but I am not able to hit the subscription WS endpoint in my GraphQL playground.

Not sure if this issue is related to the application.yml settings (I’m actually using application.properties, I understand they are basically equivalent) being only in the latest version? For my purposes, I’m currently using the codegen 2.0.0.

Would appreciate any further advice. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subscriptions in Apollo Server - Apollo GraphQL Docs
Subscriptions are long-lasting GraphQL read operations that can update their result whenever a particular server-side event occurs.
Read more >
GraphQL Subscriptions: Why we use SSE/Fetch over ...
WunderGraph exposes GraphQL Subscriptions over SSE (Server-Sent Events) or Fetch (as a fallback). This post explains why we've decided to ...
Read more >
Realtime GraphQL Subscriptions with Node.JS Tutorial
The goal is to implement two subscriptions to be exposed by your GraphQL server: Send realtime updates to subscribed clients when a new...
Read more >
Using the HTTP Publish-Subscribe Server
Before you can perform any server-side tasks on the pub-sub server and its channels, you must first instantiate a PubSubServer object which represents...
Read more >
GraphQL subscriptions - Relay
GraphQL subscriptions are a mechanism to allow clients to query for data in response to a stream of server-side events. ... Note that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found