Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit ca1a96d

Browse files
fix: __typename should succeed on root fields (#573)
1 parent bd1d2eb commit ca1a96d

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- chore: Refactor metadata dependencies [#564](https://github.com/hypermodeinc/modus/pull/564)
1313
- chore: Use Go workspace to simplify project dependencies [#565](https://github.com/hypermodeinc/modus/pull/565)
1414
- fix: "WASM Host not found in context" error on shutdown [#566](https://github.com/hypermodeinc/modus/pull/566)
15+
- fix: `__typename` should succeed on root fields [#573](https://github.com/hypermodeinc/modus/pull/573)
1516

1617
## 2024-11-06 - AssemblyScript SDK 0.13.4
1718

runtime/graphql/datasource/planner.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ type HypDSPlanner struct {
3838
}
3939

4040
type fieldInfo struct {
41-
ref int `json:"-"`
42-
Name string `json:"name"`
43-
Alias string `json:"alias,omitempty"`
44-
TypeName string `json:"type,omitempty"`
45-
Fields []fieldInfo `json:"fields,omitempty"`
46-
IsMapType bool `json:"isMapType,omitempty"`
47-
fieldRefs []int `json:"-"`
41+
ref int `json:"-"`
42+
Name string `json:"name"`
43+
Alias string `json:"alias,omitempty"`
44+
TypeName string `json:"type,omitempty"`
45+
ParentType string `json:"parentType,omitempty"`
46+
Fields []fieldInfo `json:"fields,omitempty"`
47+
IsMapType bool `json:"isMapType,omitempty"`
48+
fieldRefs []int `json:"-"`
4849
}
4950

5051
func (t *fieldInfo) AliasOrName() string {
@@ -168,6 +169,7 @@ func (p *HypDSPlanner) captureField(ref int) *fieldInfo {
168169
def, ok := walker.FieldDefinition(ref)
169170
if ok {
170171
f.TypeName = definition.FieldDefinitionTypeNameString(def)
172+
f.ParentType = walker.EnclosingTypeDefinition.NameString(definition)
171173
f.IsMapType = slices.Contains(p.config.MapTypes, f.TypeName)
172174
}
173175

runtime/graphql/datasource/source.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func (*ModusDataSource) LoadWithFiles(ctx context.Context, input []byte, files [
6565

6666
func (ds *ModusDataSource) callFunction(ctx context.Context, callInfo *callInfo) (any, []resolve.GraphQLError, error) {
6767

68+
// Handle special case for __typename on root Query or Mutation
69+
if callInfo.FieldInfo.Name == "__typename" {
70+
return callInfo.FieldInfo.ParentType, nil, nil
71+
}
72+
6873
// Get the function info
6974
fnInfo, err := ds.WasmHost.GetFunctionInfo(callInfo.FunctionName)
7075
if err != nil {

0 commit comments

Comments
 (0)