diff --git a/elasticgraph-graphql/lib/elastic_graph/graphql/schema.rb b/elasticgraph-graphql/lib/elastic_graph/graphql/schema.rb index 354f2990..6cd69d7e 100644 --- a/elasticgraph-graphql/lib/elastic_graph/graphql/schema.rb +++ b/elasticgraph-graphql/lib/elastic_graph/graphql/schema.rb @@ -106,7 +106,11 @@ def enum_value_named(type_name, enum_value_name) # The list of user-defined types that are indexed document types. (Indexed aggregation types will not be included in this.) def indexed_document_types - @indexed_document_types ||= @types_by_name.values.select(&:indexed_document?) + @indexed_document_types ||= defined_types.select(&:indexed_document?) + end + + def defined_types + @defined_types ||= @types_by_name.except(*BUILT_IN_TYPE_NAMES).values end def to_s diff --git a/elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema_spec.rb b/elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema_spec.rb index 43ce5a61..9383437c 100644 --- a/elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema_spec.rb +++ b/elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema_spec.rb @@ -70,6 +70,22 @@ class GraphQL end end + describe "#defined_types" do + # Note: `defined_type` isn't used internally by ElasticGraph itself, but it's exposed for use by extensions. + it "returns a list containing all explicitly defined types (excluding built-ins)" do + schema = define_schema do |s| + s.enum_type "Options" do |t| + t.value "firstOption" + end + s.object_type "Color" + end + + expect(schema.defined_types).to all be_a Schema::Type + expect(schema.defined_types.map(&:name)).to include(:Options, :Color, :Query) + .and exclude(:Int, :Float, :Boolean, :String, :ID) + end + end + describe "#indexed_document_types" do it "returns a list containing all types defined as indexed types" do schema = define_schema do |s|