How to change/customize the response format of Lighthouse? - laravel

I am using Lighthouse GraphQL with Laravel 9 for my application. Graphql have standard format and each response show under the data and operation name. It does not show proper response (error/success) to handle for front-end application. Because, on the basis of error code iOS/Android/frontend may work easily. Here is the sample:
Request:
query Translations {
translations {
name
slug
}
}
Response:
{
"data": {
"translations": [
{
"name": "English",
"slug": "en_US"
},
{
"name": "English (United Kingdom)",
"slug": "en_UK"
}
]
}
}
I have tried to override response with Laravel response classes and create custom queries/mutations resolver. But, it returns all the information. This should use Graphql "Tailoring your need" also. So, I want to customize the response so that response should include code, status, message, data[].
The result I got:
{
"status": true,
"code": 200,
"message": "",
"data": [
{
"_id": "63b2d767e2a07754b20845f6",
"name": "English",
"slug": "en_US",
"isActive": true,
"isDefault": true,
"updated_at": "2023-01-02T13:08:54.940000Z",
"created_at": "2023-01-02T13:08:54.940000Z",
"logo": "/United-States.svg"
},
{
"_id": "63b3e78ae2a07754b20845ff",
"name": "English (United Kingdom)",
"slug": "en_UK",
"isActive": true,
"isDefault": false,
"updated_at": "2023-01-03T08:30:02.085000Z",
"created_at": "2023-01-03T08:30:02.085000Z",
"logo": "/Great-Britain.svg"
}
]
}
It should be:
{
"status": true,
"code": 200,
"message": "",
"data": [
{
"name": "English",
"slug": "en_US"
},
{
"name": "English (United Kingdom)",
"slug": "en_UK"
}
]
}

Lighthouse returns the response based on the GraphQL specification. You have the power to change the response with the EndRequest event. Listen to the event in AppServiceProvider and then manipulate the response in any form that you need.
/**
* #param Dispatcher $dispatcher
*
* #return void
*/
public function boot(Dispatcher $dispatcher): void {
$dispatcher->listen(
EndRequest::class,
function (EndRequest $endRequest) {
dd($endRequest->response);
});
}

It should be:
{
"status": true,
"code": 200,
"message": "",
"data": [
{
"name": "English",
"slug": "en_US"
},
{
"name": "English (United Kingdom)",
"slug": "en_UK"
}
]
}
I would strongly advise against this, as it violates the GraphQL specification:
To ensure future changes to the protocol do not break existing services and clients, the top level response map must not contain any entries other than the three described above.
Use extensions for custom additions. You can add to extensions in Lighthouse by listening to the BuildExtensionsResponse event, see https://lighthouse-php.com/master/api-reference/events.html#buildextensionsresponse

Related

teams - graph api - can't create event with defined organizer / specify channel

I'm trying to create an event for a teams. Using the WEB interface, I can create and specify the channel. through the API, there's no channel field.
Also, When I'm specifying an organizer, it's being over writed to some other values.
What I need to do:
1-) create the event and keep the specified organizer
2-) invite all members of the channel (or specify the channel) when creating the event.
I'm following the official 1.0 API:
POST https://graph.microsoft.com/v1.0/groups/{my-id}/calendar/events
{
"subject": "TESTE - New Event - Sala virtual",
"body": {
"contentType": "HTML",
"content": "Does late morning work for you?"
},
"start": {
"dateTime": "2020-04-21T11:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2020-04-21T12:30:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Online"
},
"attendees": [
{
"emailAddress": {
"address":"test#another.com",
"name": "Test"
},
"type": "required"
}
,
{
"emailAddress": {
"name": "Teste",
"address": "group#test.com"
},
"type": "required"
}
],
"onlineMeetingProvider":"teamsForBusiness",
"isOnlineMeeting": true,
"organizer":{
"emailAddress":{
"name":"Owner",
"address":"owner#test.com"
}
}
}

Google Knowledge Graph API `articleBody` field missing from `detailedDescription`

Following the sample request for Taylor Swift shown here, I get the following response which does not match the response shown on the site. Moreover, I'm interested in the articleBody of the detailedDescription field which is not being returned the same way. Has there been an update to the API that was not reflected in the documentation? Is there a way to request the articleBody via the Python API?
{
"#context": {
"#vocab": "http://schema.org/",
"goog": "http://schema.googleapis.com/",
"EntitySearchResult": "goog:EntitySearchResult",
"detailedDescription": "goog:detailedDescription",
"resultScore": "goog:resultScore",
"kg": "http://g.co/kg"
},
"#type": "ItemList",
"itemListElement": [
{
"#type": "EntitySearchResult",
"result": {
"#id": "kg:/m/0dl567",
"name": "Taylor Swift",
"#type": [
"Thing",
"Person"
],
"description": "American singer",
"image": {
"contentUrl": "http://t0.gstatic.com/images?q=tbn:ANd9GcST848UJ0u31E6aoQfb2nnKZFyad7rwNF0ZLOCACGpu4jnboEzV",
"url": "https://en.wikipedia.org/wiki/Begin_Again_(Taylor_Swift_song)"
},
"url": "http://taylorswift.com/"
},
"resultScore": 1237.141968
}
]
}

Bug: findMeetingTimes throws “AttendeesUnavailable” even for optional attendees

I'm trying to use the https://outlook.office.com/api/v2.0/me/findmeetingtimes endpoint documented on the MSDN Outlook Calendar website. When I call the endpoint with the following payload:
{
"Attendees": [
{
"Type": "optional",
"EmailAddress": {
"Name": "Studio 3",
"Address": "PDXICSTUDIO3#rogueInc.onmicrosoft.com"
}
}
],
"TimeConstraint": {
"ActivityDomain":"Unrestricted",
"Timeslots": [
{
"Start": {
"DateTime": "2018-10-30T19:30:00",
"TimeZone": "UTC"
},
"End": {
"DateTime": "2018-10-30T20:30:00",
"TimeZone": "UTC"
}
}
]
},
"ReturnSuggestionReasons": "true",
"IsOrganizerOptional": false,
"MaxCandidates": 99
}
I get an empty meeting time suggestions response with the reason provided as "AttendeesUnavailable". It doesn't seem to matter whether I declare the type of the attendee as "optional", "required", or "resource" as specified in the attendeeBase Resource Type documentation. This seems like a bug with the GraphAPI and I'm unsure as to how to proceed.

Can't get almost all information from event from service Hook

I am trying to use the Trello service hook with Team Foundation Server. I have followed this tutorial and the connection worked without problems but, I can't get the informations I need from the Event JSON:
The Description I Tried
This is the Event JSON:
{
"id": "03c164c2-8912-4d5e-8009-3707d5f83734",
"eventType": "git.push",
"publisherId": "tfs",
"scope": 0,
"message": {
"text": "Jamal Hartnett pushed updates to Fabrikam-Fiber-Git:master.",
"html": "Jamal Hartnett pushed updates to Fabrikam-Fiber-Git:master.",
"markdown": "Jamal Hartnett pushed updates to `Fabrikam-Fiber-Git`:`master`."
},
"detailedMessage": {
"text": "Jamal Hartnett pushed a commit to Fabrikam-Fiber-Git:master.\n - Fixed bug in web.config file 33b55f7c",
"html": "Jamal Hartnett pushed a commit to Fabrikam-Fiber-Git:master.\n<ul>\n<li>Fixed bug in web.config file 33b55f7c\n</ul>",
"markdown": "Jamal Hartnett pushed a commit to [Fabrikam-Fiber-Git](https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/):[master](https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/#version=GBmaster).\n* Fixed bug in web.config file [33b55f7c](https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74)"
},
"resource": {
"commits": [
{
"commitId": "33b55f7cb7e7e245323987634f960cf4a6e6bc74",
"author": {
"name": "Jamal Hartnett",
"email": "fabrikamfiber4#hotmail.com",
"date": "2015-02-25T19:01:00Z"
},
"committer": {
"name": "Jamal Hartnett",
"email": "fabrikamfiber4#hotmail.com",
"date": "2015-02-25T19:01:00Z"
},
"comment": "Fixed bug in web.config file",
"url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74"
}
],
"refUpdates": [
{
"name": "refs/heads/master",
"oldObjectId": "aad331d8d3b131fa9ae03cf5e53965b51942618a",
"newObjectId": "33b55f7cb7e7e245323987634f960cf4a6e6bc74"
}
],
"repository": {
"id": "278d5cd2-584d-4b63-824a-2ba458937249",
"name": "Fabrikam-Fiber-Git",
"url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249",
"project": {
"id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
"name": "Fabrikam-Fiber-Git",
"url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
"state": "wellFormed",
"visibility": "unchanged"
},
"defaultBranch": "refs/heads/master",
"remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git"
},
"pushedBy": {
"id": "00067FFED5C7AF52#Live.com",
"displayName": "Jamal Hartnett",
"uniqueName": "Windows Live ID\\fabrikamfiber4#hotmail.com"
},
"pushId": 14,
"date": "2014-05-02T19:17:13.3309587Z",
"url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/pushes/14"
},
"resourceVersion": "1.0",
"resourceContainers": {
"collection": {
"id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2"
},
"account": {
"id": "f844ec47-a9db-4511-8281-8b63f4eaf94e"
},
"project": {
"id": "be9b3917-87e6-42a4-a549-2bc06a7a878f"
}
},
"createdDate": "2017-07-21T16:48:44.312Z"
}
This is the Request that was send to Trello:
Method: POST
URI: https://api.trello.com/1/cards?key=7d6630fd03ac2b6fc9fde2f2ef0c4096&token=********
HTTP Version: 1.1
Headers:
{
Content-Type: application/json; charset=utf-8
}
Content:
{
"name": "Test Nº ",
"desc": "Description: ",
"pos": "top",
"due": null,
"labels": "green",
"idList": "5935a0d45ff8e5a6c8f828b9"
}
The only field that I could get/read from the Event JSON was the "message".
What am I doing wrong?
If you want to get the push ID and comments, the description is:
{{push.pushId}}
{{push.commits[0].comment}}
Update
Eddie is right you should use push as the resource in this case. The docs are not so clear. In the end, it was something so simple. However the corresponding checkin is not work for Code checked in event.
The docs could definitely be more clear in how the resource are for each event which applied to help avoid this confusion.
The basic form of the placeholder is {{resource.field}} where
resource is the name of the resource raising the event (workitem, build, etc) and field is a field within the resource section of the
event, like id. So, if the subscription were for a completed build,
it might be something like:
Build {{build.id}} completed at {{build.finishTime}}
Seems the issue is you are using the wrong placeholder in this case. According to your send Request , resource.pushID & resource.commits.[0].comment is not replaced by values from the event that was raised.

swagger: how to validate formData

So far I'm able to do swagger validation if the parameters are from "in": "body" or if the input expected is in a json format.
However, I can't find how to validate a simple string entered as formData.
Below is my swagger script (in json format)
v1swag = {
"cancels_post": {
"tags": ["/api/v1"],
"parameters": [
{
"name": "token",
"in": "formData",
"type": "string",
"required": True,
"description": "Cancels the provided token.",
}
],
"responses": {
"200": {
"description": "Success!",
}
}
}
}
I removed the schema as it seems to only work for "in": "body"
I've been searching the net but can't seem to find the light.
Though I will still be searching... Any hints would be greatly appreciated.
Thank you very much in advance.
A different source media type has to be consumed here. Specify "consumes" member to include media type of application/x-www-form-urlencoded.
v1swag = {
"cancels_post": {
"tags": ["/api/v1"],
"consumes": [
"application/x-www-form-urlencoded"
],
"parameters": [
{
"name": "token",
"in": "formData",
"type": "string",
"required": True,
"description": "Cancels the provided token.",
}
],
"responses": {
"200": {
"description": "Success!",
}
}
}
}

Resources