gqlgen

Using two handlers for a GraphQL project; handle query with the second one if the first one is not capable of

江枫思渺然 提交于 2021-01-29 10:17:16
问题 I'm trying to use both SuperGraph as-a-library and GqlGen. So I have two handlers: the first one is SuperGraph ; this checks that it can carry out the operation the second one is GqlGen ; this checks that it can carry out the operation if the first one can't The code I'm using is this: type reqBody struct { Query string `json:"query"` } func Handler(sg *core.SuperGraph, next http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { bodyBytes, _ := ioutil.ReadAll(r

Custom error status code with gqlgen + go gin

流过昼夜 提交于 2021-01-29 07:40:49
问题 Recently I have been updating my GO REST APIs into graphQl API's and I came across issue where I am unable to customise my status code with gqlgen. Response I got Headers Status Code: 200 OK { data: null, errors: [ {message: "Unauthorized access", path: ["..."]} ] } Expected Header Status Code: 401 UNAUTHORISED Any help would be really appreciating! 回答1: Assume you have a gqlgen resolver similar to this: func (r *queryResolver) SecretItems(ctx context.Context, userID string, password string)

Custom error status code with gqlgen + go gin

戏子无情 提交于 2021-01-29 07:35:21
问题 Recently I have been updating my GO REST APIs into graphQl API's and I came across issue where I am unable to customise my status code with gqlgen. Response I got Headers Status Code: 200 OK { data: null, errors: [ {message: "Unauthorized access", path: ["..."]} ] } Expected Header Status Code: 401 UNAUTHORISED Any help would be really appreciating! 回答1: Assume you have a gqlgen resolver similar to this: func (r *queryResolver) SecretItems(ctx context.Context, userID string, password string)