JSON data types cannot be deserialized from a GraphQL query by using Ferry package - dart

I have this GraphQL query:
query QuoteRequests($page: Int!) {
getQuoteRequestsList(page: $page) {
vehicle
body
licensePlate
vin
quality
currency
items
}
}
It generates this sample result:
{
"data": {
"getQuoteRequestsList": [
{
"vehicle": "1997 TOYOTA AVALON 4 DR ",
"body": "Sedan",
"licensePlate": "RHJ456",
"vin": "XBGGDFYYREAXVJJJD",
"quality": [
"GENUINO"
],
"currency": "USD",
"items": [
{
"uid": "74355f85-5312-9999-8acd-709ceccda00a",
"name": "Doble cero que es",
"description": "no me interesa",
"quantity": 11
},
{
"uid": "66db6fe0-1044-4d58-8454-5e51ab7a313f",
"name": "El arenero",
"description": "el duende verde",
"quantity": 2
}
]
},
]
}
}
The items data is a JSON type, and when trying to fetch that data by using Ferry package with
client.request(GQuoteRequestsReq((b) => b..vars.page = 0)).listen((response) => print(response.data.toString()));
I get a Null result, but if I leave items out of the query, I get a no-null result. I have no problem if I run that query using the HTTP package.
Is this is an error from Package? or do I need to configure something?
Thanks.
UPDATE 1
This is definitely an error because if I try to make a hot-reload in Flutter I get this error in debug console:
Reloaded 1 of 1700 libraries in 860ms.
E/flutter ( 2286): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Deserializing '[__typename, Query, getQuoteRequestsList, [{__typename: GetQuoteRequestsRecor...' to 'GQuoteRequestsData' failed due to: Deserializing '[{__typename: GetQuoteRequestsRecord, uid: 0bf6709f-7ab7-464e-8ee3-6a94e46f05...' to 'BuiltList<GQuoteRequestsData_getQuoteRequestsList>' failed due to: Deserializing '[__typename, GetQuoteRequestsRecord, uid, 0bf6709f-7ab7-464e-8ee3-6a94e46f057...' to 'GQuoteRequestsData_getQuoteRequestsList' failed due to: Deserializing '[{uid: 16870250-5acb-4c23-a7e4-f4e23bbd23ad, name: Doble cero que es, descrip...' to 'GJSON' failed due to: type 'List<dynamic>' is not a subtype of type 'String?' in type cast
E/flutter ( 2286): #0 BuiltJsonSerializers._deserialize
package:built_value/src/built_json_serializers.dart:178
E/flutter ( 2286): #1 BuiltJsonSerializers.deserialize
package:built_value/src/built_json_serializers.dart:124
It's clear it is fetching the expected result but it cannot deserialize properly, then it returns a null result.
Is there any workaround?
UPDATE 2
I've tried this solution but I'm getting same error.
In my case, I've followed these steps, I've
installed built_value package,
edited build.yaml file,
run the command flutter packages pub run build_runner build

The answer can be found in this issue.

Related

Twitter API 2.0 - Unable to fetch user.fields

I am using API version 2.0 and unable to fetch the user.fields results. All other parameters seem to be returning results correctly. I'm following this documentation.
url = "https://api.twitter.com/2/tweets/search/all"
query_params = {
"query": "APPL",
"max_results": "10",
"tweet.fields": "created_at,lang,text,author_id",
"user.fields": "name,username,created_at,location",
"expansions": "referenced_tweets.id.author_id",
}
response = requests.request("GET", url, headers=headers, params=query_params).json()
Sample result:
{
'author_id': '1251347502013521925',
'text': 'All conspiracy. But watch for bad news on Apple. Such a vulnerable stocktechnically for the biggest market cap # $2.1T ( Thanks Jay). This is the glue for the bulls. But, they stopped innovating when Steve died, built a fancy office and split the stock. $appl',
'lang': 'en',
'created_at': '2021-06-05T02:33:48.000Z',
'id': '1401004298738311168',
'referenced_tweets': [{
'type': 'retweeted',
'id': '1401004298738311168'
}]
}
As you can see, the following information is not returned: name, username, and location.
Any idea how to retrieve this info?
Your query does actually return the correct data. I tested this myself.
A full example response will be structured like this:
{
"data": [
{
"created_at": "2021-06-05T02:33:48.000Z",
"lang": "en",
"id": "1401004298738311168",
"text": "All conspiracy. But watch for bad news on Apple. Such a vulnerable stocktechnically for the biggest market cap # $2.1T ( Thanks Jay). This is the glue for the bulls. But, they stopped innovating when Steve died, built a fancy office and split the stock. $appl",
"author_id": "1251347502013521925",
"referenced_tweets": [
{
"type": "retweeted",
"id": "1401004298738311168"
}
]
}
],
"includes": {
"users": [
{
"name": "Gary Casper",
"id": "1251347502013521925",
"username": "Hisel1979",
"created_at": "2020-07-11T13:39:58.000Z"
}
]
}
}
The sample result you provided comes from within the data object. However, the expanded object data will be nested in the includes object (in your case name, username, and location). The corresponding user object can be referenced via the author_id field.

MS Graph - Access Reviews - recurrenceType Dependency?

I am able to create an access review using this JSON:
{
"displayName": "Test-review-2 Group Membership Review",
"startDateTime":"2020-01-15T00:00:11.111Z",
"endDateTime":"2020-04-04T00:00:11.111Z",
"reviewedEntity":
{
"id": "f4b4b660-a6c2-4b1f-bb16-75f81432a63e"
},
"reviewerType" : "entityOwners",
"businessFlowTemplateId": "6e4f3d20-c5c3-407f-9695-8460952bcc68",
"description":"Access Review for the AAD group:Test-review-2(f4b4b660-a6c2-4b1f-bb16-75f81432a63e)",
"settings":
{
"mailNotificationsEnabled":true,
"remindersEnabled": true,
"justificationRequiredOnApproval":true,
"autoReviewEnabled":false,
"activityDurationInDays":365,
"autoApplyReviewResultsEnabled":true,
"accessRecommendationsEnabled":false,
"recurrenceSettings":
{
"recurrenceType":"onetime",
"recurrenceEndType":"occurrences",
"durationInDays":7,
"recurrenceCount":3
},
"autoReviewSettings":{
"notReviewedResult":"Approve"
}
}
}
If I change the recurrenceType to "weekly", I suddenly get an error:
Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.AggregateException: One or more errors occurred. (Message: An error has occurred.
Inner error:
AdditionalData:
request-id: c1ba20d2-4fbb-45e4-ac89-a7f0ebb650ba
date: 2020-01-14T19:54:42
ClientRequestId: c1ba20d2-4fbb-45e4-ac89-a7f0ebb650ba
)
---> Status Code: InternalServerError
Microsoft.Graph.ServiceException: Message: An error has occurred.
Inner error:
AdditionalData:
request-id: c1ba20d2-4fbb-45e4-ac89-a7f0ebb650ba
date: 2020-01-14T19:54:42
ClientRequestId: c1ba20d2-4fbb-45e4-ac89-a7f0ebb650ba
I have looked through the documentation, and can't understand why.. Is there a dependent property I'm missing?
It looks like, in your example, recurrenceSettings is being passed in with the following values:
"recurrenceSettings":
{
"recurrenceType":"weekly",
"recurrenceEndType":"occurrences",
"durationInDays":7,
"recurrenceCount":3
},
"autoReviewSettings":{
"notReviewedResult":"Approve"
}
There are limits to the duration in days that one can specify for recurring reviews:
weekly -> 6
monthly -> 27
quarterly -> 80
annual -> 360
The durationInDays value that you’re passing for recurrenceType weekly is greater than the allowed maximum(6). Please try setting a value less than 7.

Lua script fails but the JS works in console

I have this very basic lua script that returns an error, but running the querySelector directly in the console works just fine.
Any hints on what is wrong with my lua?
function main(splash, args)
assert(splash:go(args.url))
assert(splash:wait(1))
assert(splash:runjs('document.querySelector("button.btn.btn-primary.btn-show-rates").click()'))
splash:set_viewport_full()
return {
html = splash:html(),
}
end
BTW: website is here
Error log:
{
"type": "ScriptError",
"error": 400,
"info": {
"type": "LUA_ERROR",
"line_number": 4,
"error": "JS error: 'TypeError: null is not an object (evaluating \\'document.querySelector(\"button.btn.btn-primary.btn-show-rates\").click\\')'",
"message": "Lua error: [string \"function main(splash, args)\r...\"]:4: JS error: 'TypeError: null is not an object (evaluating \\'document.querySelector(\"button.btn.btn-primary.btn-show-rates\").click\\')'",
"source": "[string \"function main(splash, args)\r...\"]"
},
"description": "Error happened while executing Lua script"
}
Turns out it was kinda simple...
A slightly longer "wait" and changing to document.querySelectorAll made it work. Final code here:
function main(splash, args)
assert(splash:go(args.url))
assert(splash:wait(5.0))
assert(splash:runjs('document.querySelectorAll("button.btn.btn-primary.btn-show-rates")[0].click()'))
assert(splash:runjs('document.querySelectorAll("button.btn.btn-primary.btn-show-rates")[1].click()'))
assert(splash:runjs('document.querySelectorAll("button.btn.btn-primary.btn-show-rates")[2].click()'))
splash:set_viewport_full()
return {
html = splash:html(),
}
end

Date-time format in the JIRA REST API giving error response Operation value must be a string

I am passing the below JOSN with the POST request to create the Jira issue. One of the parameters is the starting date and time (customfield_10603
).On the JIRA app we have date and time picker for this field.
In what format this value should be sent out. I tried with 2018-06-17T00:00:00.0+0000.
JSON sent:
{
"fields": {
"project":
{
"key": "HOA"
},
"summary": "Test ticket for JIRA_Jenkins integration.",
"customfield_10616":{"value":"Other"},
"description": "Creating of an issue using project keys and issue type names using the REST API",
"customfield_10603": {"value":"2018-06-17T00:00:00.0+0000"},
"issuetype": {"name": "Change Request" },
"customfield_10624": {"value":"Low"},
"customfield_12100": {"value" :"Low"},
"customfield_10625": {"value":"SRE"},
"customfield_10615": {"value":"Routine"}
}
}
received response:
{
"errorMessages": [],
"errors": {
"customfield_10603": "Operation value must be a string"
}
}
Found the solution.
"customfield_10603": "2018-06-17T00:00:00.0+0000".

Submitting a transaction via RESTful API (how to handle transactionid and timestamp)

Problem:
I am unable to POST a transaction via the RESTful API generated by the composer-rest-server. I am receiving statusCode 422; the transaction instance is not valid. However, the same example works in the Playground.
Scenario:
I've set up a transaction called Offer in my .cto file which posts an offer to buy a house:
// Offer - Specifies an offer that a bidder places on a house listing with an associated price
transaction Offer {
o Double bidPrice
--> HouseListing listing
--> Person bidder
}
The composer-rest-server has generated an API with the following JSON string to post a transaction of type Offer:
{
"$class": "org.acme.purchasing.Offer",
"bidPrice": 0,
"listing": "string",
"bidder": "string",
"transactionId": "string",
"timestamp": "2017-07-21T13:37:09.460Z"
}
I've since replaced this with a sample transaction using the following JSON code derived from the above example:
{
"$class": "org.acme.purchasing.Offer",
"bidPrice": 1000,
"listing": "001",
"bidder": "RJOHNSON",
"transactionId": "1b9aa63c-dfad-4aad-a610-dfc80f2796b2",
"timestamp": "2017-07-21T13:37:09.460Z"
}
The response returned is error code 422:
{
"error": {
"statusCode": 422,
"name": "ValidationError",
"message": "The `Offer` instance is not valid. Details: `transactionId` can't be set (value: \"1b9aa63c-dfad-4aad-a610-d...6b2\").",
"details": {
"context": "Offer",
"codes": {
"transactionId": [
"absence"
]
},
"messages": {
"transactionId": [
"can't be set"
]
}
},
"stack": "ValidationError: The `Offer` instance is not valid. Details: `transactionId` can't be set (value: \"1b9aa63c-dfad-4aad-a610-d...6b2\").\n at /usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/dao.js:355:12\n at ModelConstructor.<anonymous> (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/validations.js:566:11)\n at ModelConstructor.next (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/hooks.js:93:12)\n at ModelConstructor.<anonymous> (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/validations.js:563:23)\n at ModelConstructor.trigger (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/hooks.js:83:12)\n at ModelConstructor.Validatable.isValid (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/validations.js:529:8)\n at /usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/dao.js:351:9\n at doNotify (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n at doNotify (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n at doNotify (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n at doNotify (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n at Function.ObserverMixin._notifyBaseObservers (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:178:5)\n at Function.ObserverMixin.notifyObserversOf (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\n at Function.ObserverMixin._notifyBaseObservers (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:176:15)\n at Function.ObserverMixin.notifyObserversOf (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\n at Function.ObserverMixin._notifyBaseObservers (/usr/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:176:15)"
}
}
Now the strange thing is that I've deployed the same BNA onto the Hyperledger Composer Playground and am able to execute transactions of type Offer successfully.
Note that in the Playground, "transactionId" and "timestamp" are not specified as the Playground appears to take care of these values. For example, this is what Playground proposes to me initially:
{
"$class": "org.acme.purchasing.Offer",
"bidPrice": 0,
"listing": "resource:org.acme.purchasing.HouseListing#id:7965",
"bidder": "resource:org.acme.purchasing.Person#id:4441"
}
Can anyone advise why it's saying the Offer instance is not valid? My first thought was that it's not liking the string I'm placing in "transactionId" but another Stack Overflow post points out that the transactionId is just an arbitrary UUIDv4 string which I've generated already.
Update #1: Failing even with default demo
In order to ensure by BNA is error-free, I've deployed the default carauction-demo (resembles my example closely) onto my local Hyperledger Fabric instance and deployed the composer-rest-server. I've also deployed the same BNA into the Playground. All assets and participants were created identical in both from the Explorer (local instance) and Playground. When it comes time to submit an Offer transaction:
{
"$class": "org.acme.vehicle.auction.Offer",
"bidPrice": 800,
"listing": "resource:org.acme.vehicle.auction.VehicleListing#L001",
"member": "resource:org.acme.vehicle.auction.Member#member3#acme.org"
}
This JSON was generated by the Playground and succeeds there. Copy/paste/executing into the Explorer yields a status 500 error.
{
"error": {
"statusCode": 500,
"name": "Error",
"message": "error trying invoke chaincode. Error: chaincode error (status: 500, message: Error: Object with ID 'string' in collection with ID 'Asset:org.acme.vehicle.auction.VehicleListing' does not exist)",
"stack": "Error: error trying invoke chaincode. Error: chaincode error (status: 500, message: Error: Object with ID 'string' in collection with ID 'Asset:org.acme.vehicle.auction.VehicleListing' does not exist)\n at _initializeChannel.then.then.then.then.catch (/usr/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:806:34)"
}
}
I'm still at a lost as to what is wrong here.
After much experimentation and some searching, I've concluded that the problem was that NPM was installed using sudo (as root). I redid the installation as non-root and the problem has now been solved. Everything is working as expected.
Composer updates the transactionId itself as its generated, you cannot do this in your JSON and hence why you get the error. This is a Loopback -> Swagger conversion issue as it should not appear in a /POST REST operation - captured here https://github.com/hyperledger/composer/issues/663
So I have successfully executed Offer transactions (/POST). I think the '500' error is because there is a missing field ('string' type), or relationship in your Offer transaction via REST.
Using the example of the Car Auction network https://github.com/hyperledger/composer-sample-networks/blob/master/packages/carauction-network/models/auction.cto
Either of these Offer transactions using /POST were successful in Explorer:
{
"$class": "org.acme.vehicle.auction.Offer",
"bidPrice": 20,
"listing": "org.acme.vehicle.auction.VehicleListing#100",
"member": "org.acme.vehicle.auction.Member#a#b.com"
}
OR
{
"$class": "org.acme.vehicle.auction.Offer",
"bidPrice": 20,
"listing": "org.acme.vehicle.auction.VehicleListing#100",
"member": "org.acme.vehicle.auction.Member#a#b.com",
"timestamp": "2017-07-28T14:07:02.558Z"
}
responded with a 200 (SUCCESS) and a transactionId in Explorer:
{
"$class": "org.acme.vehicle.auction.Offer",
"bidPrice": 20,
"listing": "org.acme.vehicle.auction.VehicleListing#100",
"member": "org.acme.vehicle.auction.Member#a#b.com",
"transactionId": "e75b9934-1f08-4daf-90db-702bbe4b8fa1"
}
This is my VehicleListing asset JSON for #100 above
{
"$class": "org.acme.vehicle.auction.VehicleListing",
"listingId": "100",
"reservePrice": 50,
"description": "string",
"state": "FOR_SALE",
"offers": [
{
"$class": "org.acme.vehicle.auction.Offer",
"bidPrice": 50,
"listing": "100",
"member": "resource:org.acme.vehicle.auction.Member#a#b.com",
"transactionId": "string123",
"timestamp": "2017-07-28T14:07:02.825Z"
}
],
"vehicle": "resource:org.acme.vehicle.auction.Vehicle#123"
}
And I created asset for Vehicle 123 as well as Member a#b.com

Resources