Closed alichherawalla closed 4 years ago
Does this work
gqlgen.yml
schema:
- ../schema.graphql
exec:
filename: graphql_models/generated.go
package: graphql_models
model:
filename: graphql_models/generated_models.go
package: graphql_models
resolver:
filename: resolver.go
type: Resolver
The directories needs aliasing so these are required till a next release| graphql_models for gqlgen models models for sqlboiler models
Do you have single or multiple schema.graphql?
Hi, thanks for the swift response.
It doesn't work with the gqlgen.yml you posted, unfortunately.
I have a single schema.graphql
[convert] get boiler models
[convert] get model with information
[convert] get extra's from schema
[convert] render preload.gotpl
renderError template.gotpl: template: template.gotpl:21:3: executing "template.gotpl" at <reserveImport $.BackendModelsPath>: error calling reserveImport: empty ambient import
[convert] render convert.gotpl
renderError template.gotpl: template: template.gotpl:21:3: executing "template.gotpl" at <reserveImport $.BackendModelsPath>: error calling reserveImport: empty ambient import
[convert] render convert_input.gotpl
renderError template.gotpl: template: template.gotpl:21:3: executing "template.gotpl" at <reserveImport $.BackendModelsPath>: error calling reserveImport: empty ambient import
[convert] render filter.gotpl
renderError template.gotpl: template: template.gotpl:22:3: executing "template.gotpl" at <reserveImport $.BackendModelsPath>: error calling reserveImport: empty ambient import
panic: recursive or concurrent call to RenderToFile detected
goroutine 1 [running]:
github.com/99designs/gqlgen/codegen/templates.Render(0xc0002f4820, 0xe, 0x0, 0x0, 0xc0000e5a40, 0x3f, 0x101, 0x0, 0x0, 0x0, ...)
/Users/mac/GolandProjects/go-boiler/vendor/github.com/99designs/gqlgen/codegen/templates/templates.go:63 +0xfdf
github.com/99designs/gqlgen/codegen.GenerateCode(0xc000a1e880, 0xc000a1e880, 0x0)
/Users/mac/GolandProjects/go-boiler/vendor/github.com/99designs/gqlgen/codegen/generate.go:8 +0xfb
github.com/99designs/gqlgen/api.Generate(0xc00031cdc0, 0xc0001f3f38, 0x2, 0x2, 0xc0003034d0, 0xc0001f3f18)
/Users/mac/GolandProjects/go-boiler/vendor/github.com/99designs/gqlgen/api/generate.go:77 +0x378
github.com/wednesday-solution/go-boiler.Convert()
/Users/mac/GolandProjects/go-boiler/convert_plugin.go:26 +0x180
main.main()
/Users/mac/GolandProjects/go-boiler/cmd/convert/main.go:6 +0x20
Process finished with exit code 2
this is the full stack trace
also btw i'm using postgres
Hmm strange, on what versions are you of gqlgen and sqlboiler? I'm on the latest versions of both.
Mine is:
// +build ignore
package main
import (
"fmt"
"os"
"github.com/99designs/gqlgen/api"
"github.com/99designs/gqlgen/codegen/config"
convertsGenerator "github.com/web-ridge/gqlgen-sqlboiler/convert"
resolverGenerator "github.com/web-ridge/gqlgen-sqlboiler/resolver"
)
func main() {
cfg, err := config.LoadConfigFromDefaultLocations()
if err != nil {
fmt.Fprintln(os.Stderr, "failed to load config", err.Error())
os.Exit(2)
}
convertHelpersDir := "helpers"
sqlboilerDir := "models"
gqlgenModelDir := "graphql_models"
err = api.Generate(cfg,
api.AddPlugin(convertsGenerator.New(
convertHelpersDir, // directory where convert.go, convert_input.go and preload.go should live
sqlboilerDir, // directory where sqlboiler files are put
gqlgenModelDir, // directory where gqlgen models live
)),
api.AddPlugin(resolverGenerator.New(
convertHelpersDir,
sqlboilerDir,
gqlgenModelDir,
"gitlab.com/decicify/app/backend/auth",
)),
)
if err != nil {
fmt.Println("error!!")
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(3)
}
}
It crashes on this line in qqlgen code. https://github.com/99designs/gqlgen/blob/master/codegen/templates/templates.go#L68
Your convert_plugin.go file needs to live in the same folder as the project where you want to generate.
Did you generate your models for your database with https://github.com/volatiletech/sqlboiler?
I'm on the latest versions of gqlgen and sqlboiler as well. yes i've generated the database models from sqlboiler. and yes the convert_plugin is in the root folder
Interesting, to be honest I don't know if the output of sqlboiler is any different than with postgressql vs mysql.
What operating system do you use?
macos
Me too :)
i simplified the schema to have a just single type with a few scalar fields but it still doesn't work for some reason
Can you share your schema (maybe privately)
My email is on my profile
I'm generating my schema with: https://github.com/web-ridge/sqlboiler-graphql-schema a.t.m.
go run github.com/web-ridge/sqlboiler-graphql-schema --output=../schema.graphql --skip-input-fields=organizationId --directives=isAuthenticated
Maybe I made some assumptions about the schema.grapql which are not always true for everyone.
I used that to generate my schema as well
I tried it on a playground Blog/Comment/Post project as well, let me share that schema with you
I did have this issue too now I remember: the cause is here. https://github.com/99designs/gqlgen/blob/master/codegen/templates/templates.go#L62
This library generates multiple files instead of one, so we we needed to prevent this panic from happening.
That was fixed 6 days ago: https://github.com/web-ridge/gqlgen-sqlboiler/blob/master/convert/convert.go#L208
Somehow go.mod does not always understand how to update to the latest version
Maybe put this instead of the other web-ridge vendors in go.mod and run go mod tidy. And try regenerating.
github.com/web-ridge/gqlgen-sqlboiler/convert 82c6f4a43f5e8052d109bed0ce72ec194f726147
github.com/web-ridge/gqlgen-sqlboiler/helper 82c6f4a43f5e8052d109bed0ce72ec194f726147
github.com/web-ridge/gqlgen-sqlboiler/resolver 82c6f4a43f5e8052d109bed0ce72ec194f726147
that doesn't seem to work, could you please send me your go.mod?
I've added an example. https://github.com/web-ridge/gqlgen-sqlboiler/tree/master/examples/social-network
I do something wrong here with go-modules maybe I need to split up the project or something like that to keep everything on latest version
what's the go version that you are on?
i've added the project locally to make sure that there are no issues with the version for now but it still doesn't seem to work. I wasn't able to run your project either. Could it be something in the environment configuration?
➜ ~ go version go version go1.13.5 darwin/amd64
I don't know, it's strange!
I also don't have problems with latest version of golang go version go version go1.14.2 darwin/amd64
Ah!! I have the same problem now if I take it outside my golang path src directory
I think I need to rewrite this function or something like that. https://github.com/web-ridge/gqlgen-sqlboiler/blob/master/convert/convert.go#L134
Do you have the option available to move to your GOPATH folder?
that did the trick! Thanks very much
In v2.1.1 it works outside of GOPATH!
@randallmlough added support for repositories outside of GOPATH based on where the go.mod file lives👌
Thanks for this amazing library!
Currently when executing
go run convert_plugin.go
I'm getting the following errorpanic: recursive or concurrent call to RenderToFile detected
my gqlgen.yml looks like this
any idea why this would be an issue?