From 25d79697e18ac5e54cd8a34865a075bb9ad815e0 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Fri, 8 Nov 2024 11:32:28 -0800 Subject: [PATCH 1/3] Capture parent type on field info --- runtime/graphql/datasource/planner.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/runtime/graphql/datasource/planner.go b/runtime/graphql/datasource/planner.go index 04dbdd6cc..06b146023 100644 --- a/runtime/graphql/datasource/planner.go +++ b/runtime/graphql/datasource/planner.go @@ -38,13 +38,14 @@ type HypDSPlanner struct { } type fieldInfo struct { - ref int `json:"-"` - Name string `json:"name"` - Alias string `json:"alias,omitempty"` - TypeName string `json:"type,omitempty"` - Fields []fieldInfo `json:"fields,omitempty"` - IsMapType bool `json:"isMapType,omitempty"` - fieldRefs []int `json:"-"` + ref int `json:"-"` + Name string `json:"name"` + Alias string `json:"alias,omitempty"` + TypeName string `json:"type,omitempty"` + ParentType string `json:"parentType,omitempty"` + Fields []fieldInfo `json:"fields,omitempty"` + IsMapType bool `json:"isMapType,omitempty"` + fieldRefs []int `json:"-"` } func (t *fieldInfo) AliasOrName() string { @@ -168,6 +169,7 @@ func (p *HypDSPlanner) captureField(ref int) *fieldInfo { def, ok := walker.FieldDefinition(ref) if ok { f.TypeName = definition.FieldDefinitionTypeNameString(def) + f.ParentType = walker.EnclosingTypeDefinition.NameString(definition) f.IsMapType = slices.Contains(p.config.MapTypes, f.TypeName) } From 8823004d02b5c5e6f00e09e90b69d0d89b48f3e5 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Fri, 8 Nov 2024 11:33:35 -0800 Subject: [PATCH 2/3] Handle __typename on root fields --- runtime/graphql/datasource/source.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/graphql/datasource/source.go b/runtime/graphql/datasource/source.go index 2183ff206..e56dec6ae 100644 --- a/runtime/graphql/datasource/source.go +++ b/runtime/graphql/datasource/source.go @@ -65,6 +65,11 @@ func (*ModusDataSource) LoadWithFiles(ctx context.Context, input []byte, files [ func (ds *ModusDataSource) callFunction(ctx context.Context, callInfo *callInfo) (any, []resolve.GraphQLError, error) { + // Handle special case for __typename on root Query or Mutation + if callInfo.FieldInfo.Name == "__typename" { + return callInfo.FieldInfo.ParentType, nil, nil + } + // Get the function info fnInfo, err := ds.WasmHost.GetFunctionInfo(callInfo.FunctionName) if err != nil { From 0d93b2a5288b8281412bc8af0d6f04849d4cd05b Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Fri, 8 Nov 2024 11:34:39 -0800 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e55806fb8..1bd9972a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - chore: Refactor metadata dependencies [#564](https://github.com/hypermodeinc/modus/pull/564) - chore: Use Go workspace to simplify project dependencies [#565](https://github.com/hypermodeinc/modus/pull/565) - fix: "WASM Host not found in context" error on shutdown [#566](https://github.com/hypermodeinc/modus/pull/566) +- fix: `__typename` should succeed on root fields [#573](https://github.com/hypermodeinc/modus/pull/573) ## 2024-11-06 - AssemblyScript SDK 0.13.4