Rajat Shrestha
Rajat Shrestha

Reputation: 63

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?

Upvotes: 4

Views: 2095

Answers (1)

A. Dhakal
A. Dhakal

Reputation: 179

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()
)

Upvotes: 2

Related Questions