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

Import resolver bugs. #60

Closed
jacklaaa89 opened this issue Mar 20, 2018 · 5 comments
Closed

Import resolver bugs. #60

jacklaaa89 opened this issue Mar 20, 2018 · 5 comments
Labels
bug Something isn't working

Comments

@jacklaaa89
Copy link

jacklaaa89 commented Mar 20, 2018

When attempting to generate code from a schema, a panic is thrown in import_build.go when attempting to resolve imports. The import path for my all of my types matches the name of one of the core imports the generated code relies on. i.e: my package: /path/to/package/introspection which conflicts with internal package: github.com/vektah/gqlgen/neelance/introspection (As they have the same base-name). I think this is down to line 40 in import_build.go:

for imp := imports.findByName(localName); imp != nil && imp.Package != t.Package; localName = filepath.Base(t.Package) + strconv.Itoa(i) { ... }

As for the example above: for the first iteration it will find match for the first iteration with the package: github.com/vektah/gqlgen/neelance/introspection, but will fail the imp != nil && imp.Package != t.Package condition. On any subsequent iteration however, the new name (i.e introspection1, ...2, ..3) will never match a package thus causing the panic('too many collisions') error.

@vektah vektah added the bug Something isn't working label Mar 20, 2018
@vektah
Copy link
Collaborator

vektah commented Mar 20, 2018

Thanks for the bug report, should be fixed now.

@jacklaaa89
Copy link
Author

Cheers for the quick resolution.

@tsuna
Copy link

tsuna commented Jul 16, 2018

I seem to be experiencing this issue again (I'm using gqlgen built from commit 55179a6). I have a package called foo/query and upon re-generating the code today I saw this:

--- a/foo/apigraphql/generated.go
+++ b/foo/apigraphql/generated.go
@@ -1,4 +1,4 @@
-// This file was generated by github.com/vektah/gqlgen, DO NOT EDIT
+// Code generated by github.com/vektah/gqlgen, DO NOT EDIT.
 
 package apigraphql
 
@@ -6,33 +6,154 @@ import (
        "bytes"
        context "context"
        apimodel "foo/apimodel"
-       query1 "foo/query"
+       query "foo/query"
        strconv "strconv"
 
        graphql "github.com/vektah/gqlgen/graphql"
        introspection "github.com/vektah/gqlgen/neelance/introspection"
-       query "github.com/vektah/gqlgen/neelance/query"
        schema "github.com/vektah/gqlgen/neelance/schema"
 )
 

as a result the code obviously doesn't compile anymore:

$ go test ./...
# foo/apigraphql
./generated.go:167:59: undefined: "foo/query".Operation

@tsuna
Copy link

tsuna commented Jul 16, 2018

I tried going back to commit cb87a2c and still had the problem, so I went back further, to commit 40d9a11, and the generated code no longer exhibits the issue and tests pass. So I assume there has been a regression. Re-opening.

@tsuna
Copy link

tsuna commented Jul 16, 2018

Nailed it down to commits abf85a1 / c0158f5 (the former doesn't build, so the last commit that works for me is a39c63a).

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

No branches or pull requests

3 participants