Can I connect to a GraphQL Subscribtion using Insomnia REST client? - graphql

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.

Related

How to configure authentication from Azure data factory to Google Sheets

I am trying to fetch data from Google Sheets via the Azure Data Factory. I have a data flow configured, and a Google Sheets Linked Service configured as well. The Google Sheets Linked Service is using an API key that has no Application Restrictions, and for API restrictions, it is restricted to Google Sheets. When I test the connection, it is successful. However, when I try to fetch a spreadsheet using the data flow in debug mode, I get the error:
at Source 'GoogleSheetsOutput': Failure to read most recent page request: DF-REST_001 - Error response from server: Some({
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}), Status code: 403. Please check your request url and body. (url:https://sheets.googleapis.com/v4/spreadsheets/<my_spreadsheet_id>/values/Sheet1!A2:B3,request body: None, request method: GET)
I made a service account, and shared the google sheet with the service account e-mail, and I also shared it with the admin on the account, which is where the API Key was made.
Any ideas what I need to do here? I would also prefer to use oauth / service account instead if possible, so I am happy to go down that route if there is some documentation I can follow.
"error": { "code": 403, "message": "The caller does not have permission", "status": "PERMISSION_DENIED" }
I tried to repro this and got the same error.
To solve this, I changed access of my google sheets from restricted to Anyone with the link
It worked and data is previewed without error.

Graphiql does not display incoming data for subscriptions

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",...}

Is there any tool to debug the rest calls made by GraphQL Playground?

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.

How to cascade 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

Google API Explorer and Google Identity Toolkit API not working

I'm trying to explore the Google Identity Toolkit API using the Google API Explorer. The API hints that "No auth required", however when I try to execute a request there is an error message:
This method requires you to be authenticated. You may need to activate the toggle above to authorize your request using OAuth 2.0.
If I try to use the OAuth 2.0 toggle and Authorise the API I get a 400 error:
Error: invalid_request
Missing required parameter: scope
But Google Identity Toolkit API does not declare any scopes.
Please can someone help?
UPDATE:
Further errors I get when using the API Explorer: When trying to execute the getAccountInfo request, I pass a request body with the localId field populated. The response I get is:
400 OK
- Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "INVALID_SERVICE_ACCOUNT"
}
],
"code": 400,
"message": "INVALID_SERVICE_ACCOUNT"
}
}
Here is the list of Google API scopes:
https://developers.google.com/identity/protocols/googlescopes#oauth2v2
This completely omits Identity Kit.
Tying in a random string into the scopes box produces an error:
I have guessed up that the scope should be https://www.googleapis.com/auth/identitytoolkit by looking at the pattern.
And this scope does not cause an error. So this means it is a valid scope, even though it is undocumented.
That said, I used an API request of:
POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/downloadAccount?fields=kind%2CnextPageToken%2Cusers&key={YOUR_API_KEY}
{
"maxResults": 999
}
And it produced:
200 OK
{
"kind": "identitytoolkit#DownloadAccountResponse"
}
So I will say that I have successfully executed this query while using an undocumented feature. However, it appears that the result from the server is incorrect.
This should answer your question, although the result is simply shining light on a broken server implementation.
I have not reported the bugs / undocumented feature in this answer and would appreciate assistance in that effort.
You may find how to use Google Identity Toolkit from the official site. If you really want to manually try Google Identity Toolkit API, you need to enable the API in your Google Developers Console project, create an ApiKey in the project, and call the API using a command tool like curl. The request syntax should follow the one shown in the Google API Explorer.

Resources