Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid "Object types must have fields" warnings. #83

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading