Skip to content

Commit bd9b1cd

Browse files
Allow null query_cluster in datastore config to hide types
The acceptance tests demonstrate that setting `query_cluster: nil` should hide index types from the GraphQL schema. However, loading this configuration from YAML fails validation because the JSON schema only accepts string values. This commit updates the schema definitions to accept null values: - Updated config_schema.yaml to allow ['string', 'null'] - Updated config.rb JSON schema to allow ["string", "null"] - Updated RBS type signatures to allow String? - Added regression test for YAML loading with null value - Updated documentation to explain null behavior The query_cluster field remains required to force explicit configuration choices. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d0aed7a commit bd9b1cd

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

elasticgraph-datastore_core/lib/elastic_graph/datastore_core/config.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ class Config < Support::Config.define(:client_faraday_adapter, :clusters, :index
132132
}],
133133
properties: {
134134
query_cluster: {
135-
type: "string",
136-
description: "Named search cluster to be used for queries on this index. The value must match be a key in the `clusters` map.",
137-
examples: ["main", "search_cluster"]
135+
type: ["string", "null"],
136+
description: "Named search cluster to be used for queries on this index. The value must match be a key in the `clusters` map. Set to `nil` to hide this index's types from the GraphQL schema.",
137+
examples: ["main", "search_cluster", nil]
138138
},
139139
index_into_clusters: {
140140
type: "array",

elasticgraph-datastore_core/sig/elastic_graph/datastore_core/configuration/index_definition.rbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ module ElasticGraph
33
module Configuration
44
class IndexDefinitionSupertype
55
attr_reader ignore_routing_values: ::Set[::String]
6-
attr_reader query_cluster: ::String
6+
attr_reader query_cluster: ::String?
77
attr_reader index_into_clusters: ::Array[::String]
88
attr_reader setting_overrides: ::Hash[::String, untyped]
99
attr_reader setting_overrides_by_timestamp: ::Hash[::String, ::Hash[::String, untyped]]
1010
attr_reader custom_timestamp_ranges: ::Array[IndexDefinition::CustomTimestampRange]
1111

1212
def initialize: (
1313
ignore_routing_values: ::Set[::String],
14-
query_cluster: ::String,
14+
query_cluster: ::String?,
1515
index_into_clusters: ::Array[::String],
1616
setting_overrides: ::Hash[::String, untyped],
1717
setting_overrides_by_timestamp: ::Hash[::String, ::Hash[::String, untyped]],
@@ -20,7 +20,7 @@ module ElasticGraph
2020

2121
def with: (
2222
?ignore_routing_values: ::Set[::String],
23-
?query_cluster: ::String,
23+
?query_cluster: ::String?,
2424
?index_into_clusters: ::Array[::String],
2525
?setting_overrides: ::Hash[::String, untyped],
2626
?setting_overrides_by_timestamp: ::Hash[::String, ::Hash[::String, untyped]],

elasticgraph-datastore_core/spec/unit/elastic_graph/datastore_core/config_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,43 @@ class DatastoreCore
9797
expect(config.max_client_retries).to eq 3
9898
end
9999

100+
it "allows `query_cluster: null` to hide index types from GraphQL schema" do
101+
config = config_from_yaml(<<~YAML)
102+
client_faraday_adapter: {}
103+
clusters:
104+
main1:
105+
url: http://example.com/1234
106+
backend: elasticsearch
107+
settings:
108+
foo: 23
109+
index_definitions:
110+
widgets:
111+
query_cluster: null
112+
index_into_clusters: ["main1"]
113+
ignore_routing_values: []
114+
setting_overrides: {}
115+
setting_overrides_by_timestamp: {}
116+
custom_timestamp_ranges: []
117+
YAML
118+
119+
widgets_config = config.index_definitions.fetch("widgets")
120+
121+
# Verify the config was loaded correctly from YAML
122+
expect(widgets_config).to eq(Configuration::IndexDefinition.new(
123+
ignore_routing_values: [],
124+
query_cluster: nil,
125+
index_into_clusters: ["main1"],
126+
setting_overrides: {},
127+
setting_overrides_by_timestamp: {},
128+
custom_timestamp_ranges: []
129+
))
130+
131+
# Verify the key property: query_cluster is nil (not a string, not missing)
132+
# This nil value will cause accessible_from_queries? to return false,
133+
# which hides the index's types from the GraphQL schema.
134+
expect(widgets_config.query_cluster).to be_nil
135+
end
136+
100137
it "surfaces misspellings in `backend`" do
101138
expect {
102139
config_from_yaml(<<~YAML)

elasticgraph-local/lib/elastic_graph/local/spec_support/config_schema.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,16 @@ properties:
141141
number_of_shards: 32
142142
properties:
143143
query_cluster:
144-
type: string
144+
type:
145+
- string
146+
- 'null'
145147
description: Named search cluster to be used for queries on this index.
146-
The value must match be a key in the `clusters` map.
148+
The value must match be a key in the `clusters` map. Set to `nil`
149+
to hide this index's types from the GraphQL schema.
147150
examples:
148151
- main
149152
- search_cluster
153+
-
150154
index_into_clusters:
151155
type: array
152156
items:

0 commit comments

Comments
 (0)