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

resolve all pkg dependencies #722

Merged
merged 2 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions codegen/config/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// Binder connects graphql types to golang types using static analysis
type Binder struct {
pkgs []*packages.Package
pkgs map[string]*packages.Package
schema *ast.Schema
cfg *Config
References []*TypeReference
Expand All @@ -26,7 +26,9 @@ func (c *Config) NewBinder(s *ast.Schema) (*Binder, error) {
return nil, err
}

mp := map[string]*packages.Package{}
for _, p := range pkgs {
populatePkg(mp, p)
for _, e := range p.Errors {
if e.Kind == packages.ListError {
return nil, p.Errors[0]
Expand All @@ -35,12 +37,23 @@ func (c *Config) NewBinder(s *ast.Schema) (*Binder, error) {
}

return &Binder{
pkgs: pkgs,
pkgs: mp,
schema: s,
cfg: c,
}, nil
}

func populatePkg(mp map[string]*packages.Package, p *packages.Package) {
imp := code.NormalizeVendor(p.PkgPath)
if _, ok := mp[imp]; ok {
return
}
mp[imp] = p
for _, p := range p.Imports {
populatePkg(mp, p)
}
}

func (b *Binder) TypePosition(typ types.Type) token.Position {
named, isNamed := typ.(*types.Named)
if !isNamed {
Expand Down Expand Up @@ -75,10 +88,9 @@ func (b *Binder) FindType(pkgName string, typeName string) (types.Type, error) {
}

func (b *Binder) getPkg(find string) *packages.Package {
for _, p := range b.pkgs {
if code.NormalizeVendor(find) == code.NormalizeVendor(p.PkgPath) {
return p
}
imp := code.NormalizeVendor(find)
if p, ok := b.pkgs[imp]; ok {
return p
}
return nil
}
Expand Down
204 changes: 204 additions & 0 deletions codegen/testserver/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions codegen/testserver/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ models:
model: "github.com/99designs/gqlgen/codegen/testserver.FallbackToStringEncoding"
Bytes:
model: "github.com/99designs/gqlgen/codegen/testserver.Bytes"
WrappedStruct:
model: "github.com/99designs/gqlgen/codegen/testserver.WrappedStruct"
WrappedScalar:
model: "github.com/99designs/gqlgen/codegen/testserver.WrappedScalar"
7 changes: 7 additions & 0 deletions codegen/testserver/otherpkg/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package otherpkg

type Scalar string

type Struct struct {
Name string
}
6 changes: 6 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ func (r *queryResolver) OptionalUnion(ctx context.Context) (TestUnion, error) {
func (r *queryResolver) ValidType(ctx context.Context) (*ValidType, error) {
panic("not implemented")
}
func (r *queryResolver) WrappedStruct(ctx context.Context) (*WrappedStruct, error) {
panic("not implemented")
}
func (r *queryResolver) WrappedScalar(ctx context.Context) (WrappedScalar, error) {
panic("not implemented")
}

type subscriptionResolver struct{ *Resolver }

Expand Down
8 changes: 8 additions & 0 deletions codegen/testserver/stub.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions codegen/testserver/wrapped_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package testserver

import "github.com/99designs/gqlgen/codegen/testserver/otherpkg"

type WrappedScalar otherpkg.Scalar
type WrappedStruct otherpkg.Struct
Loading