Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Nov 27 19:42
    namnm edited #1730
  • Nov 27 19:40
    namnm opened #1730
  • 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
Cole Lawrence
@colelawrence
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.
Jon Lundy
@JonLundy
@mariosttass how do you mean?
like its a large schema? or there are many interconnected types and queries?
Tassios Marios
@mariosttass
  Hi, I was meaning that in case that there are many types and queries. 
Jon Lundy
@JonLundy
is it failing to generate the source files?