Search code examples
graphqlgraphene-python

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?


Solution

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