99designs / 99designs/gqlgen

Example of using InterceptRootField with error inside the Interceptor

Ouverte
#2,700 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Go
Étoiles
10.8k
Forks
1.3k
Merge moyen
2 j 36 min
PR mergées (30 j)
26

Description

### I am using InterceptRootField as following
```
func (a MyExtension) InterceptRootField(ctx context.Context, next graphql.RootResolver) graphql.Marshaler {

fc := graphql.GetRootFieldContext(ctx)

if fc.Object == "__schema" {
return next(ctx)
}

if fc.Field.Definition != nil && fc.Field.Definition.Directives != nil {
dir := fc.Field.Definition.Directives
if dir.ForName("IgnoreAuth") != nil {
return next(ctx)
}
}

err, ok := ctx.Value(CtxAuthKeyError).(error)
if ok {
log.Err(err).Msg("error while authentication in core gql")
graphql.AddError(ctx, dErrors.Err401(err.Error()).GQLError(ctx))
return graphql.Null
}

sess := session.GetSessionFromRequestContext(ctx)
if sess == nil {
log.Err(err).Msg("error while authentication, nil session container")

graphql.AddError(ctx, dErrors.Err401("error while authentication, nil session container"))
return graphql.Null
}

return next(ctx)
}
```

### My schema looks like this
```
directive @IgnoreAuth on FIELD_DEFINITION
extend type Mutation{
apiFirst: Response! @IgnoreAuth
apiSecond: Response!
}
```

### Mutation api that i called

```
mutation multiApis {
apiFirst {
status
}
apiSecond {
status
}
}
```

### What did you expect?
In the above example, i have one api which continues execution, and another send a `graphql.Null` marshaller for second response since my api validation fails.

But i am not getting the data for the first api response, and data is null with an error.

What am i doing wrong? Or is this expected ?

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.