Build namespace types as object types#1264
Open
jwils wants to merge 1 commit into
Open
Conversation
7f1a360 to
9a863cb
Compare
myronmarston
requested changes
Jun 20, 2026
myronmarston
left a comment
Collaborator
There was a problem hiding this comment.
The approach you've taken here feels pretty messy. Temporarily changing what's essentially a global variable never feels good.
Two alternate approaches I'd consider:
- Delegation: instead of having
NamespaceTypesubclassObjectType, doclass NamespaceType < DelegateClass(ObjectType)so that it wraps anobject_typeinstance. Then anew_object_typeoverride in an extension will apply to theObjectTypethat gets wrapped byNamespaceType. - Don't use a separate type for
namespace_typeat all--instead, havefactory.new_namespace_typeusefactory.new_object_typeand apply namespace-specific settings (e.g.graphql_only true,resolve_fields_with nil) to it before yielding. For theindexoverride that raises an error we could have the rootindexmethod raise an error forgraphql_onlytypes as it doesn't make sense to define an index on a graphql-only type.
I think I like the latter solution best, as namespace_type.rb doesn't really have much logic.
Thoughts?
9a863cb to
c920a13
Compare
Namespace types behave like regular object types with a couple of factory-applied settings: they are GraphQL-only and have no default field resolver. Build them through new_object_type so object-type factory extensions still apply, without introducing a separate NamespaceType subclass or mutating factory constructor state. Since GraphQL-only types have no backing datastore representation, reject index definitions for any GraphQL-only type in HasIndices#index. This keeps namespace types unindexable and makes the invariant explicit at the shared indexing boundary.
c920a13 to
6af2bef
Compare
new_object_type
Collaborator
Author
|
Option 1 I think looked just as messy, so agree with you and went with option 2. @rossroberts-toast let me know if you have any concerns. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Namespace types are now built as regular
ObjectTypeinstances vianew_object_type.new_namespace_typeapplies the namespace-specific settings (graphql_only trueandresolve_fields_with nil) before yielding, so object-type factory extensions apply to namespace types without swapping constructors or maintaining a dedicatedNamespaceTypesubclass.Because GraphQL-only types have no backing datastore representation,
HasIndices#indexnow rejects index definitions on any GraphQL-only type. That keeps namespace types unindexable at the shared indexing boundary instead of via a namespace-only subclass override.The Apollo factory extension no longer needs a separate namespace hook because namespace creation now flows through its existing
new_object_typeextension.Testing Performed
bundle exec rspec elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/factory_spec.rbbundle exec rspec elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/graphql_schema/namespace_type_spec.rb elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/graphql_schema/object_type_spec.rbbundle exec rspec elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/runtime_metadata/object_types_by_name/namespace_type_spec.rb elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/datastore_config/index_mappings/namespace_type_spec.rbbundle exec rspec elasticgraph-apollo/spec/unit/elastic_graph/apollo/schema_definition_spec.rbscript/type_checkscript/lintgit diff --check