99designs / 99designs/gqlgen

Adding directive to specific field

Ouverte
#2,433 2 commentaires 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

### What happened?
I created an Auth directive and passed it to just one query but seems like no query works if that single one fails. This is not the given expectation
### What did you expect?

I wan only the only query to reflect this directive
### Minimal graphql.schema and models to reproduce

```
directive @auth on FIELD_DEFINITION

type Data {
code: Int!
status: String!
message: String!
packages: [String!]!
}

type PackageData {
code: Int!
status: String!
message: String!
package: String!
}

type Query {
completedPackages(limit: Int!, page: Int!): Data!
getPackage(id: ID!): PackageData!
activePackages(limit: Int!, page: Int!): Data! @auth
}

func Auth(ctx context.Context, obj interface{}, next graphql.Resolver) (interface{}, error) {
tokenData, err := middleware.CtxValue(ctx)
if err != nil {
return nil, err
}
if tokenData == nil {
return nil, &gqlerror.Error{
Message: "Access Denied",
}
}

return next(ctx)
}

func GraphqlHandler(db *mongo.Database) gin.HandlerFunc {
// NewExecutableSchema and Config are in the generated.go file
// Resolver is in the resolver.go file
c := generated.Config{Resolvers: &graph.Resolver{Collection: db.Collection("deliveries")}}
c.Directives.Auth = directives.Auth
h := handler.NewDefaultServer(
generated.NewExecutableSchema(c))

return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}
```

### versions
- `go run github.com/99designs/gqlgen 0.17.20`?
- `go version 1.19`?

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.