Skip to content

Commit

Permalink
Merge pull request #83 from block/myron/address-graphql-warnings
Browse files Browse the repository at this point in the history
Avoid "Object types must have fields" warnings.
  • Loading branch information
myronmarston authored Jan 2, 2025
2 parents b040b4d + 898e4bb commit aad51d2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ def self.with_both_casing_forms(&block)
t.field "id", "ID" do |f|
expect(f).not_to respond_to(*field_extensions)
end
t.index "t1"
end

schema.interface_type "T2" do |t|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ class Schema
RSpec.describe Type, :ensure_no_orphaned_types do
it "exposes the name as a capitalized symbol" do
type = define_schema do |schema|
schema.object_type "Color"
schema.object_type "Color" do |t|
t.field "name", "String"
end
end.type_named("Color")

expect(type.name).to eq :Color
end

it "inspects well" do
type = define_schema do |schema|
schema.object_type "Color"
schema.object_type "Color" do |t|
t.field "name", "String"
end
end.type_named("Color")

expect(type.inspect).to eq "#<ElasticGraph::GraphQL::Schema::Type Color>"
Expand Down Expand Up @@ -608,7 +612,7 @@ def type_for(field_name)
describe "#search_index_definitions" do
it "returns an empty array for a non-union type that is not indexed" do
search_index_definitions = search_index_definitions_from do |schema, type|
schema.object_type(type) {}
schema.object_type(type) { |t| t.field "name", "String" }
end

expect(search_index_definitions).to eq []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class GraphQL
describe "#type_named" do
let(:schema) do
define_schema do |s|
s.object_type "Color"
s.object_type "Color" do |f|
f.field "name", "String"
end
end
end

Expand Down Expand Up @@ -77,7 +79,9 @@ class GraphQL
s.enum_type "Options" do |t|
t.value "firstOption"
end
s.object_type "Color"
s.object_type "Color" do |t|
t.field "name", "String"
end
end

expect(schema.defined_types).to all be_a Schema::Type
Expand Down
4 changes: 4 additions & 0 deletions elasticgraph-health_check/spec/unit/envoy_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def build_graphql_for_path(http_path_segment)
config = {http_path_segment: http_path_segment}.compact
schema_artifacts = generate_schema_artifacts do |schema|
schema.register_graphql_extension(EnvoyExtension, defined_at: "elastic_graph/health_check/envoy_extension", **config)
schema.object_type "Widget" do |t|
t.field "id", "ID"
t.index "widgets"
end
end

build_graphql(schema_artifacts: schema_artifacts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ def expect_configured_interceptors(graphql)
expect(query_adapter.interceptors).to match_array(yield) # we yield to make it lazy since the interceptors are loaded lazily
expect(query_adapter.interceptors.map(&:elasticgraph_graphql)).to all be graphql
end

def generate_schema_artifacts
super do |schema|
yield schema

# Ensure there's at least one indexed type defined to avoid GraphQL validation errors.
schema.object_type "Widget" do |t|
t.field "id", "ID"
t.index "widgets"
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,9 @@ module SchemaDefinition
f.renamed_from "old_description"
end
t.renamed_from "Widget3"
t.field "id", "ID"
t.index "widgets"
end
end
EOS
Expand Down

0 comments on commit aad51d2

Please sign in to comment.