how do you do nested objects in graphql - i'm using appsync and dynamodb - amazon-dynamodb

I have the following object and I want to create a schema for it that handles nested objects - what's the best way using graphql:
{
"type": "product",
"id": "411e2a2b-37e8-421e-adb8-2e038751d263",
"name": "Hazel",
"slug": "hazel",
"sku": "ENGINEERED3",
"manage_stock": false,
"description": "Abstract, sculptural, refined and edgy with a modern twist. Its symmetrical, spoked structure generates a clever geometric presence, which works well in a contemporary environment..",
"price": [
{
"amount": 11200,
"currency": "AUD",
"includes_tax": true
}
],
"status": "live",
"commodity_type": "physical",
"meta": {
"timestamps": {
"created_at": "2019-05-09T13:30:10+00:00",
"updated_at": "2019-05-09T13:45:11+00:00"
},
"display_price": {
"with_tax": {
"amount": 11200,
"currency": "AUD",
"formatted": "$112.00"
},
"without_tax": {
"amount": 11200,
"currency": "AUD",
"formatted": "$112.00"
}
},
"stock": {
"level": 0,
"availability": "out-stock"
}
}
}
It seems as though graphql wants a separate type per nested object - is that true?

Related

Sylius ShopApiPlugin Can't add products to cart

I'am trying to add a product to my cart using the ShopApiPlugin made for Sylius.
When I try to add a product thru /carts/mytokenoid/items with the json body
{
"productCode": "iphone9",
"quantity": 5
}
I get this response
{
"tokenValue": "mytokenoid",
"channel": "US_WEB",
"currency": "EUR",
"locale": "en_US",
"checkoutState": "cart",
"items": [
{
"quantity": 5,
"total": 4800,
"product": {
"code": "iphone9",
"name": "iPhone 9",
"slug": "iphone-9",
"averageRating": 0,
"taxons": {
"others": []
},
"variants": [
{
"code": "iphone9",
"axis": [],
"nameAxis": [],
"price": {
"current": 2000,
"currency": "EUR"
},
"images": []
}
],
"attributes": [],
"associations": [],
"images": []
}
}
],
"totals": {
"total": 6896,
"items": 4800,
"taxes": 0,
"shipping": 2096,
"promotion": -5200
}, (...)
But when I do /shop-api/carts/mytokenoid to check my cart content, it is empty, nothing was added. Also I checked the database and the cart is there with the correct token but no items.
Does anyone know how can I solve this? I already tried with authorization token and without. Got the same thing
Found the solution.
You just have to uncomment the "- tactician.middleware.doctrine" line in the config/packages/league_tactician.yaml

How to query CosmosDB when the Where clause data is in a subarray?

I have the following document
{
"id": "46c0ccbc-7a05-41dc-bc33-e9d1e69b74fa",
"_id": "5bf8b90f9568cf0001463719",
"vendor": "XXX",
"updatedAt": "2018-11-26T02:17:59.311Z",
"locales": [
{
"title": "351011",
"description": " ",
"categories": [
"Children",
"Accessories"
],
"brand": null,
"images": [
"https://lp.example.com/app006prod?set=source[02_0690165_001_001],type[PRODUCT],device[hdpi],quality[80],ImageVersion[2018081]&call=url[file:/product/main]"
],
"country": "SE",
"currency": "SEK",
"language": "en",
"variants": [
{
"artno": "example",
"urls": [
"https://www.example.com/en_sek/children/baby-newborn/product.cotton-cashmere-newborn-mittens-red.0690165001.html"
],
"price": 120,
"stock": 15,
"attributes": {
"size": "One Size",
"color": "Burgundy"
}
}
]
}
],
"_rid": "QEwcAOOf+rUHAAAAAAAAAA==",
"_self": "dbs/QEwcAA==/colls/QEwcAOOf+rU=/docs/QEwcAOOf+rUHAAAAAAAAAA==/",
"_etag": "\"00000e00-0000-0000-0000-5bfc890d0000\"",
"_attachments": "attachments/",
"_ts": 1543276813
}
I am trying to write a simple query that lists all documents that has "Children" as one of its Categories
I tried the following query but it does not work
SELECT * FROM c where c.locales.categories = "Children"
I am assuming I am referencing the subarrays wrong but what is the right way to write this query?
You need to use the ARRAY_CONTAINS function.
Try this: SELECT * FROM c where ARRAY_CONTAINS(c.locales[0].categories, "Children")

How can I select a filtered child document collection when querying a top level document in cosmos db

I'm trying to filter the child documents returned when querying a parent document using the sql api in cosmos db.
For example given this document:
{
"customerName": "Wallace",
"customerReference": 666777,
"orders": [
{
"date": "20181105T00:00:00",
"amount": 118.84,
"description": "Laptop Battery"
},
{
"date": "20181105T00:00:00",
"amount": 81.27,
"description": "Toner"
},
{
"date": "20181105T00:00:00",
"amount": 55.12,
"description": "Business Cards"
},
{
"date": "20181105T00:00:00",
"amount": 281.00,
"description": "Espresso Machine"
}]
}
I would like to query the customer to retrieve the name, reference and orders over 100.00 to produce a results like this
[{
"customerName": "Wallace",
"customerReference": 666777,
"orders": [
{
"date": "20181105T00:00:00",
"amount": 118.84,
"description": "Laptop Battery"
},
{
"date": "20181105T00:00:00",
"amount": 281.00,
"description": "Espresso Machine"
}]
}]
the query I have so far is as follows
SELECT c.customerName, c.customerReference, c.orders
from c
where c.customerReference = 666777
and c.orders.amount > 100
this returns an empty set
[]
and if you remove "and c.orders.amount > 100" it matches the document and returns all orders.
To reproduce this issue I simply set up a new database, added a new collection and copied the json example in as the only document. The index policy is left as the default which I've copied below.
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Spatial",
"dataType": "Point"
}
]
}
],
"excludedPaths": []
}
Cosmos DB doesn't support the deep filtering in the way I attempted in my original query.
To achieve the results described you need to use a subquery using a combination of ARRAY and VALUE as follows:
SELECT
c.customerName,
c.customerReference,
ARRAY(SELECT Value ord from ord in c.orders WHERE ord.amount > 100) orders
from c
where c.customerReference = 666777
note the use of 'ord' - 'order' is a reserved word.
The query then produces the correct result - eg
[{
"customerName": "Wallace",
"customerReference": 666777,
"orders": [
{
"date": "20181105T00:00:00",
"amount": 118.84,
"description": "Laptop Battery"
},
{
"date": "20181105T00:00:00",
"amount": 281.00,
"description": "Espresso Machine"
}
]
}]

OpenRefine reconciliation service not working - mutliple vs single queries

I have been using OpenRefine 2.6 Beta 1 w/o problems since its release, and later, with the reconciliation service at:
http://reconcile.freebaseapps.com/reconcile
However, in the past fee days, I have not been able to use it all. If I go to the URL:
http://reconcile.freebaseapps.com/
and type the multiple query:
{
"query": "Ford",
"type": "/people/person",
"properties": [
{
"pid": "/people/person/place_of_birth",
"v": "Detroit"
}
]
}
I obtain:
{
"result": [
{
"id": "/m/0j8pb6y",
"name": "Ford",
"type": [
{
"id": "/people/person",
"name": "Person"
},
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/geography/mountaineer",
"name": "Mountaineer"
}
],
"notable": [],
"score": 1.1546246,
"match": false
},
{
"id": "/m/01vd3gv",
"name": "Ford",
"type": [
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/music/artist",
"name": "Musical Artist"
}
],
"notable": [],
"score": 1.0330245999999998,
"match": false
},
{
"id": "/m/0cmdhzt",
"name": "James Meredith",
"type": [
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/people/person",
"name": "Person"
},
{
"id": "/military/military_person",
"name": "Military Person"
},
{
"id": "/people/deceased_person",
"name": "Deceased Person"
}
],
"notable": [],
"score": 0.0681692,
"match": false
}
],
"duration": 369
}
But if I try a simple query:
{
"query": "Ford"
}
I get:
Status: error Error:undefined
Any insights into what's happening with the reconciliation service? Is there any other service I could use to replace freebaseapps.com?
Thanks
Try this in Queries Parameter at http://reconcile.freebaseapps.com/
{
"q0": {
"query": "Ford"
}
}
For some reason, single queries are not accepted in Query Parameter but in Queries Parameter in the format above. I have not tested this in OpenRefine, so you might have to modify it.
I don't know for certain about the date, but Freebase was announced earlier this year as being shutdown by Jun 30, 2015, for some services. Maybe service is intermittent until full shutdown? Sorry, this answer probably doesn't help much.

Open graph fitness.runs returning no data

I have a bunch of Nike+ run data which i'm assuming (based on the below article) is published to the open graph. It certainly looks that way in my timeline.
https://developers.facebook.com/blog/post/2012/08/29/early-success-stories--fitness-and-open-graph/
Frustratingly while my music.listens request works fine and returns all of my Spotify listens, my request for fitness.runs returns no data. Is this simply because Nike haven't integrated correctly with the Open Graph. Or perhaps I need to request extended permissions in my Auth token?
https://developers.facebook.com/docs/reference/opengraph/action-type/fitness.runs
Any ideas?
As with all actions you need the correct permissions, in this case
user_actions.fitness
So the data returned from /me/fitness.runs for Nike will look like
{
"data": [
{
"id": "10101118696330517",
"from": {
"name": "Philippe Harewood",
"id": "13608786"
},
"start_time": "2013-03-22T23:15:56+0000",
"end_time": "2013-03-22T23:26:36+0000",
"publish_time": "2013-03-24T15:50:00+0000",
"application": {
"name": "Nike",
"namespace": "nikeapp",
"id": "84697719333"
},
"data": {
"course": {
"id": "476811255725972",
"url": "http://nikeplus.nike.com/plus/activity/running/detail/2118587303?external_share_id=CE32E1C4-93D8-48A7-A08F-6D5B4C13EE6A&is_new_meta=true",
"type": "fitness.course",
"title": "1.12 miles"
}
},
"type": "fitness.runs",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
},
{
"id": "10101118696155867",
"from": {
"name": "Philippe Harewood",
"id": "13608786"
},
"start_time": "2013-03-19T22:03:32+0000",
"end_time": "2013-03-19T22:18:37+0000",
"publish_time": "2013-03-24T15:49:46+0000",
"application": {
"name": "Nike",
"namespace": "nikeapp",
"id": "84697719333"
},
"data": {
"course": {
"id": "502469216483599",
"url": "http://nikeplus.nike.com/plus/activity/running/detail/2118587302?external_share_id=EBF6BC1D-BDEA-4EE5-B18D-FBC576610F13&is_new_meta=true",
"type": "fitness.course",
"title": "1.49 miles"
}
},
"type": "fitness.runs",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
}
],
"paging": {
"next": "https://graph.facebook.com/13608786/fitness.runs?limit=25&offset=25&__after_id=10101118696155867"
}
}

Resources