Skip to content

Allow extending existing fields#4522

Open
egoodwinx wants to merge 10 commits intographql:16.x.xfrom
egoodwinx:extend-fields
Open

Allow extending existing fields#4522
egoodwinx wants to merge 10 commits intographql:16.x.xfrom
egoodwinx:extend-fields

Conversation

@egoodwinx
Copy link

Summary

This PR adds the ability to extend and modify existing fields when using GraphQL schema extensions, enabling more flexible schema composition patterns. Previously, extending a type with a field that already existed would cause a validation error. Now, extensions can override field properties and additively merge field arguments.

Motivation

RFC: graphql/graphql-spec#1162 (comment)

Changes

Core Implementation
extendSchema.ts

Added mergeFieldConfigs() function to intelligently merge field configurations
Added mergeFieldMaps() function to merge field maps from extensions
Modified buildFieldMap() to detect and merge duplicate field definitions
Updated extendObjectType() and extendInterfaceType() to use field merging
Merging Behavior:

Field type: Incoming type overrides existing (allows type evolution)
Description: Incoming description overrides existing
Arguments: Merged additively (existing + new arguments)
Deprecation reason: Incoming reason overrides existing

Tests

src/utilities/tests/extendSchema-test.ts

Added comprehensive test suite for field merging scenarios:
✅ Merging field types when extending with same field name
✅ Merging field arguments additively
✅ Merging multiple extensions on the same field
✅ Merging field descriptions
✅ Preserving original field properties when not overridden
✅ Allowing overriding field properties with extensions
✅ Interface field merging
✅ Complex multi-extension scenarios

@egoodwinx egoodwinx requested a review from a team as a code owner January 15, 2026 03:14
@vercel
Copy link

vercel bot commented Jan 15, 2026

@egoodwinx is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@egoodwinx
Copy link
Author

@martinbonnin 👀

@martinbonnin martinbonnin changed the title intial commit of allowing extension of existing fields Allow extending existing fields Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant