Skip to content

Commit

Permalink
Merge pull request #722 from marwan-at-work/deps
Browse files Browse the repository at this point in the history
resolve all pkg dependencies
  • Loading branch information
vektah authored Jun 18, 2019
2 parents 694f90a + be18ae1 commit 090f0bd
Show file tree
Hide file tree
Showing 9 changed files with 316 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
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

0 comments on commit 090f0bd

Please sign in to comment.