by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 06 04:01
    stale[bot] closed #1123
  • Jun 05 22:14
    pepusz commented #1138
  • Jun 05 22:12
    pepusz commented #1138
  • Jun 05 12:16
    pepusz commented #1138
  • Jun 05 10:17
    gabrielcuvillier commented #1158
  • Jun 04 23:58
    stale[bot] labeled #1133
  • Jun 04 23:58
    stale[bot] commented #1133
  • Jun 04 23:58
    stale[bot] closed #1048
  • Jun 04 23:58
    stale[bot] labeled #1134
  • Jun 04 23:58
    stale[bot] commented #1134
  • Jun 03 20:12
    songmink commented #1159
  • Jun 03 13:56
    matheuss-leonel commented #1104
  • Jun 03 09:43
    nitin302 commented #1152
  • Jun 03 09:34
    Kichiyaki commented #1152
  • Jun 03 06:12
    stale[bot] closed #1121
  • Jun 03 04:49
    jacksontj commented #1103
  • Jun 03 04:27
    jacksontj commented #1103
  • Jun 02 09:50
    NateScarlet opened #1205
  • Jun 02 03:33
    coveralls commented #1204
  • Jun 02 03:30
    NateScarlet synchronize #1204
Jeremy Reed
@jpreed00
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
@jlucier

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
@kashifshaikh_twitter
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.
ankurbaglodi
@ankurbaglodi
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.
@dtrckd
@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
@forstmeier

Can anyone explain how ctx would be set in the "TODO" example?
https://github.com/99designs/gqlgen/blob/master/example/todo/todo.go#L37

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
@Maxweston
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.
sateeshpnv
@sateeshpnv

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
@liamross

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
@rbUUbr

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
schema:
  - "graph/*.graphql"

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

resolver:
  layout: follow-schema
  dir: graph
  type: resolver

model:
  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
@AlexSwiss

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
@rbUUbr
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
@AlexSwiss

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
@rbUUbr

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
@AlexSwiss
Can I see your schema file?
Kirill Tatchihin
@rbUUbr
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
    | FIELD_DEFINITION

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

type Query {
    users: UsersOutput!

}
Kirill Tatchihin
@rbUUbr
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
@AlexSwiss

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
@rbUUbr
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
@AlexSwiss
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
@rbUUbr
Thomas Jackson
@jacksontj
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
@k_rthik1991_twitter

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
@bhaskarsaraogi_twitter
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
@karthikraobr
Is there a way to grab the operation execution time from the OperationContext? TIA
Randy Lough
@randallmlough
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
@randallmlough
@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
Randy Lough
@randallmlough
I think I got the ast.Path to work for now using a makeshift appender using context
Randy Lough
@randallmlough
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
@kishyr
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
@vaihtovirta
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?
NickBlow
@NickBlow
Anyone got any examples of testing resolvers? ideally unit testing i guess...
Jeremy Marshall
@JeremyMarshall
@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
yuvalt7
@yuvalt7

Hi!

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
@aliksend

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

models:
  ID:
    model: path/to/your/file.GlobalID

and in file implement MarshalGlobalID and UnmarshalGlobalID functions

Alik Send
@aliksend

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} }

etc

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

fix for #965

For #956 *

Akhil Indurti
@smasher164

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?

Thanks,
Akhil