Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 19:19
    tprebs commented #1732
  • 18:29
    Kichiyaki commented #1152
  • 18:21
    tolik505 commented #1152
  • 14:18
    StevenACoffman commented #1737
  • 14:18
    StevenACoffman closed #1737
  • 14:18
    StevenACoffman closed #1736
  • 09:02
    frederikhors commented #1734
  • 09:00
    frederikhors synchronize #1734
  • Dec 02 17:15
    zenyui commented #1714
  • Dec 02 17:13
    frederikhors commented #1714
  • Dec 02 06:00
    jimvmathews opened #1739
  • Dec 01 21:17
    lkendrickd commented #1723
  • Dec 01 19:49
    frederikhors commented #1722
  • Dec 01 19:47
    odannyc opened #1738
  • Dec 01 18:00
    MiguelCastillo commented #1723
  • Dec 01 14:48
    StevenACoffman commented #1723
  • Dec 01 14:13
    coveralls commented #1737
  • Dec 01 13:33
    tprebs edited #1737
  • Dec 01 13:33
    tprebs synchronize #1737
  • Dec 01 13:20
    tprebs commented #1737
Cole Lawrence
@colelawrence
@dtrckd you may have gone this deep already, but this looks like the place that currently handles that return template https://github.com/99designs/gqlgen/blob/14dccc57885df5d5ca4ef347c1b80f5f3648719a/codegen/field.go#L467-L484
Adrien D.
@dtrckd
@JonLundy @colelawrence , thx for your responses !
yes I didn"t found a relevant documentation for modifying code. Typically, I don't want to modify generated models, but the code inside generated resolvers. Instead of the default "panic", I have some code that should apply. (i am doing a bridge between gqlgen and dgraph, using gqlgen as a Business Logic Layer )
Cole Lawrence
@colelawrence
@dtrckd Yeah, so far, I've found it quite difficult to actually change the way gqlgen works without simply copying and pasting large swathes of its source code
But that could also be because I haven't found what I need to apply fine-grained control over what introspection will show versus what I want present on my generated models.
I suppose you could fork gqlgen
Jon Lundy
@JonLundy
... and contribute back to the project ;)
maybe this?
Cole Lawrence
@colelawrence
Nice find, I think you'd still have to figure out how to override ShortResolverDeclaration
https://github.com/99designs/gqlgen/blob/master/plugin/stubgen/stubs.gotpl#L45
Cole Lawrence
@colelawrence

So, I ended up writing a second yml file with configuration for adding arbitrary fields to generated models

# Add transient fields to the generated glq model
models:
  User:
    DBUser: github.com/my/package/models.User

# # Place all added fields into their own embedded struct with the following field name
# field: Internals

Then, I used a very simple plugin built off of the modelgen.Plugin to add these fields to the models during codegen. I will be experimenting to see if there are any "gotchas" that I might have missed with this approach.

cpunekar
@cpunekar
Guys, I'm very new to both graphql and golang, trying to run a simple app using gqlgen but observing below error, any help is appreciated -> User-MacBook-Pro:test-gql user$ go run github.com/99designs/gqlgen
validation failed: packages.Load: /Users/test-gql/schema.resolvers.go:12:73: NewTodo not declared by package models
/Users/test-gql/schema.resolvers.go:12:91: Todo not declared by package models
/Users/test-gql/schema.resolvers.go:16:63: Todo not declared by package models
/Users/test-gql/schema.resolvers.go:21:31: undeclared name: generated
/Users/test-gql/schema.resolvers.go:24:28: undeclared name: generated
exit status 1
User-MacBook-Pro:test-gql user$ go run github.com/99designs/gqlgen
validation failed: packages.Load: /Users/test-gql/schema.resolvers.go:12:73: NewTodo not declared by package models
/Users/test-gql/schema.resolvers.go:12:91: Todo not declared by package models
/Users/test-gql/schema.resolvers.go:16:63: Todo not declared by package models
/Users/test-gql/schema.resolvers.go:21:31: undeclared name: generated
/Users/test-gql/schema.resolvers.go:24:28: undeclared name: generated
exit status 1
I guess it's looking for model called 'NewTodo' which is part of the old model.. I have removed that part
Cole Lawrence
@colelawrence
@cpunekar are you observing that gqlgen is still generating the models file? Because this validation step shouldn't block the generation from happening. What is the expected behavior you're looking for?
cpunekar
@cpunekar
Thanks @colelawrence, I got past this issue, worked after deleting the resolver file. Now stuck on below error
User-MacBook-Pro:test-gql user$ go run server.go resolver.go generated.go
package main: found packages main (server.go) and test_gql (resolver.go) in /Users/test-gql
Jon Lundy
@JonLundy
ah that is because go expects one module per directory
cpunekar
@cpunekar
@JonLundy not sure what that means, is it related to the folder structure? mine looks like this
```
- models
    - person.go
    - pet.go
- generated.go
- resolver.go
- server.go
- schema.graphql
- gqlgen.yml
Jon Lundy
@JonLundy
hmm resolver is marked as package test_gql ?
you should be able to run with just go run .
cpunekar
@cpunekar
yes, resolver's pkg is test_gql.. still getting the same error with go run .
server is marked with pkg "main"
I tried making resolver and generated.go pkg names as main but got some cycle error, guess it's not that way
Jon Lundy
@JonLundy
hmm should only give you cycle if its trying to import its own package i think
is resolver trying to import the generated ?
cpunekar
@cpunekar
nope.. no references of generated in resolver
Jon Lundy
@JonLundy
what about server.go?
or rather what does it say is cycleing
cpunekar
@cpunekar
user-MacBook-Pro:test-gql user$ go run .
import cycle not allowed
package test-gql
    imports test-gql
Jon Lundy
@JonLundy
imports itsself?
try removing that :)
cpunekar
@cpunekar
package name is "main" in resolver, generated and server
ah yes.. I did import "tets-gql" in server.go (sleep deprived).. not sure how should I write below line since the server.go needs to in the folder as generated.go and resolver.go
cpunekar
@cpunekar
srv := handler.NewDefaultServer(test-gql.NewExecutableSchema(test-gql.Config{Resolvers: &test-gql.Resolver{}}))
Jon Lundy
@JonLundy
just remove the test-gql. from everything
its all defined in the same package
importing from the same directory is a python convention.. its not like that in Go
cpunekar
@cpunekar
the joy when your code works.. thanks to you @JonLundy
Jon Lundy
@JonLundy
np
cpunekar
@cpunekar
just for general knowledge.. what's the folder structure you guys follow for production servers?
Jon Lundy
@JonLundy
I typically have
  • pkg/generated/generated.go
  • pkg/model/model_gen.go
  • pkg/resolvers/...go
Just to keep them separate
I have seen in examples where the generated/models are subdirectory of resolvers
cpunekar
@cpunekar
@JonLundy that makes more sense.. thanks!
Tassios Marios
@mariosttass
Hi guys,
Basically I have a simple question, in case that we have a very complicated schema there is a work around to generate that using gqlgen library?
Thank you.