I implemented a graphql server using graphql-java that offers subscriptions over websockets.
When I subscribe using the websocket CL-tool wscat everything works as intended.
Here is how the data looks that the server publishes (<):
$wscat -c "ws://localhost:9876/subscriptions"
> { "query" : "subscription{resourceSubscription(hasTypes : []){id}}" }
< {"type":"subscription_success"}
< {"payload":{"data":{"resourceSubscription":{"id":"..."}}},"id":"1","type":"subscription_data"} (*1)
The JSON response format is copied from this tutorial. I have also tried to just send the "data" block without the "payload" wrapper.
For graphiql I use the graphiql-spring-boot-starter v7.1.0 package. When I fire a subscription from graphiql, the display shows:
"Your subscription data will appear here after server publication!"
graphiql sends the query to the websocket endpoint:
{"type":"connection_init","payload":{}}
{"id":"1","type":"start","payload":{"query":"subscription[...]","variables":null}}
A websocket is created on the server, and new data is actually published to the established websocket (like in *1), however, it is not displayed in graphiql, the incoming data is completely ignored and the prompt remains.
Does anyone have an idea why this happens? Is the JSON response not formatted correctly?
The necessary response types is:
{"type": "data",...} instead of {"type" : "subscription_data",...}
Related
Insomnia now supports WebSockets. Therefore I was hoping that I can also use it to test GraphQL Subscriptions, since they are also using WebSockets.
I created a GraphQL request to open a new Subscription, but I always get the following response:
{
"errors": [
{
"message": "The response type is not supported."
}
]
}
Am I doing something wrong or are GraphQL Subscriptions simply not a feature in Insomnia?
I checked the Insomnia WebSocket Docs as well as the Insomnia GraphQL Queries Docs but couldn't find any info regarding this topic.
I am using Hot Chocolate to create a GraphQL server on my back end. I have several subscriptions which have been working reliably for months now, but they all of sudden don't work at all.
When I attempt to subscribe to a subscription using the Banana Cake Pop client, I receive this response:
{
"errors": [
{
"message": "The response type is not supported."
}
]
}
According to this answer to a similar question, this error message means that HTTP is being used rather than web sockets, which doesn't work because subscriptions are built on web sockets. So I clicked over to "Transport Details" tab, and sure enough it seems to be using HTTP.
I checked the settings, and the web socket endpoint does use websockets rather than HTTP: ws://localhost:5000/graphql.
I have not changed any settings, and I have never had this issue before. So, why does banana cake pop do this, and how can I make it use web sockets?
I'm not able to figure out why the REST API call works just fine in Postman but not in the GraphQL Playground. If I could see the actual REST call being made by GraphQL, would be helpful to debug the issue.
Firecamp's GraphQL client lets you test the GraphQL as an API call or as a Query way.
Here is the dedicated GraphQL client
Here is REST like GraphQL client
Note: Make sure that you double-check the method and headers while using REST-like GraphQL client. IN most cases method would be post and header should contains Content-Type: application-json / application/graphql
The GraphQL playground allows to send GraphQL queries/mutations to your GraphQL server. You can see the requests that are send using the network tab of a browser dev tools.
For example, if a server is in running at the following address http://localhost:4000/graphql, sending a query/mutation, a XHR request will be sent to it. In the Request Payload of the Headers section there is the query/mutation itself.
In the Response section you can see the returned response.
You can start having a look at the returned response of your query/mutation. Perhaps there is something wrong in the related resolve function in GraphQL.
I'm currently using "client side GraphQL server" to wrap RESTful endpoint to GraphQL endpoint.
But what if server side is also a GraphQL endpoint? How can I queue another GraphQL server in a GraphQL server by a lightweight way?
Or more generally, If I have GraphQL servers "A" and "B", providing microservices, then I use a GraphQL server "C" to integrate "A" and "B". Should I use some kind of "Server side Client" using apollo-client or so to queue "A" and "B" in "C" ?
I've never seen client side GraphQL used that way, but I imagine it would work like usual. You have your query with a resolver which returns data. In this case, you would use a GraphQL request instead of a REST api request, but the principle is the same.
Remember, GraphQL is not that different from any other api. You send HTTP requests (with GraphQL, all of the requests are POST) to a URL endpoint (with GraphQL, the URL is always the same) and send parameter data with your request (with GraphQL, this is where the entire query goes).
I imagine you could translate your variables from the client GraphQL query to the variables in the server GraphQL query and construct your query that way.
With cURL, you can query with a format like this:
$ curl -XPOST -H "Content-Type:application/graphql" -d 'query RootQueryType { count }' http://localhost:3000/graphql
And the response would look like this:
{
"data": {
"count": 0
}
}
Just use the request library you are using on the client to hit the REST client, but modify it to match the API of the GraphQL server you are trying to reach.
Actually, I think it's the job of resolving function to interact with your micro services. For more information, you should have a look at GraphQL and Microservice Architecture
I am using the ResponseBodyEmitter in Spring 4.2 RC1 for sending JSON object as part of the server send events. I am able to see the response in web browser. Is there any spring client for the same ?
I tried using AsyncRestTemplate, but I am getting all the response together. Ie if I am sending 3 objects one after another using ResponseBodyEmitter , using AsyncRestTemplate, I get all of them together. I would like to receive in client as and when the server sends it.
You could give a go to Reactor HTTP client if you're into async and reactive programming: https://github.com/reactor/reactor/blob/master/reactor-net/src/test/groovy/reactor/io/net/http/HttpSpec.groovy#L74.