Arjunlal M.A
Arjunlal M.A

Reputation: 161

GraphQL Python Graphene - How do resolvers work? If there is a resolver function for each field, how does graphql know to order them?

I am a beginner at GraphQL and is having trouble grasping how resolvers really work. If there a resolver function for each field and there are multiple rows of data, how does graphQL know how to put togethers all the fields in the exact order of data?

from graphene import ObjectType, Field, String,Schema
import uuid


class HostQuery(ObjectType):
  hostname = Field(String, default_value="hostname1!", description="Host Name")
  pid = Field(String, default_value="pid", description="PID")
  display_label = Field(String, default_value="asf8dsf", description="Display Label")

  def resolve_hostname(parent,info):
    # print(f"parent : {parent}")
    # print(f"info : {info}")
    return f"Example"
  
  def resolve_pid(parent, info):
    return uuid.uuid4().hex
  
  def resolve_display_label(parent, info):
    return "LOCO-ROCO"
  
class Query(HostQuery):
  host = Field(HostQuery)
  
  def resolve_host(parent,info):
    print(parent)
    print(info)
    return parent

schema = Schema(query=Query)

query_string = ''' 
{   host
    {
        hostname
        pid
        displayLabel
    }
}
        '''

result = schema.execute(query_string)
print(result)

Also, what are root queries, root resolvers and root fields?

Upvotes: 0

Views: 60

Answers (0)

Related Questions