Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
  • Sep 24 19:20
    murnux synchronize #1359
  • Sep 24 13:54
    qhenkart edited #1635
  • Sep 24 13:53
    qhenkart opened #1635
  • Sep 24 03:02
    timoha commented #1491
  • Sep 23 20:20
    dball opened #1634
  • Sep 23 16:10
    sneko commented #957
  • Sep 23 16:02
    sneko commented #957
  • Sep 23 16:01
    sneko commented #957
  • Sep 23 12:59
    raoulk commented #1501
  • Sep 23 03:57
    mtibben review_request_removed #1623
  • Sep 22 23:13
    coveralls commented #1623
  • Sep 22 21:01
    mtibben closed #1628
  • Sep 22 20:31
    schafle opened #1633
  • Sep 22 19:37
    bluejay9676 closed #1632
  • Sep 22 19:37
    bluejay9676 opened #1632
  • Sep 22 19:34
    bqiang-wish edited #1631
  • Sep 22 19:30
    bqiang-wish edited #1631
  • Sep 22 19:29
    bqiang-wish opened #1631
  • Sep 22 19:05
    schafle opened #1630
  • Sep 22 18:28
    manbeing opened #1629
Jon Lundy
Graphql typically returns a json object for requests. Do you mean having the json embedded in a value?
Like {"res":"{\"a\":1}"}
is someone encounter problems with extensions errors ?
Tassios Marios
Hi guys,
I have a question, I am using gqlgen library with gorm library and I want to use only one model, how I can setup the gqlgen to use the already defined model ?
Thanks !
David Douglas

Hello All, been using GQLGen for a while now. Just started a fresh project today and I am getting the following error when generating the schema.

validation failed: packages.Load: -: no matching versions for query "latest"

I did some research and i think this is an error from a dependency of gqlgen

Any tips?
Andy Grunwald
Hey everyone,

First, thanks a lot for this awesome project. It helps a lot and makes a lot of fun.
I am curious, is there support for multiple GraphQL Schemas? I am not talking about splitting your Schema into multiple files. I am talking about two GraphQL schemas. One intended for a public interface and one for a backend service (e.g., an admin dashboard).
In an admin dashboard, you typically want to expose more data than in the public interface. The scenario is also described here: https://spectrum.chat/graphql/general/splitting-a-graphql-api-between-public-private~d84a2d9c-e052-422f-aedc-21c0ecc642eb

An alternative would be to create a second service from scratch and keep it 100% independent. Con here would be code duplication or it is getting tricky to share code/models.

Client ---> Public GraphQL Service ---> Database <--- Private GraphQL Service <---Backend/Admin-Dashboard

How do you think about this?
Let me know (also if this is the wrong place to ask and I should open a feature request to support multiple schemas in one instance)

Andy Grunwald
I opened up an issue to discuss this: 99designs/gqlgen#1126
Adrien D.
Hello. Is it possible to access a Resolver object from within a directive handle ?
I only see the parameter next graphql.Resolver...
Adrien D.
...or the gqlgen Config object (which typically contains the Resolvers) ?
Adrien D.
... As I am asking about directives management, I take this opportunity to ask, do the directive function handlers are executed in parallel ? What would be a good approach to use object shared by all the handlers, and call a final method when all directives passed to kind of "reduce" the result ?
John Forstmeier

Hi everyone, I've getting started using gqlgen and I had a couple questions on configuration:

  • Under what circumstances is a schema.resolvers.go file generated?
  • Is it possible to control the naming/location of this output file?
  • Where can I find an example YML file that contains all of the settings options available? E.g. other options for the resolver.layout: follow-schema field.

I also have just a general question on GraphQL:

  • Is there a way to set a default value for one of the fields on an input type? E.g. with two mutations one for creating a user on an application having the default role set to USER and another where a user is created as part an org being created in which case their role is set to ADMIN.
hello, does anyone know how to test authentication with client ? the recipe example get the user's information from context, but I can't find a function to set client context.
Jeremy Reed
Hi all, is there an example somewhere about how to modularize schemas/graphql functions, etc.? The use case is I have two customers, A and B. I want to have a "core" API module that contains shared functionality, such as authorization, 2 factor authentication, password resets, etc. Then, I want to extend this core (or somehow include it) into the separate APIs for customers A and B, each having different requirements and so on.
The idea is that any changes to the "core" module, would be reflected in the API for both customer A and customer B without having to maintain a completely separate codebase.
Jordan Lucier

Hello all, I'm using gqlgen with a Dgraph database and the fields on types I've defined in Dgraph end up with names like User.email instead of just email which is not reflected in the schema graphql files.

Thus, in order to unmarshal json from Dgraph responses, I either can't use the Golang structs gqlgen generates for me or I have to modify them (by adding User. in front of the json hints). This seems rather cumbersome, so I'm curious if anyone has thoughts or solutions. I hope I haven't missed something out there in docs somewhere (if I have, a link would be awesome).

Kashif Shaikh
Hi everyone - I wanted to test how gqlgen would work for big schemas - I used the Github public schema - but it SIGSEGVs after generating the models. The reason I’m doing this, is that I want to create a service where ppl upload there schemas and I would auto-generate or scaffold resolvers with simple mapping to DBs, Etc.
Hi All, Are there any examples where I can see how GqlGen - GraphQL server written with tests? I am trying to write integration tests for the GraphQL Server in my repo. Any pointers will be helpful :)
Adrien D.
@jlucier Hi am building a backend that use gqlgen as the Business Logic Layer and Graphql-Dgraph as the database. I use a source schema to feed the Graphql-Dgraph endpoint and the same one for gqlgen by basically appending the query, mutation and input generated by Grraphql-Dgraph into the source schema. Like this, I can follow the request from gqlgen to Dgraph and backward, by marshalling request and response and whithout the need to append the class name. (and by using custom resolver to translate the request in/out.
John Forstmeier

Can anyone explain how ctx would be set in the "TODO" example?

For example, if I'm running this "TODO" example app locally and I want to query the done field for the todo owned by them, how would I pass in the them ID?

Max Weston
hey all, don't suppose anyone would know why generate.go would be generating an import incorrectly to "github.com/vektah/gqlparser/v2/ast" to call the method MustLoadSchema, after fishing through the vendor files i have found that this method exists in the root folder of the dependancy.

Any is a scalar that maps to interface{} go type - https://gqlgen.com/reference/scalars/#any.

This is preventing usage of github.com/gogo/protobuf/types.Any . go run gqlgen fails with panic: interface conversion: types.Type is *types.Signature, not *types.Named

What is the alternative?

2 replies
Liam Ross

I'm having a lot of trouble implementing even basic logging (other than top level logging on chi which has no insight into the actual graphql requests), and I'm wondering if anyone is able to point me towards some docs or examples.

I've seen people link to the prometheus package, but that is outdated, and I don't know how the now non-existent RequestMiddleware maps to the new OperationMiddleware vs ResponseMiddleware, or what the difference between those are. If someone has a modern example, or is able to clear up when I should use OperationMiddleware vs ResponseMiddleware, and how to translate the dated prometheus example (I wouldn't mind implementing prometheus, but obviously would need to rewrite the package in order for it to work with modern gqlgen) that would be really appreciated!

1 reply
Kirill Tatchihin

hi everyone, I meet with issue while upgrading my resolvers from 1 file to follow-schema. Every time I run "go run github.com/99designs/gqlgen generate" all my files are recreating :( here is my gqlgen.yml:

# .gqlgen.yml example
# Refer to https://gqlgen.com/config/
# for detailed .gqlgen.yml documentation.

#GraphQL Schemas
  - "graph/*.graphql"

  filename: "graph/generated/gql.go"
  package: gql

  layout: follow-schema
  dir: graph
  type: resolver

  filename: models/generated.go
autobind: []

expected: after running go run github.com/99designs/gqlgen generate as it was in old mechanism with one resolver

alexander ikeh

You don’t need to specify the resolver in the yml file before you can follow the schema.

Just write your schema in your .graphl file then run

go run github.com/99designs/gqlgen

It will generate your schema resolver file and also the model file to follow your schema
Kirill Tatchihin
yep, but after generation of resolvers, I would like to add field to schema. I add it, run:
go run github.com/99designs/gqlgen
and then see that all my files inside of graph directory regenerated, how can I make it to not regenerate existing files?
alexander ikeh

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

go run github.com/99designs/gqlgen

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