I have recently started looking into integrating FastAPI with Ariadne to create an API. For simple type this is working fine but I am now looking to enable the user to save / retrieve any python dict using the API.
It's not clear to me how custom scalars could be leveraged to complete the operation.
I would have schema.graphql
scalar Generic
type UserData {
name: String!
data: Generic!
}
Where Generic could be any object which can be parsed as a Json dictionary. I wonder what would be required in terms of resolver to persist and retrieve the data for this scenario ?
You would need to introduce your
Generic
as a scalar type in your service's code, withparse
andserialize
methods that just passed through any value (or, by your description, any dictionary / JSON object) literally. That would then allow it to pass into and out of your GraphQL service.To avoid doubt: this means you need to influence the available types for your service, rather than using a resolver to influence the behaviour of a particular field.