Skip to content

Commit f69a3a6

Browse files
authored
fix: don't panic when calling QueryPlan on FetchTreeNode if includeQueryPlans is false (#1189)
This currently panics because https://github.com/wundergraph/graphql-go-tools/blob/e75a1dd24d5255b6cc990269c5c7922f851f4fc1/v2/pkg/engine/resolve/fetchtree.go#L212-L213 is a nil pointer dereference when This change makes it just fail empty instead of panic, which is fine for what it's needed for in the router. I originally made this not nil at the source in https://github.com/wundergraph/graphql-go-tools/blob/dd0d9cc2a9192799c4b3c5ecaa89134c03e01801/v2/pkg/engine/plan/visitor.go#L1259-L1261 but it causes like 1000+ inline snapshot tests to fail which are hardcoded and don't have `-update`, so I catch the nilness at usage site instead
1 parent dd0d9cc commit f69a3a6

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

v2/pkg/engine/resolve/fetchtree.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,43 +209,55 @@ func (n *FetchTreeNode) queryPlan() *FetchTreeQueryPlanNode {
209209
DependsOnFetchIDs: f.FetchDependencies.DependsOnFetchIDs,
210210
SubgraphName: f.Info.DataSourceName,
211211
SubgraphID: f.Info.DataSourceID,
212-
Query: f.Info.QueryPlan.Query,
213-
Representations: f.Info.QueryPlan.DependsOnFields,
214212
Path: n.Item.ResponsePath,
215213
}
214+
215+
if f.Info.QueryPlan != nil {
216+
queryPlan.Fetch.Query = f.Info.QueryPlan.Query
217+
queryPlan.Fetch.Representations = f.Info.QueryPlan.DependsOnFields
218+
}
216219
case *EntityFetch:
217220
queryPlan.Fetch = &FetchTreeQueryPlan{
218221
Kind: "Entity",
219222
FetchID: f.FetchDependencies.FetchID,
220223
DependsOnFetchIDs: f.FetchDependencies.DependsOnFetchIDs,
221224
SubgraphName: f.Info.DataSourceName,
222225
SubgraphID: f.Info.DataSourceID,
223-
Query: f.Info.QueryPlan.Query,
224-
Representations: f.Info.QueryPlan.DependsOnFields,
225226
Path: n.Item.ResponsePath,
226227
}
228+
229+
if f.Info.QueryPlan != nil {
230+
queryPlan.Fetch.Query = f.Info.QueryPlan.Query
231+
queryPlan.Fetch.Representations = f.Info.QueryPlan.DependsOnFields
232+
}
227233
case *BatchEntityFetch:
228234
queryPlan.Fetch = &FetchTreeQueryPlan{
229235
Kind: "BatchEntity",
230236
FetchID: f.FetchDependencies.FetchID,
231237
DependsOnFetchIDs: f.FetchDependencies.DependsOnFetchIDs,
232238
SubgraphName: f.Info.DataSourceName,
233239
SubgraphID: f.Info.DataSourceID,
234-
Query: f.Info.QueryPlan.Query,
235-
Representations: f.Info.QueryPlan.DependsOnFields,
236240
Path: n.Item.ResponsePath,
237241
}
242+
243+
if f.Info.QueryPlan != nil {
244+
queryPlan.Fetch.Query = f.Info.QueryPlan.Query
245+
queryPlan.Fetch.Representations = f.Info.QueryPlan.DependsOnFields
246+
}
238247
case *ParallelListItemFetch:
239248
queryPlan.Fetch = &FetchTreeQueryPlan{
240249
Kind: "ParallelList",
241250
FetchID: f.Fetch.FetchDependencies.FetchID,
242251
DependsOnFetchIDs: f.Fetch.FetchDependencies.DependsOnFetchIDs,
243252
SubgraphName: f.Fetch.Info.DataSourceName,
244253
SubgraphID: f.Fetch.Info.DataSourceID,
245-
Query: f.Fetch.Info.QueryPlan.Query,
246-
Representations: f.Fetch.Info.QueryPlan.DependsOnFields,
247254
Path: n.Item.ResponsePath,
248255
}
256+
257+
if f.Fetch.Info.QueryPlan != nil {
258+
queryPlan.Fetch.Query = f.Fetch.Info.QueryPlan.Query
259+
queryPlan.Fetch.Representations = f.Fetch.Info.QueryPlan.DependsOnFields
260+
}
249261
default:
250262
}
251263
case FetchTreeNodeKindSequence, FetchTreeNodeKindParallel:

0 commit comments

Comments
 (0)