Skip to content
Draft
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 @@ -28,9 +28,7 @@ module FactoryExtension
def new_enum_type(name)
super(name) do |type|
type.extend EnumTypeExtension
# :nocov: -- currently all invocations have a block
yield type if block_given?
# :nocov:
end
end

Expand Down Expand Up @@ -59,9 +57,7 @@ def new_index(name, settings, type, &block)
def new_interface_type(name)
super(name) do |type|
type.extend ObjectInterfaceAndUnionExtension
# :nocov: -- currently all invocations have a block
yield type if block_given?
# :nocov:
end
end

Expand All @@ -73,9 +69,7 @@ def new_interface_type(name)
def new_object_type(name)
super(name) do |type|
type.extend ObjectInterfaceAndUnionExtension
# :nocov: -- currently all invocations have a block
yield type if block_given?
# :nocov:
end
end

Expand All @@ -87,9 +81,7 @@ def new_object_type(name)
def new_scalar_type(name)
super(name) do |type|
type.extend ScalarTypeExtension
# :nocov: -- currently all invocations have a block
yield type if block_given?
# :nocov:
end
end

Expand All @@ -101,9 +93,7 @@ def new_scalar_type(name)
def new_union_type(name)
super(name) do |type|
type.extend ObjectInterfaceAndUnionExtension
# :nocov: -- currently all invocations have a block
yield type if block_given?
# :nocov:
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2024 - 2026 Block, Inc.
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
#
# frozen_string_literal: true

require "elastic_graph/spec_support/schema_definition_helpers"
require "elastic_graph/warehouse/schema_definition/api_extension"

module ElasticGraph
module Warehouse
module SchemaDefinition
RSpec.describe FactoryExtension do
include_context "SchemaDefinitionHelpers"

it "extends enum types created without customization blocks" do
api = build_api
api.enum_type "Status"

expect(api.state.enum_types_by_name.fetch("Status")).to be_a(EnumTypeExtension)
end

it "extends interface types created without customization blocks" do
api = build_api
api.interface_type "Identifiable"

expect(api.state.object_types_by_name.fetch("Identifiable")).to be_a(ObjectInterfaceAndUnionExtension)
end

it "extends object types created without customization blocks" do
api = build_api
api.object_type "Widget"

expect(api.state.object_types_by_name.fetch("Widget")).to be_a(ObjectInterfaceAndUnionExtension)
end

it "allows scalar type validation to fail normally without a customization block" do
api = build_api

expect {
api.scalar_type "Money"
}.to raise_error(Errors::SchemaError, a_string_including("Scalar types require `mapping` to be configured"))
end

it "extends union types created without customization blocks" do
api = build_api
api.union_type "SearchResult"

expect(api.state.object_types_by_name.fetch("SearchResult")).to be_a(ObjectInterfaceAndUnionExtension)
end

def build_api

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need this since you're using include_context "SchemaDefinitionHelpers" -- just use define_schema.

schema_elements = SchemaArtifacts::RuntimeMetadata::SchemaElementNames.new(form: "snake_case")
ElasticGraph::SchemaDefinition::API.new(
schema_elements,
true,
extension_modules: [APIExtension],
output: log_device
)
end
end
end
end
end