Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
  • Nov 26 17:32
    zdraganov commented #1583
  • Nov 26 14:47
    RobinCPel commented #774
  • Nov 26 13:39
    RobinCPel closed #1727
  • Nov 26 13:39
    RobinCPel commented #1727
  • Nov 26 13:37
    RobinCPel commented #1728
  • Nov 26 13:35
    StevenACoffman commented #1728
  • Nov 26 13:35
    StevenACoffman labeled #1728
  • Nov 26 13:35
    StevenACoffman closed #1728
  • Nov 26 13:32
    coveralls commented #1728
  • Nov 26 13:16
    pkuk96 opened #1729
  • Nov 26 08:36
    RobinCPel synchronize #1728
  • Nov 25 22:57
    LockedThread commented #813
  • Nov 25 17:51
    zdraganov commented #1728
  • Nov 25 16:50
    coveralls commented #1728
  • Nov 25 16:48
    StevenACoffman synchronize #1728
  • Nov 25 16:38
    coveralls commented #1728
  • Nov 25 16:08
    MiguelCastillo commented #1723
  • Nov 25 15:18
    RobinCPel opened #1728
  • Nov 25 15:04
    MiguelCastillo commented #1723
  • Nov 25 15:04
    MiguelCastillo commented #1723
Jonatan Magnusson
Hey! I've built a middleware that put the session user id in Context. In my resolvers, I can then get that user id from context, fetch the user, and check the users permission based on role and other things.
Now problem is: I don't want to fetch the user from database in every resolver that needs to check authorization.
Before I wrapped my head around the problem, I was thinking I could put the user model in the context as well. But that would actually require that I mutate the context, which of course does not work.
So now I'm down to two options: use data loader or always fetch the user in the middleware, even if it's not required. Does that sound right, or is there any other option I'm missing?
Jonatan Magnusson
Just thought of a third option: if I extend the generated type with an extra "current user" field, then all sub-resolvers can get the user from there. But that would require that I don't autogenerate the type, moving further and further from the "schema first" philosophy...
Jonatan Magnusson
Similar question: I have a allUsers query that returns a UsersConnection type that has among other things a users field. As not every query will require the users field I don't want to fetch users from db in the allUsers resolver. Instead I have a custom resolver for UsersConnection.users. But allUsers has some pagination arguments that the users resolver need access to. So how can I do that? One option is to once again extend the UsersConnection type with pagination data. Does that sound right to you?
Philipp Kraus

Hello I'm new with gqlgen and I try to create a mutation with this definition:

activityConfiguration(activity: String!): ActivityConfiguration!

But I don't know how I can create the "models:" sections for this entry in my gqlgen.yml? Thanks for help

Is it possible to modify the context inside of a resolver? I'm aware of the gin's recipe and using a middleware, but can we do it in a resolver itself, which will affect other resolvers that will run later?
Jonathan Duck
@yuvalt7 I don't think you can with GQLGen's interface. The best option is probably put something mutable in the context (before passing it to GQLGen) and update that. As a hack, you could also make a mutable context you pass to GQLGen, but that would break context.Context's contract.
@duckbrain_gitlab thanks, using a mutable object in the context sounded like an anti-pattern to me and I wanted to know if there was a more main-stream way
but guess not :(
Clio Harper

Hi all! I recently discovered this project and think it's fantastic. I'm currently making a bid to get my company to switch over to Go for some of our services. As a proof of concept, I'm moving our most basic service over and came across a small issue porting the code from typescript. In our TS implementation, our directive overwrites one of the graphql arguments if the user has a certain role. Both the userId and role are set by a gateway that sits in front of all our services:

      if (roles.includes(subject.headers.role)) {
        methodArgs.userId = subject.headers['user-id'];
     return resolver(parent, methodArgs, context, ...rest);

In Go, I can get the args like so: graphql.GetResolverContext(ctx).Args but I can't seem to find a way to reassign them in my directive implementation.

Any insight would be appreciated. Thanks!

I'm struggling to understand how I'd pass a dynamodb connection to a resolver in gqlgen.
I'm actually at a lost at how it works in postgres as well.
I'm looking at a reference implementation and theres a connection being passed to a resolver here https://github.com/oshalygin/gqlgen-pg-todo-example/blob/master/resolvers/resolver.go#L9 but there doesn't seem to be a way that that connection knows the database name, or user or password to the database? It just seems to me that there is a pointer to something that doesn't exist.
its gotta be something like this ?
package graph

//go:generate go run github.com/99designs/gqlgen

import (

// This file will not be regenerated automatically.
// It serves as dependency injection for your app, add any dependencies you require here.

var sess = session.Must(session.NewSession())
var svc = dynamodb.New(sess)

type Resolver struct {
    svc *dynamodb.DynamoDB
okay I see how it happens now
Alexey Yurchenko
Hi. Why I cannot add fields with Query type? type Query { api: Query! } or type Mutation { doSome: Query! }. It produces an error but works in graphql-js
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x7ae2df]

goroutine 1 [running]:
Bogdan St─ânescu

Hi all. Is there a way to get the client's IP address for subscriptions?

It's fairly easy for queries/mutations via HTTP transport (by using a middleware similar to the authentication mechanism).
I'm not sure I can access the websocket client's IP address, and InitPayload does not contain such information

I define a union type, gqlgen help me generate its interface, but not for implementation of the union type's member type, where am I wrong
it generated a model implementation for the union, that is a interface in golang, but I need the union memeber type has the method defined by the interface
Joana Roque
hello! just wanted to ask if the project is still being maintained and what are the steps one can do to contribute :) the readme just points to this gitter room. I read in an issue that someone requested access to github discussions but there's no link anywhere
Bruno Martinez
I found an issue with the default recovery (func DefaultRecover) in combination with the default ErrorPresenter(DefaultErrorPresenter).
This cause a second panic while recovering from the first one due to a cast error.
I could propose a fix, what are the step to be allowed to contribute or to make a PR ?
Jonatan Magnusson
Hi! I have implemented some subscriptions, and today found a problem: I have subscriptions for bookings and each booking have a nested User. If I request the booking including the user with a normal query, everything works as expected. But if I use the same subfields for a subscription, user is always null.
Is this expected behavior?
I have a custom resolver for Booking.user, which does not seem to be called for subscriptions, but works as expected for queries and mutations.
Nhan Thai
Hi, seems like if I add the directive @goField(forceResolver: true) to a field, gqlgen generates both the resolver and the field inside Go struct. What do I do if I only want the resolver?
For example:
extend type Admin {
    user: User! @goField(forceResolver: true)
then I got both
func (r *adminResolver) User(ctx context.Context, obj *model.Admin) (*model.User, error) {
    panic(fmt.Errorf("not implemented"))
type Admin struct {
    User      *User     `json:"user"` <-- I don't want this
Harry Walter
Is there a hook I can use to intercept between when directives and resolvers run?:
2021/02/28 16:20:14 InterceptOperation
2021/02/28 16:20:14 InterceptResponse
2021/02/28 16:20:14 InterceptField
2021/02/28 16:20:14 Directive: todos
--- Here
2021/02/28 16:20:14 Resolver: Todos
2 replies
I need the directive to add some default value that can then be read in my hook in order to prevent the resolver running or not
Harry Walter
Or is it perhaps possible to hook into the codegen to apply a default directive?
Li Guangsheng
I'm looking for the ability to add any custom struct tags right in gql type defenition. How about 99designs/gqlgen#1173 ?
Mahendra Kumar
Hello, I'm looking for way to add constraint validation directive, but i dont see any example, can anyone help with a link?
Gabriel Balint
Hello, do you guys have any resources for using gqlgen with aws appsync?
Iko Uchiha
Hi everyone

I had a question. Is it possible to have multiple query resolvers?

as in normally, there is one /query route and then one can do say
query {
companies { name }

but I need something like.

because I need to manage access for different user type

Iko Uchiha
in gqlgen yaml file, is there a way to have multiple resolver directory ?
Iko Uchiha
I wanted to split my schema.resolvers.go into multiple packages. across directories. right now in the yaml file, there is a config called resolver: and then it has dir:, and some follow-schema. is it possible to split this into multiple packages. otherwise when there are quite a few domains it becomes cluttery. I could split it across files, but ideally I want like people/schema.resolvers.go and companies/schema.resolvers.go for separation of concerns
Iko Uchiha
is the question wrong?
Christopher Britz
wondering if there is a way in a schema directive function to know when last resolver/value is being run. I do validation for input types using directives ie minLength=1 and want to return an array of gqlerrors instead of one at a time
het jagani
Hi guys, I am having really bad with some problem when I try to decode object in a middleware. I want to access the query string of a object in middleware but I am not able to do so.. You can find the details here 99designs/gqlgen#1527. Can anyone take a look at it. Thanks in advance for any help.