error if you try to use features that aren't done (fragments/interfaces)

This commit is contained in:
Ben Kraft
2021-04-02 16:19:50 -07:00
parent edb12e3e0a
commit 334c186944
3 changed files with 13 additions and 0 deletions
+7
View File
@@ -12,6 +12,9 @@ import (
"github.com/vektah/gqlparser/v2/formatter"
)
// Set to true to test features that aren't yet really ready.
var allowBrokenFeatures = false
var fileTemplate = mustTemplate("operation.go.tmpl")
// generator is the context for the codegen process (and ends up getting passed
@@ -168,6 +171,10 @@ func Generate(config *Config) (map[string][]byte, error) {
return nil, fmt.Errorf("no queries found in %v", config.Operations)
}
if len(document.Fragments) > 0 && !allowBrokenFeatures {
return nil, fmt.Errorf("genqlient does not yet support fragments")
}
g := newGenerator(config, schema)
for _, op := range document.Operations {
if err = g.addOperation(op); err != nil {
+2
View File
@@ -48,6 +48,8 @@ func gofmt(filename, src string) (string, error) {
// snapshots don't even get compiled!
func TestGenerate(t *testing.T) {
update := (os.Getenv("UPDATE_SNAPSHOTS") == "1")
// we can test parts of features even if they're not done yet!
allowBrokenFeatures = true
files, err := ioutil.ReadDir(dataDir)
if err != nil {
+4
View File
@@ -269,6 +269,10 @@ func (builder *typeBuilder) writeTypedef(typedef *ast.Definition, fields []field
return builder.maybeWriteUnmarshal(fields)
case ast.Interface, ast.Union:
if !allowBrokenFeatures {
return fmt.Errorf("not implemented: %v", typedef.Kind)
}
// First, write the interface type.
builder.WriteString("interface {\n")
implementsMethodName := fmt.Sprintf("implementsGraphQLInterface%v", builder.typeName)