Skip to content

Commit

Permalink
Merge pull request #33 from block/myron/defined-types
Browse files Browse the repository at this point in the history
Restore `GraphQL::Schema#defined_types`.
  • Loading branch information
myronmarston authored Nov 12, 2024
2 parents 09336d0 + faf71e6 commit 1f939ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion elasticgraph-graphql/lib/elastic_graph/graphql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 1f939ed

Please sign in to comment.