Create entries in GraphQL

Hello all I try to use graphql to read and add objects to Twenty. I succeeded to get data, ie name, id and methodologies for a given "project" :
query MyQuery {
project(filter: {verraId: {eq: 4890}}) {
name
id
methodologies {
edges {
node {
id
}
}
}
}
}
query MyQuery {
project(filter: {verraId: {eq: 4890}}) {
name
id
methodologies {
edges {
node {
id
}
}
}
}
}
And I get:
{
"data": {
"project": {
"name": "Anlo wetlands",
"id": "9ae9ced6-f28c-4654-ae3d-8cdc1e035db9",
"methodologies": {
"edges": [
{
"node": {
"id": "cb2791ff-b960-40e6-95fe-2a76708fdd02"
}
}
]
}
}
}
}
{
"data": {
"project": {
"name": "Anlo wetlands",
"id": "9ae9ced6-f28c-4654-ae3d-8cdc1e035db9",
"methodologies": {
"edges": [
{
"node": {
"id": "cb2791ff-b960-40e6-95fe-2a76708fdd02"
}
}
]
}
}
}
}
If I try to create a new project :
query = gql(
"""
mutation createProject($project: ProjectCreateInput!) {
createProject(data: $project) {
id
}
}
"""
)

variables = {
"project": {
'name': name,
'countryId': id,
'verraId': vid,
'methodologies': {
'edges': [
{
'node': {
'id': mid
}
}
]
}
}
}


results = client.execute(query, variable_values=variables)
query = gql(
"""
mutation createProject($project: ProjectCreateInput!) {
createProject(data: $project) {
id
}
}
"""
)

variables = {
"project": {
'name': name,
'countryId': id,
'verraId': vid,
'methodologies': {
'edges': [
{
'node': {
'id': mid
}
}
]
}
}
}


results = client.execute(query, variable_values=variables)
It does work for simple fields as name or 1 to 1 relations but not with 1 to many (here the methodologies field could countains several Methodology objects):
gql.transport.exceptions.TransportQueryError: {'message': 'Variable "$project" got invalid value { name: "My New Project", countryId: "60d7ea0a-a5e1-4fc7-8dc8-78c1f39112a2", verraId: 1000, methodologies: { edges: [[Object]] } }; Field "methodologies" is not defined by type "ProjectCreateInput".', 'locations': [{'line': 1, 'column': 24}]}
gql.transport.exceptions.TransportQueryError: {'message': 'Variable "$project" got invalid value { name: "My New Project", countryId: "60d7ea0a-a5e1-4fc7-8dc8-78c1f39112a2", verraId: 1000, methodologies: { edges: [[Object]] } }; Field "methodologies" is not defined by type "ProjectCreateInput".', 'locations': [{'line': 1, 'column': 24}]}
Any idea how I can do that? Thanks !
7 Replies
charles
charles5mo ago
HI @iero! Glad to see you around If you want to see graphql query example, you can check your network tab on the frontend
charles
charles5mo ago
No description
charles
charles5mo ago
It will help get a better understanding on how it should look! Here you might be confusing the "variables" that are passed to the graphql fields with the "fields" that are the data you want to get back query MyQuery { tests(filter: {id: {}, name: {ilike: "a"}}) { edges { node { people { edges { node { city companyId createdAt } } } } } } }
charles
charles5mo ago
No description
charles
charles5mo ago
the variables are: filter, orderBy, after, before, limit... and filering does not support nested filters at the moment fields can be nested as far as you want (but careful of performance, every data fetch come at cost)
charles
charles5mo ago
No description
greg [iero]
greg [iero]OP5mo ago
Hello @charles Thanks for the tip with network, I will play with that and I will post the answer for others when I will get it 🙂
Want results from more Discord servers?
Add your server