I've been using github.com/graphql-go/graphql
library for my GraphQL project.
Currently, I'm trying to add authorization middleware to the following query.
Using github.com/99designs/gqlgen
library we can achieve this by adding Directives
. But couldn't find a proper example to do so using github.com/graphql-go/graphql
.
query := graphql.NewObject(graphql.ObjectConfig{
Name: "RootQuery",
Fields: graphql.Fields{
"user": &graphql.Field{
Type: userType,
Description: "Get a user by ID.",
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{Type: graphql.ID},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
...
return user
},
},
},
})
Can anyone please suggest how I can add Authorization middleware
to this resolver ?