Deserialize(Error("invalid type: map, expected a string", line: 1, column: 207))'
Hello, I'm trying to map Strapi response but I'm having issues deserializing this schema type:
type UploadFile {
name: String!
alternativeText: String
caption: String
width: Int
height: Int
formats: JSON
hash: String!
ext: String
mime: String!
size: Float!
url: String!
previewUrl: String
provider: String!
provider_metadata: JSON
related: [GenericMorph]
createdAt: DateTime
updatedAt: DateTime
}
that querygen-web mapped as
#[derive(cynic::QueryFragment, Serialize, Debug)]
pub struct UploadFile {
pub alternative_text: Option<String>,
pub caption: Option<String>,
pub ext: Option<String>,
pub formats: Option<Json>,
pub hash: String,
pub height: Option<i32>,
pub mime: String,
pub name: String,
pub width: Option<i32>,
pub url: String,
pub size: f64,
pub created_at: Option<DateTime>,
pub updated_at: Option<DateTime>,
}
the error is Deserialize(Error("invalid type: map, expected a string", line: 1, column: 207))'
where in schema I have:
# The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
scalar JSON
and in generated code I have:
#[derive(cynic::Scalar, Debug, Clone)]
#[cynic(graphql_type = "JSON")]
pub struct Json(pub String);
This scalar should be mapped as:
#[derive(cynic::Scalar, Debug, Clone)]
#[cynic(graphql_type = "JSON")]
pub struct Json(pub serde_json::Value);
Hi @kiuma, thanks for the report.
Sorry about this, but the generator doesn’t really make any effort to map custom scalars like JSON into their correct rust type. The output of the generator is mostly meant to be a best effort attempt to get you going, but won't necessarily output something that’s usable without changes.
That being said, JSON is quite a common custom scalar so I should maybe add support for it 😅
I’d suggest you update it in your codebase for now. I will probably try and add support for the common ones in the future though, it should be quite easy to do. Sorry for the hassle