Closed
Description
Hi there,
I have run into a little trouble making an Apollo frontend play nice with my Juniper + Diesel + Rocket backend specifically in handling NaiveDateTime values within an input object
I have a GraphQL input object
use chrono::NaiveDateTime;
#[derive(juniper::GraphQLInputObject, Insertable, AsChangeset)]
#[table_name = "certificates"]
pub struct NewCertificate {
pub name: String,
pub version: i32,
pub serial_no: String,
pub pub_key: String,
pub valid_from: NaiveDateTime,
pub valid_till: NaiveDateTime,
pub service_id: i32,
}
this is called in
fn create_certificate(context: &Context, data: NewCertificate) -> FieldResult<Certificate> {
Ok(
diesel::insert_into(certificates::table)
.values(&data)
.get_result(&context.db.get().unwrap())?
)
}
which behaves fine from graphiql as an inline declaration
mutation{
createCertificate(
data: {
name:"cert.domain.net",
version:3,
serialNo:"2F:F2:B3:F1:9B:9A:9A:07:B9:F2:C0:69:12:62:C8:F8",
pubKey:"EE:11:57:13:16:4F:C3:1C:7C:E1:15:8D:C7:F9:4B:01:EA:47:D1:46:93:78:C7:08:B3:BD:7F:D2:91:64:BE:C9",
validFrom:1601942400,
validTill:1696550400,
serviceId:12
}
)
{
id
name
}
}
but doesn't play so nice when called as a variable in a query
mutation($certificate: NewCertificate!){
createCertificate(data: $certificate){
id
name
version
serialNo
pubKey
validFrom
validTill
}
}
with the query variables
{
"certificate": {
"name": "cert.domain.net",
"version": 3,
"serialNo": "2F:F2:B3:F1:9B:9A:9A:07:B9:F2:C0:69:12:62:C8:F8",
"pubKey": "EE:11:57:13:16:4F:C3:1C:7C:E1:15:8D:C7:F9:4B:01:EA:47:D1:46:93:78:C7:08:B3:BD:7F:D2:91:64:BE:C9",
"validFrom": 1601942400,
"validTill": 1696550400,
"serviceId":12
}
}
there we run into the rejection
{
"errors": [
{
"message": "Variable \"$certificate\" got invalid value. In field \"validFrom\": Expected \"NaiveDateTime\".",
"locations": [
{
"line": 1,
"column": 10
}
]
},
{
"message": "Variable \"$certificate\" got invalid value. In field \"validTill\": Expected \"NaiveDateTime\".",
"locations": [
{
"line": 1,
"column": 10
}
]
}
]
}
not sure if this is a mistake of wrong import or an issue somewhere else but I would have imagined it should be handling variables the same as inline declarations.
Cheers
Pearce