graphql
graphql copied to clipboard
how to query sub field without Resolve
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
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.
define a solver for ”me“, just return any thing。