How to convert string date value to long date value using jsonata - jsonata

This is json code:
{
"Account": {
"Account name": "Filrefly",
"Date" : "2018-09-20"
}
}
I need Final output like this
{
"Account": {
"Account name": "Firefly",
"Date": 20180920
}
}

$.Account.{
"Account name": $.Accountname,
"Date":$number(($toMillis($.Date))~>$fromMillis('[Y][M][D]'))
}

Related

Get GraphQL output without second curly bracket

I have a problem. I do not want a "break" down in my GraphQL output. I have a GraphQL schema with a person. That person can have one or more interests. But unfortunately I only get a breakdown
What I mean by breakdown is the second curly brackets.
{
...
{
...
}
}
Is there an option to get the id of the person plus the id of the interests and the status without the second curly bracket?
GraphQL schema
Person
└── Interest
Query
query {
model {
allPersons{
id
name
interest {
id
status
}
}
}
}
[OUT]
{
"data": {
"model": {
"allPersons": [
{
"id": "01",
"name": "Max",
"interest ": {
"id": 4488448
"status": "active"
}
},
{
"id": "02",
"name": "Sophie",
"interest ": {
"id": 15445
"status": "deactivated"
}
},
What I want
{
{
"id": "01",
"id-interest": 4488448
"status": "active"
},
{
"id": "02",
"name": "Sophie",
"id-interest": 15445
"status": "deactivated"
},
}
What I tried but that deliver me the same result
fragment InterestTask on Interest {
id
status
}
query {
model {
allPersons{
id
interest {
...InterestTask
}
}
}
}

Simplify Contentful GraphQL query result

I am using the following graphql query to get the header from Contentful:
{
header {
name
navigationCollection {
items {
name
}
}
}
}
And this is the result I get:
{
"header"
"name": "Main Header"
"navigationCollection": {
"items" : [
{
"name": "nav1",
},
{
"name": "nav2",
}
]
}
}
I wonder if there is way to simplify the GraphQL query result to produce something like this :
{
"header"
"name": "Main Header"
"navigationItems": [
{
"name": "nav1",
},
{
"name": "nav2",
}
]
}

How to mutate a list of objects in an array as an argument in GraphQL completely

I cannot mutate a list of objects completely, because only the last element of the array will be mutated.
What already works perfectly is, if I put each element ({play_positions_id: ...}) in the array manually like here:
mutation CreateProfile {
__typename
create_profiles_item(data: {status: "draft", play_positions: [{play_positions_id: {id: "1"}}, {play_positions_id: {id: "2"}}]}) {
id
status
play_positions {
play_positions_id {
abbreviation
name
}
}
}
}
Output:
{
"data": {
"__typename": "Mutation",
"create_profiles_item": {
"id": "1337",
"status": "draft",
"play_positions": [
{
"play_positions_id": {
"id": "1",
"abbreviation": "RWB",
"name": "Right Wingback"
}
},
{
"play_positions_id": {
"id": "2",
"abbreviation": "CAM",
"name": "Central Attacking Midfielder"
}
}
],
}
}
}
Since you can add many of those elements, I defined a variable/argument like here
mutation CreateProfile2($cpppi: [create_profiles_play_positions_input]) {
__typename
create_profiles_item(data: {status: "draft", play_positions: $cpppi}) {
id
status
play_positions {
play_positions_id {
id
abbreviation
name
}
}
}
}
Variable object for above:
"cpppi": {
"play_positions_id": {
"id": "1"
},
"play_positions_id": {
"id": "2
}
}
Output:
{
"data": {
"__typename": "Mutation",
"create_profiles_item": {
"id": "1338",
"play_positions": [
{
"play_positions_id": {
"id": "2",
"abbreviation": "CAM",
"name": "Central Attacking Midfielder"
}
}
],
}
}
}
Schema:
input create_profiles_input {
id: ID
status: String!
play_positions: [create_profiles_play_positions_input]
}
input create_profiles_play_positions_input {
id: ID
play_positions_id: create_play_positions_input
}
input create_play_positions_input {
id: ID
abbreviation: String
name: String
}
At the last both snippets, only the last object with the id "2" will be mutated. I need these to use the defined input type from my backend.
I figured it out. I got it wrong with the brackets in the variable. Here the solution:
"cpppi": [
{
"play_positions_id": {
"id": "1"
}
},
{
"play_positions_id": {
"id": "2"
}
}
]

How to filter GraphQL query?

I'm new to GraphQL and got stuck in a query. Well, this is sample GQL that returns every record in database:
{
viewer {
savingsAccount {
id
feed {
id
__typename
title
detail
postDate
... on TransferInEvent {
amount
originAccount {
name
}
}
... on TransferOutEvent {
amount
destinationAccount {
name
}
}
... on TransferOutReversalEvent {
amount
}
... on BillPaymentEvent {
amount
}
... on DebitPurchaseEvent {
amount
}
... on BarcodePaymentEvent {
amount
}
... on DebitWithdrawalFeeEvent {
amount
}
... on DebitWithdrawalEvent {
amount
}
}
}
}
}
Here is sample return:
{
"data": {
"viewer": {
"savingsAccount": {
"id": "5c8fe258-34fd-4bdc-bfb6-761bc78435df",
"feed": [{
"id": "5fcd6040-cf19-4dbf-be25-47d2f1a7a29b",
"__typename": "DebitPurchaseEvent",
"title": "Test",
"detail": "Test $$",
"postDate": "2020-12-06",
"amount": 59.7
}, {
"id": "5fcd5bbd-fc70-4d87-944d-d0a186559289",
"__typename": "DebitPurchaseEvent",
"title": "Test",
"detail": "Test $$",
"postDate": "2020-12-06",
"amount": 30.0
}
}
}
}
}
How do I apply filter to return some specific postDate? I mean, after, before, etc. This attribute is stored as string but I believe it is possible to do some convertion.
Thanks in advance!

Search by first item of nest field List<object> in elasticsearch

How can i search by first item of nest field type List in elasticsearch?
public class Data
{
public int Id{get;set;}
public string Name{get;set;}
public List<History> Logs{get;set;}
}
public class History
{
public byte Status { get; set; }
public string Note { get; set; }
public DateTime DateProcessed { get; set; }
}
Example, i have 3 records like as:
PUT /my_index/Data/1
{
"name": "name 1",
"logs": [
{
"status": "2",
"note": "processed",
"dateProcessed": "2016-04-11"
},
{
"status": "1",
"note": "new",
"dateProcessed": "2016-04-10"
}
]
}
PUT /my_index/Data/2
{
"name": "name 2",
"logs": [
{
"status": "1",
"note": "new",
"dateProcessed": "2016-04-11"
}
]
}
PUT /my_index/Data/3
{
"name": "name 2",
"logs": [
{
"status": "3",
"note": "error",
"dateProcessed": "2016-04-11"
},
{
"status": "1",
"note": "new",
"dateProcessed": "2016-04-10"
}
]
}
Now, i want to get records which have first item of list (field logs) with status equal 1.
In above example, result is second record.
Please help me, thank you!
You can you Script Query, but that would be very slow.
{
"filter": {
"script": {
"script": "_source.logs?.first()?.status.equals('1')"
}
}
}
Make sure to enable scripting
The way you should go seems like Nested Query.
You should define your list as Nested during mapping. Then you can write Nested Queries on them and filter your "Data" depending on inner hits of "History".

Resources