graphql icon indicating copy to clipboard operation
graphql copied to clipboard

how to query sub field without Resolve

Open wuyazi opened this issue 2 years ago • 2 comments

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

wuyazi avatar Dec 31 '21 10:12 wuyazi

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.

bhoriuchi avatar Jan 14 '22 14:01 bhoriuchi

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

younfor avatar Jun 29 '22 14:06 younfor