Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panics when building outside of GOPATH #29

Closed
randallmlough opened this issue May 22, 2020 · 4 comments
Closed

Panics when building outside of GOPATH #29

randallmlough opened this issue May 22, 2020 · 4 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@randallmlough
Copy link
Contributor

Piggy backing off my issue on your examples: web-ridge/gqlgen-sqlboiler-examples#2

and this issue: #3

Is this library able to work outside of the GOPATH while using modules?

I created a simple example that attempts to use postgres. Unfortunately, I haven't been able to get it to work at all. It panics everytime I go go run convert_plugin.go

go run convert_plugin.go
[convert] get boiler models
[convert] get extra's from schema
[convert] get model with information
[convert] render preload.gotpl
renderError template.gotpl: template: template.gotpl:26:3: executing "template.gotpl" at <reserveImport $.BackendModelsPath>: error calling reserveImport: empty ambient import
[convert] render convert.gotpl
renderError template.gotpl: template: template.gotpl:27:3: executing "template.gotpl" at <reserveImport $.BackendModelsPath>: error calling reserveImport: empty ambient import
[convert] render convert_input.gotpl
renderError template.gotpl: template: template.gotpl:27:3: executing "template.gotpl" at <reserveImport $.BackendModelsPath>: error calling reserveImport: empty ambient import
[convert] render filter.gotpl
renderError template.gotpl: template: template.gotpl:26:3: executing "template.gotpl" at <reserveImport $.BackendModelsPath>: error calling reserveImport: empty ambient import
panic: recursive or concurrent call to RenderToFile detected

Would love some insight here.

Example prpoject: https://github.com/randallmlough/gql-boil-psql

@RichardLindhout
Copy link
Member

RichardLindhout commented May 23, 2020

It's because of this code if I'm not mistaken

func getGoImportFromFile(dir string) string {
	longPath, err := filepath.Abs(dir)
	if err != nil {
		fmt.Println("error while trying to convert folder to gopath", err)
	}
	// src/Users/.../go/src/gitlab.com/.../app/backend/graphql_models
	return strings.TrimPrefix(pathRegex.FindString(longPath), "src/")
}

https://github.com/web-ridge/gqlgen-sqlboiler/blob/master/convert.go#L151

@RichardLindhout
Copy link
Member

I need import in golang

backend := gbgen.Config{
		Directory:   "models",
		PackageName: "models",
	}

From "models" -> to import path in file e.g "github.com/web-ridge/some-app/models"

We probably need this approach
https://stackoverflow.com/questions/18537257/how-to-get-the-directory-of-the-currently-running-file

@RichardLindhout RichardLindhout added enhancement New feature or request bug Something isn't working labels May 23, 2020
@RichardLindhout
Copy link
Member

I think it's hard to detect import path if it's not in GOPATH we may need to let user explicitly set it via config.

@RichardLindhout
Copy link
Member

Thanks you for this amazing PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants