graphql-go / graphql

An implementation of GraphQL for Go / Golang
MIT License
9.86k stars 838 forks source link

how to query sub field without Resolve #621

Open wuyazi opened 2 years ago

wuyazi commented 2 years ago

this is my code:

var MeType = graphql.NewObject(graphql.ObjectConfig{
    Name: "me",
    Fields: graphql.Fields{
        "referral": &graphql.Field{
            Type: ReferralType,
            Resolve: func(p graphql.ResolveParams) (interface{}, error) {
                return proxy.GetMeReferralById(p.Context)
            },
        },
    },
})

var FIELD_API_V3_ME = graphql.Field{
    Type: MeType,
}

var ReferralType = graphql.NewObject(graphql.ObjectConfig{
    Name: "referral",
    Fields: graphql.Fields{
        "user_id": &graphql.Field{
            Type: igraphql.Int64,
        },
        "invite_by_user_id": &graphql.Field{
            Type: igraphql.Int64,
        },
    },
})

the me has no Resolve, the referral has Resolve. when i query with

{
  me{
    referral{
      user_id
    }
  }
}

i got:

{
  "data": {
    "me": null,
  }
}

and the referral Resolve func not run

bhoriuchi commented 2 years ago

is the output of proxy.GetMeReferralById(p.Context) a struct? if so try converting it to a map[string]interface{} and making sure the struct tags marshal the fields with the expected names.

younfor commented 2 years ago

define a solver for ”me“, just return any thing。