Issue workflow progress
Progress of the issue based on the
Contributor Workflow
Make sure to fork this template and run yarn generate in the terminal.
Please make sure Mesh package versions under package.json matches yours.
Describe the bug
I'm using mesh cli to join multiple encapsulated subgraphs to form supergraph. In addition to generated schema, I add custom field using additionalTypeDefs under one subgraph referring another using @resolveTo directive.
extend type TargetType {
complexDataItem: SubComplexDataFieldType
@resolveTo(
requiredSelectionSet: "{ id }"
sourceName: "Subgraph1"
sourceTypeName: "Query"
sourceFieldName: "_encapsulated_Subgraph1_complexData"
sourceArgs: { id: "{root.id}" }
result: "items[0]"
)
}
Such resolver causes TypeError: Cannot read properties of undefined (reading 'type') here.
When @resolveTo directive includes sourceSelectionSet as in the following example:
extend type TargetType {
complexDataItem: SubComplexDataFieldType
@resolveTo(
requiredSelectionSet: "{ id }"
sourceName: "Subgraph1"
sourceTypeName: "Query"
sourceFieldName: "_encapsulated_Subgraph1_complexData"
sourceSelectionSet: "{ items { key value } }" # sourceSelectionSet provided
sourceArgs: { id: "{root.id}" }
result: "items[0]"
)
}
It works as expected. However, in real life, it is hard to specify contents of sourceSelectionSet, it should derived from type according to path in result and runtime query provided selection set. When encapsulation is not applied to subgraphs, @resolveTo able to derive selection set from result without explicitly specifying sourceSelectionSet.
To Reproduce Steps to reproduce the behavior:
$ git clone https://github.com/muradm/resolve-to-result-mangling-test.git
$ cd resolve-to-result-mangling-test
$ npm run build
$ npm run start
Navigate to http://localhost:5000/graphql. In graphiql run the query:
query {
Subgraph2 {
targetQuery {
targets {
id
complexDataItem {
key
value
}
}
}
}
}
In console output of gateway you get:
[2] message: "Cannot read properties of undefined (reading 'type')"
[2] locations: [
[2] {
[2] line: 1
[2] column: 35
[2] }
[2] ]
[2] path: [
[2] "Subgraph2"
[2] "targetQuery"
[2] "targets"
[2] 2
[2] "complexDataItem"
[2] ]
Expected behavior
Expecting the following query result:
{
"data": {
"Subgraph2": {
"targetQuery": {
"targets": [
{
"id": "nullish",
"complexDataItem": null
},
{
"id": "empty",
"complexDataItem": null
},
{
"id": "full",
"complexDataItem": {
"key": "key1",
"value": "value1"
}
}
]
}
}
}
}
Environment:
- OS: Linux
"@graphql-mesh/compose-cli": "^1.5.30"
"@graphql-hive/gateway-runtime": "^2.8.7"
"@graphql-mesh/transport-http": "^1.0.23"
- NodeJS: v24.14.1
Additional context
Issue workflow progress
Progress of the issue based on the
Contributor Workflow
Github,
Stackblitz
or
CodeSandbox
Describe the bug
I'm using mesh cli to join multiple encapsulated subgraphs to form supergraph. In addition to generated schema, I add custom field using
additionalTypeDefsunder one subgraph referring another using@resolveTodirective.Such resolver causes
TypeError: Cannot read properties of undefined (reading 'type')here.When
@resolveTodirective includessourceSelectionSetas in the following example:It works as expected. However, in real life, it is hard to specify contents of
sourceSelectionSet, it should derived from type according to path inresultand runtime query provided selection set. When encapsulation is not applied to subgraphs,@resolveToable to derive selection set fromresultwithout explicitly specifyingsourceSelectionSet.To Reproduce Steps to reproduce the behavior:
Navigate to
http://localhost:5000/graphql. In graphiql run the query:In console output of gateway you get:
Expected behavior
Expecting the following query result:
{ "data": { "Subgraph2": { "targetQuery": { "targets": [ { "id": "nullish", "complexDataItem": null }, { "id": "empty", "complexDataItem": null }, { "id": "full", "complexDataItem": { "key": "key1", "value": "value1" } } ] } } } }Environment:
"@graphql-mesh/compose-cli": "^1.5.30""@graphql-hive/gateway-runtime": "^2.8.7""@graphql-mesh/transport-http": "^1.0.23"Additional context