Skip to content

Commit

Permalink
resolve all pkg dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed May 22, 2019
1 parent dc9ac88 commit 1e54468
Showing 1 changed file with 18 additions and 6 deletions.
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

0 comments on commit 1e54468

Please sign in to comment.