How can I return arbitrary json from ariadne? #591
Unanswered
shivshankardayal
asked this question in
Q&A
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. |
1 reply
|
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. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I have a FastAPI aridne app and I need to return arbitrary json from one of the resolvers. How can I achieve that?
All reactions