genql: quick hack at variables

This commit is contained in:
Ben Kraft
2020-01-02 17:52:55 -08:00
parent 77670363d3
commit 9746c818fd
7 changed files with 111 additions and 30 deletions
+11 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/vektah/gqlparser/ast"
)
func typeFor(operation *ast.OperationDefinition, schema *ast.Schema) string {
func typeForOperation(operation *ast.OperationDefinition, schema *ast.Schema) string {
var builder strings.Builder
writeSelectionSetStruct(&builder, operation.SelectionSet, schema)
@@ -15,6 +15,16 @@ func typeFor(operation *ast.OperationDefinition, schema *ast.Schema) string {
return builder.String()
}
func typeForInputType(typ *ast.Type, schema *ast.Schema) string {
var builder strings.Builder
// TODO: handle non-scalar types (by passing ...something... as the
// SelectionSet?)
writeType(&builder, typ, nil, schema)
return builder.String()
}
func writeSelectionSetStruct(builder *strings.Builder, selectionSet ast.SelectionSet, schema *ast.Schema) {
builder.WriteString("struct {\n")
for _, selection := range selectionSet {