Fix #700: Support custom string-based map key types in DefaultResolveFn#737
Fix #700: Support custom string-based map key types in DefaultResolveFn#737cobyfrombrooklyn-bot wants to merge 1 commit intographql-go:masterfrom
Conversation
DefaultResolveFn panicked with 'reflect.Value.MapIndex: value of type string is not assignable to type X' when resolving fields from maps with custom string-based key types (e.g., map[MyKey]V where type MyKey string). The fix converts the field name string to the map's actual key type using reflect.Value.Convert before calling MapIndex. Fixes graphql-go#700
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughFixes Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
DefaultResolveFnpanicked withreflect.Value.MapIndex: value of type string is not assignable to type Xwhen resolving fields from maps with custom string-based key types like:The issue is that
reflect.ValueOf(p.Info.FieldName)creates astringvalue, but the map expects aTranslationKeykey. Go reflection requires exact type matching forMapIndex.Fix
Convert the field name to the map's actual key type using
reflect.Value.Convert(r.Type().Key())before callingMapIndex. This is safe because we already check that the key kind isreflect.String.Test
Added
TestDefaultResolveFn_MapWithCustomStringKeyTypethat creates a schema usingmap[TranslationKey]stringas the source data and verifies fields are resolved correctly. Without the fix, the test fails with theMapIndexpanic. With the fix, it passes.Full test suite passes. Tested locally on macOS ARM (Apple Silicon).
Fixes #700
Summary by CodeRabbit
Bug Fixes
Tests