-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow primitive scalars to be redefined
- Loading branch information
Showing
14 changed files
with
138 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package codegen | ||
|
||
import ( | ||
"fmt" | ||
"go/types" | ||
"os" | ||
|
||
"golang.org/x/tools/go/loader" | ||
) | ||
|
||
func findGoType(prog *loader.Program, pkgName string, typeName string) types.Object { | ||
fullName := typeName | ||
if pkgName != "" { | ||
fullName = pkgName + "." + typeName | ||
} | ||
|
||
pkgName, err := resolvePkg(pkgName) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "unable to resolve package for %s: %s\n", fullName, err.Error()) | ||
return nil | ||
} | ||
|
||
pkg := prog.Imported[pkgName] | ||
if pkg == nil { | ||
fmt.Fprintf(os.Stderr, "required package was not loaded: %s", fullName) | ||
return nil | ||
} | ||
|
||
for astNode, def := range pkg.Defs { | ||
if astNode.Name != typeName || isMethod(def) { | ||
continue | ||
} | ||
|
||
return def | ||
} | ||
fmt.Fprintf(os.Stderr, "unable to find type %s\n", fullName) | ||
return nil | ||
} | ||
|
||
func isMethod(t types.Object) bool { | ||
f, isFunc := t.(*types.Func) | ||
if !isFunc { | ||
return false | ||
} | ||
|
||
return f.Type().(*types.Signature).Recv() != nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ type Order { | |
type Item { | ||
name: String | ||
} | ||
scalar Time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,3 +132,4 @@ type Starship { | |
history: [[Int]] | ||
} | ||
union SearchResult = Human | Droid | Starship | ||
scalar Time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.