I am returning MOCK JSON response for GraphQL query response in Apollo iOS client. But Apollo client is not parsing the MOCK json content.
Error: __typename missing in mock response.
I found the solution after spending some time on Apollo Client framework iOS.
Mock JSON response must contains __typename key-value in each structure inside it. So that Apollo client decoding functions can decide the corresponding struct models for the response.
{
"data": {
"summary": {
"__typename": "AccountSummaryResponse"
"accountSummary": [{
"token": "45454"
"type": "club"
"__typename": "AccountSummary"
},
{
"token": "4344"
"type": "clubA"
"__typename": "AccountSummary"
}
]
}
}
}
You will get the __typename value from API.swift automated generated file by Apollo Code-gen.
Related
I want to modify the response of hasura fetch query.
the current response is this:
{
"data": {
"ids": [
{
"id_object": {
"id": 33102
}
},
{
"id_object": {
"id": 33104
}
}
]
}
}
And I want to remove "id_object" and want just array of id's like this:
{
"data": {
"ids": [
{
"id": 33102
},
{
"id": 33104
}
]
}
}
A GraphQL server exposes an exact set of operations and the shape of the allowed responses for those operations. When interacting with any GraphQL server (Hasura or otherwise), it is therefore not possible to to arbitrarily modify the shape of the returned data.
You're free to map it into a new form when you receive the data on the client side.
If you really need the server itself to be able to respond using this shape, you'll need to extend Hasura's schema to be able to specifically support this query pattern.
There are a number of different ways that you could accomplish this:
You could write a custom Hasura Action
You could expose this query from your own GraphQL server and then stitch it together with Hasura using Remote Schemas
You could use a Postgres View or Function to shape the data as required and expose it as a new operation
I have tried this i am able to create event but this error i am getting.
body_json={
"#odata.type": "#microsoft.graph.fileAttachment",
"name": "menu.txt",
"contentBytes": "base64bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
API =" https://graph.microsoft.com/v1.0/users/{}/events/{}/attachments".format(userId,meetingID)
body_json = json.dumps(body_json)
response = requests.request("POST", url=API, data=body_json, headers=self.headers)
error : <Response [400]> {"error":{"code":"UnableToDeserializePostBody","message":"were unable to deserialize "}}
The issue here is because the data which you are putting in the contentBytes property is not BASE64. As you are following the documentation they gave that example to make you understand that the data is base64. But actually in the example its not base64. So you can convert it to base64 online as below and test it.
This is the request body I used which has Hello World.
{
"#odata.type": "#microsoft.graph.fileAttachment",
"name": "menu.txt",
"contentBytes": "SGVsbG8gV29ybGQ="
}
Which gave me successful results in graph explorer. You can use it to test Graph API calls.
I am attempting to build out a process that will do the following:
New contact lands in my CRM (Podio)
The CRM is triggered to send a POST containing a custom parameter to Twilio which will then initiate a flow
The Twilio flow will call my cell and prompt me to connect to the new contact
Once I press 1, it will take the custom parameter (new contact's phone number) and connect
me to them.
So far, I have been able to get 1-3 with no problem.
However, according to the the API documentation from Twilio I should be able to pass a 3rd parameter in the JSON body of my HTTP request containing custom "Parameters". When I attempt this the parameters aren't showing in the Twilio studio logs and thus I am unable to connect the call to the new lead.
This is the JSON body I am sending over to my Twilio Flow's API
{
"To": "+1xxxxxxxxx1",
"From": "+1xxxxxxxxx2",
"Parameters": {
"name": "example name",
"prospectphone": "+1xxxxxxxxx3"
}
}
When I view the logs in Twilio this is what I received.
{
"contact": {
"channel": {
"address": "+1xxxxxxxxx2"
}
},
"trigger": {
"request": {
"from": "+1xxxxxxxxx2",
"to": "+1xxxxxxxxx1",
"parameters": {}
}
},
"widgets": {},
"flow": {
"flow_sid": "FW936f72c0eb8d3945d0d55c62465e37a8",
"data": {},
"channel": {
"address": "+1xxxxxxxxx2"
},
"sid": "FN955cdb12827f84c8af8fc9b5264e5a28"
}
}
I really can't figure out what I'm missing here? Has anyone run into this before? Is this something you can only do if you're using the SDK or does the additional parameter need to be passed in some other way?
It should be sent x-www-form-urlencoded.
From the documentation:
"Note: the JSON value must explicitly be passed as a string, not as a hash object. Depending on your particular HTTP library, you may need to add quotes or URL encode the JSON string."
Trigger a Twilio Studio Flow Execution via the REST API
I am aware that swagger core , swagger inflector read a swagger.yaml / json file in creating a http response, Now we have a use wire mock to stub response where the content for the stub has to come from the swagger file.
I have gone through many examples but unable to figure out the right function to convert the swagger.yaml/json to return the http response. Please help me
SwaggerHub can be used to define your API in JSON or YAML. The UI provided alongside shows the API vividly. The UI has the option to trigger a newly defined API and check the response as a model - the structure of JSON response body. If "example" has been given in the API specification, it's fetched in the response.
If this response model works as per requirement, it can be then used in WireMock to generate stubbed responses having canned data. A swagger specification fragment and response model shown below -
API specification -
"swagger": "2.0",
"info":{
"version":"v0.1",
"title":
"Capital city finder",
"description":"Search capital city by country name"
},
"definitions":{
"city":{
"properties":{
"countryName":{
"type":"string",
"example":"United Kingdom"
},
"capitalCity":{
"type":"string",
"example":"London"
},
"nationalAnimal":{
"type":"string",
"example":"Lion"
},
"popularFood":{
"type":"string",
"example":"Fish & Chips"
}
... ... ...
Response Model -
[
{
"countryName": "United Kingdom",
"capitalCity": "London",
"nationalAnimal": "Lion",
"popularFood": "Fish & Chips"
}
]
Not sure if this is still relevant to you now.
For automation purposes I'm trying to create issues through the JIRA REST API, but I'm getting a 500, Internal Server Exception as response without any additional information.
With the Chrome-plugin "advance REST client", I ran through the following steps:
Entered the endpoint: h.ttps://[company-jira-url]/rest/api/2/issue/
Set the HTTP method: POST
Added the required headers:
Content-Type: application/json
Authorization: Basic (100% sure this one's correct)
Added the json payload (Basically the minimum required fields):
{
"fields": {
"project":
{
"key": "HACK"
},
"summary": "REST EXAMPLE",
"description": "Creating an issue via REST API",
"issuetype": {
"name": "Bug"
}
}
}
Click "Send"
The request basically looks like this (base64 string is not correct in this example):
The Request
Result:
The Response
Anyone ?