Skip to content

Commit b020295

Browse files
authored
feat: implement variables mapper (#1034)
1 parent 5b5331c commit b020295

File tree

9 files changed

+829
-2
lines changed

9 files changed

+829
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package astnormalization
2+
3+
import (
4+
"github.com/wundergraph/graphql-go-tools/v2/pkg/ast"
5+
"github.com/wundergraph/graphql-go-tools/v2/pkg/astvisitor"
6+
"github.com/wundergraph/graphql-go-tools/v2/pkg/operationreport"
7+
)
8+
9+
type VariablesMapper struct {
10+
walker *astvisitor.Walker
11+
variablesMappingVisitor *variablesMappingVisitor
12+
}
13+
14+
func NewVariablesMapper() *VariablesMapper {
15+
walker := astvisitor.NewDefaultWalker()
16+
mapper := remapVariables(&walker)
17+
18+
return &VariablesMapper{
19+
walker: &walker,
20+
variablesMappingVisitor: mapper,
21+
}
22+
}
23+
24+
func (v *VariablesMapper) NormalizeOperation(operation, definition *ast.Document, report *operationreport.Report) map[string]string {
25+
v.walker.Walk(operation, definition, report)
26+
if report.HasErrors() {
27+
return nil
28+
}
29+
30+
return v.variablesMappingVisitor.mapping
31+
}

0 commit comments

Comments
 (0)