How can I return arbitrary json from ariadne? #591
Replies: 2 comments 1 reply
-
I am no longer looking for the answer as I no longer have that project with me but I will leave it for someone who might need the answer. |
Beta Was this translation helpful? Give feedback.
-
Assuming that by "return arbitrary JSON" you mean you want result returned by resolver go directly to JSON serializer and skip any other result processing that GraphQL may do, all you need to do is to define custom scalar in schema and use it for your field. Schema: scalar Generic
type Query {
test: Generic
} Resolver returning dict: def resolve_test(*_):
return {"hello": {"world": ["earth", "mars"]}} GraphQL query:
JSON with query's result: {
"data": {
"test": {
"hello": {
"world": [
"earth",
"mars"
]
}
}
}
} I've named scalar "Generic" because thats how it seems to be named most commonly in GraphQL world. Note that all data returned from resolver has to be JSON-serializable, or Ariadne will crash on response creation. |
Beta Was this translation helpful? Give feedback.
-
I have a FastAPI aridne app and I need to return arbitrary json from one of the resolvers. How can I achieve that?
Beta Was this translation helpful? Give feedback.
All reactions