I am trying to do a multiple insert using a REST API exposed by Hasura (written in GraphQL). This is my mutation:
mutation insertMultipleMeasurements2($payload: [measurements_insert_input!]!) {
insert_measurements(objects: $payload) {
returning {
time
}
}
}
and this is the definition of measurements_insert_input in the Actions tab:
input measurements_insert_input {
device: String!
value: numeric!
variable: String!
}
(which btw is the only way I found to insert an object of numeric type in a bulk insert).
When I try to insert something like:
[
{
"device": "TEST",
"value": 5630,
"variable": "Length"
},
{
"device": "TEST",
"value": 5631,
"variable": "Length"
}
]
I get:
{
"path": "$",
"error": "expecting a value for non-nullable variable: \"payload\"",
"code": "validation-failed"
}
I tried many different ways to rewrite my mutation but looks like none worked. Thanks in advance
Based on the error message
"expecting a value for non-nullable variable: "payload""
you should be passing the array via an object
{
payload: [
{
"device": "TEST",
"value": 5630,
"variable": "Length"
},
{
"device": "TEST",
"value": 5631,
"variable": "Length"
}
]
}