Trying to get specific row values from Monday.com using GraphQL - graphql

Trying to use this API to get column values for my board in GraphQL, I have a column named "Email" with the persons email address but I can't seem to query it - here is my query thus far.
query {
boards (ids: 341236641) {
items () {
id
name
column_values {
id
}
}
}
}
For some reason, it wont let me put the field "Email" underneath the items() or column_values
When I look at the output, the id of column_values prints out as
'column_values': [{'id': 'status'}, {'id': 'status84'}, {'id': 'average_check4'}, {'id': 'date'}, {'id': 'text9'}, {'id': 'location'}]}
I believe the "actual" column name is text9 but that doesnt seem to work either.
Anyone use this API successfully before?
Thanks!

i'm a developer at monday.com :)
The column_values fields returns a list of ColumnValue type object. In addition to the id (column ID) you've fetched for each, you could also ask for value (the json data of this cell), text (the textual representation of the value), title (The column's title) and additional_info.
Try:
query {
boards (ids: 341236641) {
items () {
id
name
column_values {
id
title
value
text
additional_info
}
}
}
}

Related

Strapi not able to filter relations value

I have two collection. post and common. I have defined common has many Post relation. The relation is called contains.
Post as component called place with country field, which is enumeration with country codes ( two character)
So relations will have posts which might have different countries.
I trying to filter the relations values. What I want is,the relation field should only have posts with specific country code.
What i have tried
/api/commons?populate[0]=contains.basic&populate[1]=basic&filters[contains][place][country][$eq]=AF&populate[2]=contains.place
But for this the relation will have posts that have different country codes.
Is it possible to filter the relations values? Or is there better way to structure this?
not sure i fully understand your data layout, however it seems that instead filtering the relation of Common you would get the data more easily if you just filter the posts:
/api/posts?filters[$and][0][common][$eq]=commonId&filters[$and][1][country][$eq]=AF
with query:
const str = qs.stringify(
{
filters: {
$and: [{ common: { $eq: 'commonId' } }, { country: { $eq: 'AF' } }],
},
},
{ encodeValuesOnly: true }
);

will graphql cause more database IO and how to resolve it?

I know graphql can use resolver to get the real value of a field, but how to decide the right level of the field?
for example, I get a scheme like this:
type Query {
product(productId: String): {
id:String
title: String
price: Float
variant: {
id: String
title: String
}
}
}
Assuming the request just need title, variant's title,
if I write resolver for the whole product like below, there is the price field not use but I read it from database.This results in unnecessary database IO.
select * from product_table where id = productId
However, if I write resolver for each single field like below, It's a large work and not elegant design.
// title resolver
select title from product_table where id = productId
// price resolver
select price from product_table where id = productId
It's the problem of graphql and is there any way to solve it?

GraphQL - How retrieve id of previous mutation, during query of multiple mutations

i would like run multiple mutations in the same query.
In the example below, i create an order and after i create a product record, concerning previously created.
I must have 2 mutations.
First, i insert an order. In output, i retrieve among others, idorder.
Then, i insert an product. This product
mutation {
createOrder(input: {
order: {
ordername: "My order"
}
}) {
order {
idorder
ordername
}
},
createProduct(input: {
product: {
quantity: 3
idrefproduct: 25 # link to refProduct
idorder: XXXX # how can i retrieve idorder from output of createOrder above ? 🤔
}
}) {
product {
idproduct
}
}
}
Real example with SQL structure :
user(iduser, othersFields);
scenarios(idscenario, iduser, name, otherFields);
cultA(idcultA, idscenario, ...); // this table need of idscenario field
cultB(idcultB, idscenario, ...); // this table need of idscenario field
cultC(idcultC, idscenario, ...); // this table need of idscenario field
how can i retrieve idorder from output of createOrder above ? 🤔
It is possible ?
If i forgot some informations, don't hesitate.
Thanks in advance.
EDIT :
With PostGraphile, plugin "postgraphile-plugin-nested-mutations" or "custom mutations" (with PL PGSQL function)
Without PostGraphile, a resolver as the example of #xadm permits this particular nested mutation.
IMHO you can search for "nested mutations" - not described here, you'll easily find examples/tutorials.
Proposed DB structure (n-to-n relation):
order{orderID,lines[{orderLineID}] } >
order_line{orderLineID, productID, anount, price} >
product {productID}
... created in nested mutations (in reverse order product>order_line>order)
Product don't need orderID, but when you ask for it [in product resolver]
query product(id) {
id
orderedRecently {
orderID
date
price
}
}
... you can simply get it (or rather many - array) from orderLines and orders tables [using simple SQL query - where price will be read from orderLines]
orderedRecently resolver can get product id from parent object (usually 1st param)
Of course you can (and should) return data as order and orderLine types (to be cached separately, normalized):
query product($id: ID!) {
product(id: $id) {
id
orderedRecently {
id
date
orderLine {
id
amount
price
}
}
}
}
where type orderedRecently: [Order!] - array can be empty, not eordered yet
update
I slightly misunderstood your requirements (naming convention) ... you already have proper db structure. Mutation can be 'feeded' with complex data/input:
mutation {
createOrder(input: {
order: {
ordername: "My order"
products: [
{
quantity: 3
idrefproduct: 25
},
{
quantity: 5
idrefproduct: 28
}
]
}
}) {
order {
id
ordername
products {
id
idrefproduct
quantity
}
}
}
}
Your product is my orderLine, idrefproduct is product.
createOrder creates/inserts order and then use its id for creation of product records (order.id, idrefproduct and quantity). Resolver can return only order id or structured data (as above).

WIX.com Primary key to be used as reference

I'm new to the WIX web development platform.
I need to use the Primary Key of Table 1 to be used as a reference of Table 2, but I cannot use the ID of table 1 for this purpose.
I wonder if the best way is to "copy" this ID in the Title field (Primary Key) of this table 1. How I do that? Is this the best method?
Thank you,
Arturo
Arturo:
Have you tried doing this without using wix code?
Check out this post to see if it is possible.
Now in code the only way to add a reference field from another data collection is to use the ID. But note that ID is the field name used in the data collection for dashboard and Editor view. When accessing the ID value in code you need to use the field key which is _id.
So in your Table2 you need a column (field) that is of type reference and give it a field name like "Table1 Reference". The editor will generate a field key for you that will look like table1Reference.
Now if you have a record from Table1 that you want to link to Table2 you do something like this:
wixData.query('Table1')
.eq('title', 'uniqueTitle')
.find()
.then((results) => {
if (results.totalCount !== 1) {
throw Error('We didn't get a record from Table1');
}
// Success add this in a new record in Table2
let table1Item = results.items[0];
let table2Data = {
table1Reference:table1Item._id,
anotherTable2Field:"Some info for table2"
};
return wixData.save('Table2', table2Data)
.then((savedRecord) => {
// Successful save!
// Do something here....
});
})
.catch((error) => {
console.log(error);
});
Good luck!
Steve

How do you join three or more tables in RethinkDB?

I have three tables: user, post, postVote.
I want to join these tables together to construct a list of posts for the current session user. vote field of each post item in the result list will be different depending on who the current session user is and for each post item. Think of how reddit voting works.
I added a compound index of ['userId', 'postId'] as userIdpostId in postVote table for faster eqJoin.
Here are table schemas:
user {
id: string
name: string
}
post {
id: string
authorId: string
title: string
}
postVote {
id: string
userId: string
postId: string
vote: number
}
Desired result:
[
{
id: string // post id
authorId: string // author user id
authorName: string // author user name
title: string // post title
vote: number // vote for this post by current session user
// default to 0, if no matching entry is found in postVote table.
}
]
I think this might do the trick.
r.table("postVotes")
.eqJoin("authorId", r.table("users"))
.eqJoin(r.row("left")("postId"), r.table("posts"))
.map(function(doc){
//...clean up doc as necessary...
}).run()
In the end you should have a document with a left and right key at the top most layer, and then another left and right contained as the top most left value. Doing the .map at the end will allow you to clean it up to your desired JSON result.
This is a bit of an approximation since I don't have your dataset, but let me know if you have any questions.

Resources