Skip to content

Commit 0e3c00f

Browse files
authored
feat: add support for field resolvers (#1323)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Field resolver support expanded: Product (shippingEstimate, recommendedCategory) and Category (productCount, popularityScore, categoryMetrics, subcategories). * New schema types and inputs: Subcategory, CategoryMetrics, ProductCountFilter, SubcategoryItemFilter, ShippingEstimateInput, ShippingDestination enum, and openfed__FieldSet scalar. * **Improvements** * Execution engine now builds and runs dependency-aware, parallel RPC call plans for resolver-driven and federated flows, with richer response merging. * **Tests & Tooling** * New tests, benchmarks, mock service handlers, and mapping generation helpers; package Readme added. <!-- end of auto-generated comment: release notes by coderabbit.ai --> ## Checklist - [ ] I have discussed my proposed changes in an issue and have received approval to proceed. - [ ] I have followed the coding standards of the project. - [ ] Tests or benchmarks have been added or updated. <!-- Please add any additional information or context regarding your changes here. -->
1 parent 68ff0c9 commit 0e3c00f

36 files changed

+24798
-3962
lines changed

v2/pkg/ast/ast.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ func (d *Document) NodeByNameStr(name string) (Node, bool) {
236236
return d.Index.FirstNodeByNameStr(name)
237237
}
238238

239+
// ResolveNodeFromTypeRef returns the `ast.Node` for a given type reference.
240+
func (d *Document) ResolveNodeFromTypeRef(typeRef int) (Node, bool) {
241+
return d.Index.FirstNodeByNameStr(d.ResolveTypeNameString(typeRef))
242+
}
243+
239244
func (d *Document) TypeDefinitionContainsImplementsInterface(typeName, interfaceName ByteSlice) bool {
240245
typeDefinition, exists := d.Index.FirstNodeByNameBytes(typeName)
241246
if !exists {

v2/pkg/ast/ast_selection.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ast
33
import (
44
"bytes"
55
"fmt"
6+
"strings"
67

78
"github.com/wundergraph/graphql-go-tools/v2/pkg/internal/unsafebytes"
89
"github.com/wundergraph/graphql-go-tools/v2/pkg/lexer/position"
@@ -241,3 +242,18 @@ func (d *Document) SelectionSetFieldNames(set int) (fieldNames []string) {
241242
}
242243
return
243244
}
245+
246+
// SelectionSetFieldSetString returns a string of the field names in the selection set separated by a space
247+
// Example: "{ name status }" -> "name status"
248+
func (d *Document) SelectionSetFieldSetString(set int) string {
249+
fieldSelections := d.SelectionSetFieldSelections(set)
250+
builder := strings.Builder{}
251+
for i, fieldSelection := range fieldSelections {
252+
builder.Write(d.FieldNameBytes(d.Selections[fieldSelection].Ref))
253+
if i != len(fieldSelections)-1 {
254+
builder.WriteRune(' ')
255+
}
256+
}
257+
258+
return builder.String()
259+
}

v2/pkg/ast/path.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ type PathItem struct {
3333

3434
type Path []PathItem
3535

36+
func (p Path) Len() int {
37+
return len(p)
38+
}
39+
3640
func (p Path) Equals(another Path) bool {
3741
if len(p) != len(another) {
3842
return false
@@ -77,6 +81,28 @@ func (p Path) WithoutInlineFragmentNames() Path {
7781
return out
7882
}
7983

84+
func (p Path) WithPathItem(element PathItem) Path {
85+
res := make(Path, len(p)+1)
86+
copy(res, p)
87+
res[len(res)-1] = element
88+
return res
89+
}
90+
91+
func (p Path) WithFieldNameItem(fieldName []byte) Path {
92+
return p.WithPathItem(PathItem{
93+
Kind: FieldName,
94+
FieldName: fieldName,
95+
})
96+
}
97+
98+
func (p Path) RemoveLastItem() Path {
99+
if len(p) == 0 {
100+
return p
101+
}
102+
103+
return p[:len(p)-1]
104+
}
105+
80106
func (p Path) String() string {
81107
out := "["
82108
for i := range p {

0 commit comments

Comments
 (0)