Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
  • 18:54
    DENKweit closed #1555
  • 18:54
    DENKweit commented #1555
  • 18:53
    DENKweit commented #1556
  • 17:56
    maxifom closed #1559
  • 17:56
    maxifom commented #1559
  • 17:32
    acelot commented #1559
  • 17:04
    maxifom opened #1559
  • 16:09
    n-e opened #1558
  • 09:25
    1271 commented #1556
  • Jun 22 20:57
    livictoria opened #1557
  • Jun 22 20:55
    DENKweit opened #1556
  • Jun 22 20:39
    DENKweit opened #1555
  • Jun 21 21:24
    AndrewRayCode commented #1256
  • Jun 19 20:11
    Matts966 commented #1483
  • Jun 19 19:19
    Matts966 commented #1365
  • Jun 19 06:30
    acelot commented #1554
  • Jun 18 19:10
    hews commented #1550
  • Jun 18 19:08
    hews commented #1550
  • Jun 16 18:36
    crvarner commented #1467
  • Jun 16 13:52
    acelot opened #1554
alexander ikeh

And from your yml I see the model package directing to generated.go

It suppose to be model.gen.go or your custom model.go

Kirill Tatchihin

And from your yml I see the model package directing to generated.go

It suppose to be model.gen.go or your custom model.go

this is my bind for generated code dedicated to enums

This message was deleted

After you modify the schema, delete the schema.resolver file before you run

go run github.com/99designs/gqlgen

not works for me :( after it, I find out that inside of schema.resolver there is no realized resolvers, only:

func (r *queryResolver)Users(ctx context.Context) (*models.UsersOuput, error) {
    panic(fmt.Errorf("not implemented"))
alexander ikeh
Can I see your schema file?
Kirill Tatchihin
Let me explain my ideal solution:
I would like to have the possibility to split my schema and dedicated resolvers to a couple of files and then maintain them instead of maintaining file with graphql schema and big resolver file.
Can I see your schema file?
directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITION

directive @goModel(model: String, models: [String!]) on OBJECT
    | SCALAR
    | ENUM
    | UNION

type Query {
    users: UsersOutput!

Kirill Tatchihin
and my file with output types:
type User @goModel(model: "blog/models.User") {
    id: ID!
    name: String!

type UsersOuput @goModel(model: "blog/models.UsersOutput") {
    users: [User!]
alexander ikeh

Okay I get. Then I think you will get only the query resolver because you only specified the query resolver.

And I also don’t think you can have more thank big resolver file.

But can you try to create two different schemas and dir them in the yml file?

Kirill Tatchihin
It was just an example, in reality I have big schema and I would like to split resolvers for it's fields to a couple of files
alexander ikeh
The way gqlgen is structured. I am not sure you can have more than one resolver file. If you do find a solution pls let us know
Kirill Tatchihin
Thomas Jackson
I have a potentially odd question. I am trying to make call a to gql resolver within a query. Specifically the client asks for "foo" and foo is generated by inputting the result of a graphql query -- specifically the gql generated model type. So ideally I'd be able to use the resolver to do so (since it already has all the loading logic implemented). But this "subquery" isn't part of the user request; so I'm trying to create another request to run against the same resolver -- but running into snags (as this doesn't seem like a use-case others do, or at least isn't documented). Any pointers in trying to achieve this?
it seems the closest I have found is someone trying to do it outside of a handler (99designs/gqlgen#770) but there was never a response there :/
Karthik Venkateswaran

Hello folks, I am trying to generate only Go types from schema.graphql. Is there a way to achieve that? If I don't have resolver and generated entries in my gqlgen.yaml, gqlgen generates generated and resolver.

Is there a specific configuration for this?

Edit: The use case is to generate types for go clients

Thanks in advance

Bhaskar Saraogi
Hi, is there a way to omitempty(i.e not send nil/empty fields back in response) ? I tried a model hook to add omitempty to json tag of generated models but that doesnt prevent sending out nil/empty fields as "null" value in response
Kaarthik Rao Bekal Radhakrishna
Is there a way to grab the operation execution time from the OperationContext? TIA
Randy Lough
Is there a good way to add to the ast.Path, like an index? One of my operations is a bulk operation that takes a slice of elements. If there's an error I'd like to append the index of element where the error occurred. As of right now only the general path to the resolver is returned
@bhaskarsaraogi_twitter add omit_slice_element_pointers: true to your gqlgen.yml file
Randy Lough
@bhaskarsaraogi_twitter on non slice elements I'm not sure if you can since GraphQL by design you return the requested fields, so if you omit one that was requested, you're breaking the rules. I could be wrong on that, but that was always my understanding
2 replies
Randy Lough
I think I got the ast.Path to work for now using a makeshift appender using context
Randy Lough
Another question: is there a hook / middleware I can leverage that is called right before the response is sent? AroundOperations seems to be called first, then AroundResponses and then AroundFields, but this can be called multiple times. I'm looking for a hook that is called once and at the very end. My use case is I have nested mutations, and if a nested mutation fails I would like to rollback. So I would start the transaction at the start of the request and if there's an error anywhere in the request/operation I can rollback otherwise commit. If anyone has any suggestions on how to implement that I would appreciate it
Kishyr Ramdial
Hi everyone. I'm having a bit of a weird issue that I'm trying to narrow down. Every so often (can be within days, hours or within 30 minutes) I start getting 'too many open files' log messages in syslog. When I run lsof, I see hundreds of sock connections to my gqlgen-based server. I've already changed the open-files limit on my OS. I have 3 subscriptions, my app is private and only developers are connecting to it. It "feels" like the websocket part of my server is not closing these connections. Has this happened to any of you, or do you have any tips for me?
Emil Shakirov
Hello everyone!
Is it possible to force gqlgen to throw an error when there is a mismatch between enum values between the resolver response and the schema?
Currently, if the resolver returns enum field with a value that is different from schema definition, it silently renders it into the response without any error.
Is it expected behavior? Should the validation logic for enum be implemented separately?
Anyone got any examples of testing resolvers? ideally unit testing i guess...
Jeremy Marshall
@NickBlow I have this which is my top level tests using ginkgo/gomega. Its a frontend to a Kube controller. It uses a fake/mock kube api


Say I have a custom ID implementation (called GlobalID), but my models all contain a string ID. Can I point gqlgen into a function that converts a string to GlobalID
instead of it generating ID resolvers for every model?

Alik Send

@yuvalt7 better yet https://gqlgen.com/reference/scalars/#custom-scalars-with-third-party-types

    model: path/to/your/file.GlobalID

and in file implement MarshalGlobalID and UnmarshalGlobalID functions

Alik Send

Hi. I created fix for #965 ("Support fields that return top level operations"): #1200
The final implementation contains:

  • generating models without fields for root types (Query, Mutation etc) (plugin/modelgen/models.go)
  • skip generating resolver for field with root type and always return empty struct (codegen/field.go, codegen/field.gotpl)
  • fixes for templates to pass necessary number params to generated methods (codegen/type.gotpl that depends on codegen/config.TypeReference's Root field, that added in codegen/config/binder.go)

Also there are small improvements like adding IsRootDefinition method to Config to not to repeat def == c.Schema.Query || def == c.Schema.Mutation || def == c.Schema.Subscription everywhere

Who can review and merge it?

Build fails because generator on CI for some reason creates oneline methods instead of multiline:

-func (r *Resolver) BackedByInterface() BackedByInterfaceResolver {
-    return &backedByInterfaceResolver{r}
+func (r *Resolver) BackedByInterface() BackedByInterfaceResolver { return &backedByInterfaceResolver{r} }


Alik Send
I can fix it in my PR but then check-fmt will fail
Alik Send

fix for #965

For #956 *

Akhil Indurti

Hey folks, my team’s use-case requires creating and destroying connections/pool at the resolver-level. We want to destroy these connections when a parent and its children are done. Is there any way to know, for a particular parent, when its child resolvers have finished executing?


Kirill Tatchihin
hello everyone! I would like to access field context in dataloader’s fetch function, can I do this?
1 reply

Has anyone got gqlgen run within a bazel project?

It fails with "merging failed: unable to find type github.com/99designs/gqlgen/graphql.Boolean". vendor directory does have these types. I guess I am not able to tell gqlgen (or go) to look for the types in vendor directory.

@vektah ^, please help.
any example Unmarshal & Marshal primitive.ObjectID for MongoDB for model ? I want make scalar ObjectID to primitive.ObjectID

I was put this

      - go.mongodb.org/mongo-driver/bson/primitive.ObjectID

it was created on my model_gen.go
I got error validates like this : validation failed: packages.Load: .../resolver/generated.go ec.unmarshalInputObjectID undefined (type *executionContext has no field or method unmarshalInputObjectID)

I am afraid when into production this will make issue on my app ,
any idea?

trying again like this:
func MarshalObjectID(v primitive.ObjectID) graphql.Marshaler {
    return graphql.WriterFunc(func(w io.Writer) {
        err := json.NewEncoder(w).Encode(v)
        if err != nil {

func UnmarshalObjectID(v primitive.ObjectID) (primitive.ObjectID, error) {
    return v, nil
cannot use v (variable of type interface{}) as primitive.ObjectID value in argument to model.UnmarshalObjectID
4 replies
Swarup Donepudi
Anyone using Galen to run a subscription server?
2 replies

is there any example for Add header in Testing with gqlgen ?

testClient.AddHeader("Token",  TOKEN_HERE)

I wrap them in MustPost() but got token contains an invalid number of segment I bet the header was nil or can't set up

Swarup Donepudi
@vektah do you know if anyone is using gqlgen to run a subscription server.?
Kaarthik Rao Bekal Radhakrishna
Has anyone bound a graphql type that implements an interface to a protobuf message?
Eric Meier
@swarupdonepudi i am
Nur Kutlugallyamov
Hi everyone. Could you look at my PR(#1209) and give me feedback?
Does the package need this (un)marshaler?
What should I add or remove from PR(#1209)?

Can I create type with query: Query! field?

I am trying to generate by

type Login {
  query: Query!
  user: User

and get error

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x8850c3]

goroutine 1 [running]:
exit status 2