elasticgraph-apollo 0.19.1.1 → 0.19.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/apollo_tests_implementation/Gemfile +1 -1
  4. data/apollo_tests_implementation/Rakefile +1 -1
  5. data/apollo_tests_implementation/config/products_schema.rb +33 -43
  6. data/apollo_tests_implementation/config/settings.yaml +0 -3
  7. data/apollo_tests_implementation/config.ru +1 -1
  8. data/apollo_tests_implementation/lib/product_resolver.rb +40 -0
  9. data/lib/elastic_graph/apollo/graphql/engine_extension.rb +2 -18
  10. data/lib/elastic_graph/apollo/graphql/entities_field_resolver.rb +6 -10
  11. data/lib/elastic_graph/apollo/graphql/http_endpoint_extension.rb +1 -1
  12. data/lib/elastic_graph/apollo/graphql/service_field_resolver.rb +4 -4
  13. data/lib/elastic_graph/apollo/schema_definition/api_extension.rb +64 -2
  14. data/lib/elastic_graph/apollo/schema_definition/apollo_directives.rb +1 -1
  15. data/lib/elastic_graph/apollo/schema_definition/argument_extension.rb +1 -1
  16. data/lib/elastic_graph/apollo/schema_definition/entity_type_extension.rb +1 -1
  17. data/lib/elastic_graph/apollo/schema_definition/enum_type_extension.rb +1 -1
  18. data/lib/elastic_graph/apollo/schema_definition/enum_value_extension.rb +1 -1
  19. data/lib/elastic_graph/apollo/schema_definition/factory_extension.rb +1 -8
  20. data/lib/elastic_graph/apollo/schema_definition/field_extension.rb +1 -1
  21. data/lib/elastic_graph/apollo/schema_definition/input_type_extension.rb +1 -1
  22. data/lib/elastic_graph/apollo/schema_definition/interface_type_extension.rb +1 -1
  23. data/lib/elastic_graph/apollo/schema_definition/object_type_extension.rb +1 -1
  24. data/lib/elastic_graph/apollo/schema_definition/scalar_type_extension.rb +1 -1
  25. data/lib/elastic_graph/apollo/schema_definition/state_extension.rb +1 -1
  26. data/lib/elastic_graph/apollo/schema_definition/union_type_extension.rb +1 -1
  27. metadata +31 -30
  28. data/apollo_tests_implementation/lib/test_implementation_extension.rb +0 -60
  29. data/lib/elastic_graph/apollo/schema_definition/graphql_sdl_enumerator_extension.rb +0 -71
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c937a0a759548d7fe544f8a52daac00d43716a6a7df5df6390b8785e2da7f27
4
- data.tar.gz: '018720eee79797a6d163971616103b766d0e815739ae83746a5219fc8b584a5c'
3
+ metadata.gz: a3dcfc8070c3cbc774f99e9bfe5996a2dac0a5b457a24d0308bfad115250e296
4
+ data.tar.gz: 8d281a6281dd917b52335e8a09fa3563006287be3f091ad27288a48fbc115ba6
5
5
  SHA512:
6
- metadata.gz: 4ca8a19b980f9cb6c83a057b98ffd10f9bb1026b10ae295639703d2635bcc4818466839f4e7511a62918e14596ccd792fc6fe1d7ac6420901f7720cb51a7a25d
7
- data.tar.gz: 0d694363b95f2aef3bb4f6477e4a4b9d75446f9d89a4fd8eea0f497ef33440df63cd6f66aa01c4018b2bdde34f8f5adcbb65a717f1c2b3caa1d260d65c3c5e40
6
+ metadata.gz: 819486e64c39d3b77cd4f1a0e73de839ddf33ba115ef8c22dce5f16fdb122bc8cede407dcfc84c4b24f732f32f318eadd3b487c02345f419e656f20bd3ce45f4
7
+ data.tar.gz: cb51ee0da3e5aa0c4a8a21c8392cd1f15d94edeff8268746fd81890b9d2ce9d0cb3033cfabe2df06faeca968da721ee35e9542972bac01af4699b0e4771d962a
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024 Block, Inc.
3
+ Copyright (c) 2024 - 2025 Block, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -8,46 +8,6 @@
8
8
 
9
9
  # @private
10
10
  module ApolloTestImpl
11
- module GraphQLSDLEnumeratorExtension
12
- # The `apollo-federation-subgraph-compatibility` project requires[^1] that each tested implementation provide
13
- # specific `Query` fields:
14
- #
15
- # ```graphql
16
- # type Query {
17
- # product(id: ID!): Product
18
- # deprecatedProduct(sku: String!, package: String!): DeprecatedProduct @deprecated(reason: "Use product query instead")
19
- # }
20
- # ```
21
- #
22
- # ElasticGraph automatically provides plural fields for our indexed types (e.g. `products` and `deprecatedProducts`).
23
- # For the Apollo tests we need to additionally provide the two fields above. This hooks into the generation of the
24
- # `Query` type to add the required fields.
25
- #
26
- # [^1]: https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/2.0.0/COMPATIBILITY.md#products-schema-to-be-implemented-by-library-maintainers
27
- def root_query_type
28
- super.tap do |type|
29
- type.field "product", "Product" do |f|
30
- f.argument "id", "ID!"
31
- end
32
-
33
- type.field "deprecatedProduct", "DeprecatedProduct" do |f|
34
- f.argument "sku", "String!"
35
- f.argument "package", "String!"
36
- f.directive "deprecated", reason: "Use product query instead"
37
- end
38
- end
39
- end
40
- end
41
-
42
- # @private
43
- module SchemaDefFactoryExtension
44
- def new_graphql_sdl_enumerator(all_types_except_root_query_type)
45
- super(all_types_except_root_query_type).tap do |enum|
46
- enum.extend GraphQLSDLEnumeratorExtension
47
- end
48
- end
49
- end
50
-
51
11
  federation_version = ENV["TARGET_APOLLO_FEDERATION_VERSION"]
52
12
 
53
13
  # Note: this includes many "manual" schema elements (directives, raw SDL, etc) that the
@@ -57,8 +17,6 @@ module ApolloTestImpl
57
17
  #
58
18
  # https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/2.0.0/COMPATIBILITY.md#products-schema-to-be-implemented-by-library-maintainers
59
19
  ElasticGraph.define_schema do |schema|
60
- schema.factory.extend SchemaDefFactoryExtension
61
-
62
20
  schema.json_schema_version 1
63
21
  schema.target_apollo_federation_version(federation_version) if federation_version
64
22
 
@@ -72,6 +30,38 @@ module ApolloTestImpl
72
30
  EOS
73
31
  end
74
32
 
33
+ # The `apollo-federation-subgraph-compatibility` project requires[^1] that each tested implementation provide
34
+ # specific `Query` fields:
35
+ #
36
+ # ```graphql
37
+ # type Query {
38
+ # product(id: ID!): Product
39
+ # deprecatedProduct(sku: String!, package: String!): DeprecatedProduct @deprecated(reason: "Use product query instead")
40
+ # }
41
+ # ```
42
+ #
43
+ # ElasticGraph automatically provides plural fields for our indexed types (e.g. `products` and `deprecatedProducts`).
44
+ # For the Apollo tests we need to additionally provide the two fields above. This hooks into the generation of the
45
+ # `Query` type to add the required fields.
46
+ #
47
+ # [^1]: https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/2.0.0/COMPATIBILITY.md#products-schema-to-be-implemented-by-library-maintainers
48
+ schema.on_root_query_type do |type|
49
+ type.field "product", "Product" do |f|
50
+ f.argument "id", "ID!"
51
+ f.resolver = :product
52
+ end
53
+
54
+ type.field "deprecatedProduct", "DeprecatedProduct" do |f|
55
+ f.argument "sku", "String!"
56
+ f.argument "package", "String!"
57
+ f.directive "deprecated", reason: "Use product query instead"
58
+ f.resolver = :product
59
+ end
60
+ end
61
+
62
+ require_relative "../lib/product_resolver"
63
+ schema.register_graphql_resolver :product, ProductResolver, defined_at: "./lib/product_resolver"
64
+
75
65
  schema.object_type "Product" do |t|
76
66
  t.directive "custom" unless federation_version == "2.0"
77
67
  t.apollo_key fields: "sku package"
@@ -27,8 +27,5 @@ indexer:
27
27
  graphql:
28
28
  default_page_size: 50
29
29
  max_page_size: 500
30
- extension_modules:
31
- - require_path: ./lib/test_implementation_extension
32
- extension_name: ApolloTestImplementationExtension
33
30
  schema_artifacts:
34
31
  directory: config/schema/artifacts
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -0,0 +1,40 @@
1
+ # Copyright 2024 - 2025 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ # The `apollo-federation-subgraph-compatibility` project requires that each tested
10
+ # implementation provide a `Query.product(id: ID!): Product` field. ElasticGraph provides
11
+ # `Query.products(...): ProductConnection!` automatically. To be able to pass the tests,
12
+ # we need to provide the `product` field, even though ElasticGraph doesn't natively provide
13
+ # it. This resolver supports that.
14
+ #
15
+ # @private
16
+ class ProductResolver
17
+ def initialize(elasticgraph_graphql:, config:)
18
+ @datastore_query_builder = elasticgraph_graphql.datastore_query_builder
19
+ @product_index_def = elasticgraph_graphql.datastore_core.index_definitions_by_name.fetch("products")
20
+ @datastore_router = elasticgraph_graphql.datastore_search_router
21
+ end
22
+
23
+ def resolve(field:, object:, args:, context:)
24
+ query = @datastore_query_builder.new_query(
25
+ search_index_definitions: [@product_index_def],
26
+ monotonic_clock_deadline: context[:monotonic_clock_deadline],
27
+ filters: [{"id" => {"equalToAnyOf" => [args.fetch("id")]}}],
28
+ individual_docs_needed: true,
29
+ requested_fields: %w[
30
+ id sku package notes
31
+ variation.id
32
+ dimensions.size dimensions.weight dimensions.unit
33
+ createdBy.averageProductsCreatedPerYear createdBy.email createdBy.name createdBy.totalProductsCreated createdBy.yearsOfEmployment
34
+ research.study.caseNumber research.study.description research.outcome
35
+ ]
36
+ )
37
+
38
+ @datastore_router.msearch([query]).fetch(query).documents.first
39
+ end
40
+ end
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -8,7 +8,7 @@
8
8
 
9
9
  module ElasticGraph
10
10
  module Apollo
11
- # Namespace for all Apollo GraphQL enging logic.
11
+ # Namespace for all Apollo GraphQL engine logic.
12
12
  #
13
13
  # @note This module provides no public types or APIs. It will be used automatically when you use
14
14
  # {SchemaDefinition::APIExtension} as a schema definition extension module.
@@ -18,22 +18,6 @@ module ElasticGraph
18
18
  #
19
19
  # @private
20
20
  module EngineExtension
21
- # @private
22
- def graphql_resolvers
23
- @graphql_resolvers ||= begin
24
- require "elastic_graph/apollo/graphql/entities_field_resolver"
25
- require "elastic_graph/apollo/graphql/service_field_resolver"
26
-
27
- [
28
- EntitiesFieldResolver.new(
29
- datastore_query_builder: datastore_query_builder,
30
- schema_element_names: runtime_metadata.schema_element_names
31
- ),
32
- ServiceFieldResolver.new
33
- ] + super
34
- end
35
- end
36
-
37
21
  # @private
38
22
  def graphql_gem_plugins
39
23
  @graphql_gem_plugins ||= begin
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -19,13 +19,9 @@ module ElasticGraph
19
19
  #
20
20
  # @private
21
21
  class EntitiesFieldResolver
22
- def initialize(datastore_query_builder:, schema_element_names:)
23
- @datastore_query_builder = datastore_query_builder
24
- @schema_element_names = schema_element_names
25
- end
26
-
27
- def can_resolve?(field:, object:)
28
- field.parent_type.name == :Query && field.name == :_entities
22
+ def initialize(elasticgraph_graphql:, config:)
23
+ @datastore_query_builder = elasticgraph_graphql.datastore_query_builder
24
+ @schema_element_names = elasticgraph_graphql.runtime_metadata.schema_element_names
29
25
  end
30
26
 
31
27
  def resolve(field:, object:, args:, context:, lookahead:)
@@ -170,7 +166,7 @@ module ElasticGraph
170
166
  query.merge_with(
171
167
  document_pagination: {first: representations.length},
172
168
  requested_fields: additional_requested_fields_for(representations),
173
- filter: filter
169
+ filters: [filter]
174
170
  )
175
171
  end
176
172
 
@@ -246,7 +242,7 @@ module ElasticGraph
246
242
  # In the case of representations which don't query Id, we ask for 2 documents so that
247
243
  # if something weird is going on and it matches more than 1, we can detect that and return an error.
248
244
  document_pagination: {first: 2},
249
- filter: build_filter_for_hash(fields)
245
+ filters: [build_filter_for_hash(fields)]
250
246
  )
251
247
  end
252
248
 
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -13,11 +13,11 @@ module ElasticGraph
13
13
  #
14
14
  # @private
15
15
  class ServiceFieldResolver
16
- def can_resolve?(field:, object:)
17
- field.parent_type.name == :Query && field.name == :_service
16
+ def initialize(elasticgraph_graphql:, config:)
17
+ # Nothing to initialize, but needs to be defined to satisfy the resolver interface.
18
18
  end
19
19
 
20
- def resolve(field:, object:, args:, context:, lookahead:)
20
+ def resolve(field:, object:, args:, context:)
21
21
  {"sdl" => service_sdl(context.fetch(:elastic_graph_schema).graphql_schema)}
22
22
  end
23
23
 
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -117,7 +117,12 @@ module ElasticGraph
117
117
  api.on_built_in_types do |type|
118
118
  # Built-in types like `PageInfo` need to be tagged with `@shareable` on Federation V2 since other subgraphs may
119
119
  # have them and they aren't entity types. `Query`, as the root, is a special case that must be skipped.
120
- (_ = type).apollo_shareable if type.respond_to?(:apollo_shareable) && type.name != "Query"
120
+ # We also need to customize it.
121
+ if type.name == "Query"
122
+ customize_root_query_type(_ = type)
123
+ elsif type.respond_to?(:apollo_shareable)
124
+ (_ = type).apollo_shareable
125
+ end
121
126
  end
122
127
 
123
128
  api.register_graphql_extension GraphQL::EngineExtension, defined_at: "elastic_graph/apollo/graphql/engine_extension"
@@ -374,6 +379,12 @@ module ElasticGraph
374
379
  t.subtypes(*entity_type_names)
375
380
  end
376
381
  end
382
+
383
+ require(require_path = "elastic_graph/apollo/graphql/entities_field_resolver")
384
+ register_graphql_resolver :apollo_entities, GraphQL::EntitiesFieldResolver, defined_at: require_path
385
+
386
+ require(require_path = "elastic_graph/apollo/graphql/service_field_resolver")
387
+ register_graphql_resolver :apollo_service, GraphQL::ServiceFieldResolver, defined_at: require_path
377
388
  end
378
389
 
379
390
  def apollo_object_type(name, &block)
@@ -444,6 +455,57 @@ module ElasticGraph
444
455
  raise Errors::SchemaError, unresolvable_field_errors.join("\n#{"-" * 100}\n")
445
456
  end
446
457
  end
458
+
459
+ private_class_method def self.customize_root_query_type(type)
460
+ if type.schema_def_state.object_types_by_name.values.any?(&:indexed?)
461
+ type.field "_entities", "[_Entity]!", graphql_only: true do |f|
462
+ f.documentation <<~EOS
463
+ A field required by the [Apollo Federation subgraph
464
+ spec](https://www.apollographql.com/docs/federation/subgraph-spec/#query_entities):
465
+
466
+ > The graph router uses this root-level `Query` field to directly fetch fields of entities defined by a subgraph.
467
+ >
468
+ > This field must take a `representations` argument of type `[_Any!]!` (a non-nullable list of non-nullable
469
+ > [`_Any` scalars](https://www.apollographql.com/docs/federation/subgraph-spec/#scalar-_any)). Its return type must be `[_Entity]!` (a non-nullable list of _nullable_
470
+ > objects that belong to the [`_Entity` union](https://www.apollographql.com/docs/federation/subgraph-spec/#union-_entity)).
471
+ >
472
+ > Each entry in the `representations` list must be validated with the following rules:
473
+ >
474
+ > - A representation must include a `__typename` string field.
475
+ > - A representation must contain all fields included in the fieldset of a `@key` directive applied to the corresponding entity definition.
476
+ >
477
+ > For details, see [Resolving entity fields with `Query._entities`](https://www.apollographql.com/docs/federation/subgraph-spec/#resolving-entity-fields-with-query_entities).
478
+
479
+ Not intended for use by clients other than Apollo.
480
+ EOS
481
+
482
+ f.argument "representations", "[_Any!]!" do |a|
483
+ a.documentation <<~EOS
484
+ A list of entity data blobs from other apollo subgraphs. For more information (and
485
+ to see an example of what form this argument takes), see the [Apollo Federation subgraph
486
+ spec](https://www.apollographql.com/docs/federation/subgraph-spec/#resolve-requests-for-entities).
487
+ EOS
488
+ end
489
+
490
+ f.resolver = :apollo_entities
491
+ end
492
+ end
493
+
494
+ type.field "_service", "_Service!", graphql_only: true do |f|
495
+ f.documentation <<~EOS
496
+ A field required by the [Apollo Federation subgraph
497
+ spec](https://www.apollographql.com/docs/federation/subgraph-spec/#query_service):
498
+
499
+ > This field of the root `Query` type must return a non-nullable [`_Service` type](https://www.apollographql.com/docs/federation/subgraph-spec/#type-_service).
500
+
501
+ > For details, see [Enhanced introspection with `Query._service`](https://www.apollographql.com/docs/federation/subgraph-spec/#enhanced-introspection-with-query_service).
502
+
503
+ Not intended for use by clients other than Apollo.
504
+ EOS
505
+
506
+ f.resolver = :apollo_service
507
+ end
508
+ end
447
509
  end
448
510
  end
449
511
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -10,7 +10,6 @@ require "elastic_graph/apollo/schema_definition/argument_extension"
10
10
  require "elastic_graph/apollo/schema_definition/enum_type_extension"
11
11
  require "elastic_graph/apollo/schema_definition/enum_value_extension"
12
12
  require "elastic_graph/apollo/schema_definition/field_extension"
13
- require "elastic_graph/apollo/schema_definition/graphql_sdl_enumerator_extension"
14
13
  require "elastic_graph/apollo/schema_definition/input_type_extension"
15
14
  require "elastic_graph/apollo/schema_definition/interface_type_extension"
16
15
  require "elastic_graph/apollo/schema_definition/object_type_extension"
@@ -32,12 +31,6 @@ module ElasticGraph
32
31
  end
33
32
  end
34
33
 
35
- def new_graphql_sdl_enumerator(all_types_except_root_query_type)
36
- super.tap do |enum|
37
- enum.extend GraphQLSDLEnumeratorExtension
38
- end
39
- end
40
-
41
34
  def new_argument(field, name, value_type)
42
35
  super(field, name, value_type) do |type|
43
36
  type.extend ArgumentExtension
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Block, Inc.
1
+ # Copyright 2024 - 2025 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticgraph-apollo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1.1
4
+ version: 0.19.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myron Marston
8
8
  - Ben VandenBos
9
9
  - Block Engineering
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2025-02-07 00:00:00.000000000 Z
12
+ date: 2025-04-09 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: elasticgraph-graphql
@@ -18,127 +17,132 @@ dependencies:
18
17
  requirements:
19
18
  - - '='
20
19
  - !ruby/object:Gem::Version
21
- version: 0.19.1.1
20
+ version: 0.19.2.0
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
25
  - - '='
27
26
  - !ruby/object:Gem::Version
28
- version: 0.19.1.1
27
+ version: 0.19.2.0
29
28
  - !ruby/object:Gem::Dependency
30
29
  name: elasticgraph-support
31
30
  requirement: !ruby/object:Gem::Requirement
32
31
  requirements:
33
32
  - - '='
34
33
  - !ruby/object:Gem::Version
35
- version: 0.19.1.1
34
+ version: 0.19.2.0
36
35
  type: :runtime
37
36
  prerelease: false
38
37
  version_requirements: !ruby/object:Gem::Requirement
39
38
  requirements:
40
39
  - - '='
41
40
  - !ruby/object:Gem::Version
42
- version: 0.19.1.1
41
+ version: 0.19.2.0
43
42
  - !ruby/object:Gem::Dependency
44
43
  name: graphql
45
44
  requirement: !ruby/object:Gem::Requirement
46
45
  requirements:
47
46
  - - "~>"
48
47
  - !ruby/object:Gem::Version
49
- version: 2.4.8
48
+ version: 2.5.1
50
49
  type: :runtime
51
50
  prerelease: false
52
51
  version_requirements: !ruby/object:Gem::Requirement
53
52
  requirements:
54
53
  - - "~>"
55
54
  - !ruby/object:Gem::Version
56
- version: 2.4.8
55
+ version: 2.5.1
57
56
  - !ruby/object:Gem::Dependency
58
57
  name: apollo-federation
59
58
  requirement: !ruby/object:Gem::Requirement
60
59
  requirements:
61
60
  - - "~>"
62
61
  - !ruby/object:Gem::Version
63
- version: '3.8'
62
+ version: '3.10'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 3.10.1
64
66
  type: :runtime
65
67
  prerelease: false
66
68
  version_requirements: !ruby/object:Gem::Requirement
67
69
  requirements:
68
70
  - - "~>"
69
71
  - !ruby/object:Gem::Version
70
- version: '3.8'
72
+ version: '3.10'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.10.1
71
76
  - !ruby/object:Gem::Dependency
72
77
  name: elasticgraph-schema_definition
73
78
  requirement: !ruby/object:Gem::Requirement
74
79
  requirements:
75
80
  - - '='
76
81
  - !ruby/object:Gem::Version
77
- version: 0.19.1.1
82
+ version: 0.19.2.0
78
83
  type: :development
79
84
  prerelease: false
80
85
  version_requirements: !ruby/object:Gem::Requirement
81
86
  requirements:
82
87
  - - '='
83
88
  - !ruby/object:Gem::Version
84
- version: 0.19.1.1
89
+ version: 0.19.2.0
85
90
  - !ruby/object:Gem::Dependency
86
91
  name: elasticgraph-admin
87
92
  requirement: !ruby/object:Gem::Requirement
88
93
  requirements:
89
94
  - - '='
90
95
  - !ruby/object:Gem::Version
91
- version: 0.19.1.1
96
+ version: 0.19.2.0
92
97
  type: :development
93
98
  prerelease: false
94
99
  version_requirements: !ruby/object:Gem::Requirement
95
100
  requirements:
96
101
  - - '='
97
102
  - !ruby/object:Gem::Version
98
- version: 0.19.1.1
103
+ version: 0.19.2.0
99
104
  - !ruby/object:Gem::Dependency
100
105
  name: elasticgraph-elasticsearch
101
106
  requirement: !ruby/object:Gem::Requirement
102
107
  requirements:
103
108
  - - '='
104
109
  - !ruby/object:Gem::Version
105
- version: 0.19.1.1
110
+ version: 0.19.2.0
106
111
  type: :development
107
112
  prerelease: false
108
113
  version_requirements: !ruby/object:Gem::Requirement
109
114
  requirements:
110
115
  - - '='
111
116
  - !ruby/object:Gem::Version
112
- version: 0.19.1.1
117
+ version: 0.19.2.0
113
118
  - !ruby/object:Gem::Dependency
114
119
  name: elasticgraph-opensearch
115
120
  requirement: !ruby/object:Gem::Requirement
116
121
  requirements:
117
122
  - - '='
118
123
  - !ruby/object:Gem::Version
119
- version: 0.19.1.1
124
+ version: 0.19.2.0
120
125
  type: :development
121
126
  prerelease: false
122
127
  version_requirements: !ruby/object:Gem::Requirement
123
128
  requirements:
124
129
  - - '='
125
130
  - !ruby/object:Gem::Version
126
- version: 0.19.1.1
131
+ version: 0.19.2.0
127
132
  - !ruby/object:Gem::Dependency
128
133
  name: elasticgraph-indexer
129
134
  requirement: !ruby/object:Gem::Requirement
130
135
  requirements:
131
136
  - - '='
132
137
  - !ruby/object:Gem::Version
133
- version: 0.19.1.1
138
+ version: 0.19.2.0
134
139
  type: :development
135
140
  prerelease: false
136
141
  version_requirements: !ruby/object:Gem::Requirement
137
142
  requirements:
138
143
  - - '='
139
144
  - !ruby/object:Gem::Version
140
- version: 0.19.1.1
141
- description:
145
+ version: 0.19.2.0
142
146
  email:
143
147
  - myron@squareup.com
144
148
  executables: []
@@ -154,7 +158,7 @@ files:
154
158
  - apollo_tests_implementation/config/products_schema.rb
155
159
  - apollo_tests_implementation/config/settings.yaml
156
160
  - apollo_tests_implementation/docker-compose.yaml
157
- - apollo_tests_implementation/lib/test_implementation_extension.rb
161
+ - apollo_tests_implementation/lib/product_resolver.rb
158
162
  - apollo_tests_implementation/wait_for_datastore.sh
159
163
  - lib/elastic_graph/apollo/graphql/engine_extension.rb
160
164
  - lib/elastic_graph/apollo/graphql/entities_field_resolver.rb
@@ -168,7 +172,6 @@ files:
168
172
  - lib/elastic_graph/apollo/schema_definition/enum_value_extension.rb
169
173
  - lib/elastic_graph/apollo/schema_definition/factory_extension.rb
170
174
  - lib/elastic_graph/apollo/schema_definition/field_extension.rb
171
- - lib/elastic_graph/apollo/schema_definition/graphql_sdl_enumerator_extension.rb
172
175
  - lib/elastic_graph/apollo/schema_definition/input_type_extension.rb
173
176
  - lib/elastic_graph/apollo/schema_definition/interface_type_extension.rb
174
177
  - lib/elastic_graph/apollo/schema_definition/object_type_extension.rb
@@ -183,12 +186,11 @@ licenses:
183
186
  - MIT
184
187
  metadata:
185
188
  bug_tracker_uri: https://github.com/block/elasticgraph/issues
186
- changelog_uri: https://github.com/block/elasticgraph/releases/tag/v0.19.1.1
187
- documentation_uri: https://block.github.io/elasticgraph/docs/main/
189
+ changelog_uri: https://github.com/block/elasticgraph/releases/tag/v0.19.2.0
190
+ documentation_uri: https://block.github.io/elasticgraph/api-docs/v0.19.2.0/
188
191
  homepage_uri: https://block.github.io/elasticgraph/
189
- source_code_uri: https://github.com/block/elasticgraph/tree/v0.19.1.1/elasticgraph-apollo
192
+ source_code_uri: https://github.com/block/elasticgraph/tree/v0.19.2.0/elasticgraph-apollo
190
193
  gem_category: extension
191
- post_install_message:
192
194
  rdoc_options: []
193
195
  require_paths:
194
196
  - lib
@@ -206,8 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
208
  - !ruby/object:Gem::Version
207
209
  version: '0'
208
210
  requirements: []
209
- rubygems_version: 3.5.22
210
- signing_key:
211
+ rubygems_version: 3.6.2
211
212
  specification_version: 4
212
213
  summary: An ElasticGraph extension that implements the Apollo federation spec.
213
214
  test_files: []
@@ -1,60 +0,0 @@
1
- # Copyright 2024 Block, Inc.
2
- #
3
- # Use of this source code is governed by an MIT-style
4
- # license that can be found in the LICENSE file or at
5
- # https://opensource.org/licenses/MIT.
6
- #
7
- # frozen_string_literal: true
8
-
9
- # The `apollo-federation-subgraph-compatibility` project requires that each tested
10
- # implementation provide a `Query.product(id: ID!): Product` field. ElasticGraph provides
11
- # `Query.products(...): ProductConnection!` automatically. To be able to pass the tests,
12
- # we need to provide the `product` field, even though ElasticGraph doesn't natively provide
13
- # it.
14
- #
15
- # This defines an extension that injects a custom resolver that supports the field.
16
- # @private
17
- module ApolloTestImplementationExtension
18
- def graphql_resolvers
19
- @graphql_resolvers ||= [product_field_resolver] + super
20
- end
21
-
22
- def product_field_resolver
23
- @product_field_resolver ||= ProductFieldResolver.new(
24
- datastore_query_builder: datastore_query_builder,
25
- product_index_def: datastore_core.index_definitions_by_name.fetch("products"),
26
- datastore_router: datastore_search_router
27
- )
28
- end
29
-
30
- # @private
31
- class ProductFieldResolver
32
- def initialize(datastore_query_builder:, product_index_def:, datastore_router:)
33
- @datastore_query_builder = datastore_query_builder
34
- @product_index_def = product_index_def
35
- @datastore_router = datastore_router
36
- end
37
-
38
- def can_resolve?(field:, object:)
39
- field.parent_type.name == :Query && field.name == :product
40
- end
41
-
42
- def resolve(field:, object:, args:, context:, lookahead:)
43
- query = @datastore_query_builder.new_query(
44
- search_index_definitions: [@product_index_def],
45
- monotonic_clock_deadline: context[:monotonic_clock_deadline],
46
- filter: {"id" => {"equalToAnyOf" => [args.fetch("id")]}},
47
- individual_docs_needed: true,
48
- requested_fields: %w[
49
- id sku package notes
50
- variation.id
51
- dimensions.size dimensions.weight dimensions.unit
52
- createdBy.averageProductsCreatedPerYear createdBy.email createdBy.name createdBy.totalProductsCreated createdBy.yearsOfEmployment
53
- research.study.caseNumber research.study.description research.outcome
54
- ]
55
- )
56
-
57
- @datastore_router.msearch([query]).fetch(query).documents.first
58
- end
59
- end
60
- end
@@ -1,71 +0,0 @@
1
- # Copyright 2024 Block, Inc.
2
- #
3
- # Use of this source code is governed by an MIT-style
4
- # license that can be found in the LICENSE file or at
5
- # https://opensource.org/licenses/MIT.
6
- #
7
- # frozen_string_literal: true
8
-
9
- module ElasticGraph
10
- module Apollo
11
- module SchemaDefinition
12
- # Module designed to be extended onto an `ElasticGraph::SchemaDefinition::GraphQLSDLEnumerator`
13
- # instance to customize the schema artifacts to support Apollo.
14
- #
15
- # @private
16
- module GraphQLSDLEnumeratorExtension
17
- def root_query_type
18
- super.tap do |type_or_nil|
19
- # @type var type: ElasticGraph::SchemaDefinition::SchemaElements::ObjectType
20
- type = _ = type_or_nil
21
-
22
- if schema_def_state.object_types_by_name.values.any?(&:indexed?)
23
- type.field "_entities", "[_Entity]!" do |f|
24
- f.documentation <<~EOS
25
- A field required by the [Apollo Federation subgraph
26
- spec](https://www.apollographql.com/docs/federation/subgraph-spec/#query_entities):
27
-
28
- > The graph router uses this root-level `Query` field to directly fetch fields of entities defined by a subgraph.
29
- >
30
- > This field must take a `representations` argument of type `[_Any!]!` (a non-nullable list of non-nullable
31
- > [`_Any` scalars](https://www.apollographql.com/docs/federation/subgraph-spec/#scalar-_any)). Its return type must be `[_Entity]!` (a non-nullable list of _nullable_
32
- > objects that belong to the [`_Entity` union](https://www.apollographql.com/docs/federation/subgraph-spec/#union-_entity)).
33
- >
34
- > Each entry in the `representations` list must be validated with the following rules:
35
- >
36
- > - A representation must include a `__typename` string field.
37
- > - A representation must contain all fields included in the fieldset of a `@key` directive applied to the corresponding entity definition.
38
- >
39
- > For details, see [Resolving entity fields with `Query._entities`](https://www.apollographql.com/docs/federation/subgraph-spec/#resolving-entity-fields-with-query_entities).
40
-
41
- Not intended for use by clients other than Apollo.
42
- EOS
43
-
44
- f.argument "representations", "[_Any!]!" do |a|
45
- a.documentation <<~EOS
46
- A list of entity data blobs from other apollo subgraphs. For more information (and
47
- to see an example of what form this argument takes), see the [Apollo Federation subgraph
48
- spec](https://www.apollographql.com/docs/federation/subgraph-spec/#resolve-requests-for-entities).
49
- EOS
50
- end
51
- end
52
- end
53
-
54
- type.field "_service", "_Service!" do |f|
55
- f.documentation <<~EOS
56
- A field required by the [Apollo Federation subgraph
57
- spec](https://www.apollographql.com/docs/federation/subgraph-spec/#query_service):
58
-
59
- > This field of the root `Query` type must return a non-nullable [`_Service` type](https://www.apollographql.com/docs/federation/subgraph-spec/#type-_service).
60
-
61
- > For details, see [Enhanced introspection with `Query._service`](https://www.apollographql.com/docs/federation/subgraph-spec/#enhanced-introspection-with-query_service).
62
-
63
- Not intended for use by clients other than Apollo.
64
- EOS
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
71
- end