Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return dictionary insted of string in Graphql using graphene

I want my graphql query to return multiple values in form of dictionary but i am only able to return the dictionary inside the string. enter image description here

class Query(ObjectType):

get_reply = String(
    question=String(),
    sender=String(),
    timestamp=String()
)

def resolve_get_reply(root, info, question, sender, timestamp):
    written_to_database = False
    reply = 'hello'
    d = {"reply": reply, "wtd": written_to_database}
    return d

The existing guides have just confused me even more. How do i define the schema for this case?

like image 616
Rajat Shrestha Avatar asked Oct 15 '25 12:10

Rajat Shrestha


1 Answers

You have set your get_reply variable as a String. You are therefore receiving a String as a response.

You can create a custom Reply class and set the get_reply as follows:

get_reply = graphene.Field(Reply, 
    question=String()
)
like image 74
A. Dhakal Avatar answered Oct 18 '25 09:10

A. Dhakal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!