Skip to content

Commit 945b9cf

Browse files
committed
Provide apollo_entity_ref_field to expose an id field as an entity ref.
When plugging into an Apollo supergraph, it's quite useful to be able to expoes "entity reference" types (e.g. a type with just an id field, that refers to an entity owned by another subgraph) rather than just exposing an id field. This allows Apollo to federate the type. This adds two new APIs to support this: * `apollo_entity_ref_field` * `apollo_entity_ref_paginated_collection_field` The latter exposes a list of ids as a paginated relay connection.
1 parent a577648 commit 945b9cf

24 files changed

Lines changed: 1291 additions & 9 deletions

File tree

config/schema/artifacts/datastore_config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,10 @@ indices:
15431543
type: integer
15441544
part_ids:
15451545
type: keyword
1546+
owner_ids:
1547+
type: keyword
1548+
owner_id:
1549+
type: keyword
15461550
__counts:
15471551
properties:
15481552
tags:
@@ -1551,6 +1555,8 @@ indices:
15511555
type: integer
15521556
part_ids:
15531557
type: integer
1558+
owner_ids:
1559+
type: integer
15541560
__sources:
15551561
type: keyword
15561562
__versions:

config/schema/artifacts/json_schemas.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ json_schema_version: 1
212212
allOf:
213213
- "$ref": "#/$defs/ID"
214214
- maxLength: 8191
215+
owner_ids:
216+
type: array
217+
items:
218+
allOf:
219+
- "$ref": "#/$defs/ID"
220+
- maxLength: 8191
221+
owner_id:
222+
anyOf:
223+
- allOf:
224+
- "$ref": "#/$defs/ID"
225+
- maxLength: 8191
226+
- type: 'null'
215227
__typename:
216228
type: string
217229
const: Component
@@ -223,6 +235,8 @@ json_schema_version: 1
223235
- position
224236
- tags
225237
- part_ids
238+
- owner_ids
239+
- owner_id
226240
Date:
227241
type: string
228242
format: date

config/schema/artifacts/json_schemas_by_version/v1.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,24 @@ json_schema_version: 1
263263
ElasticGraph:
264264
type: "[ID!]!"
265265
nameInIndex: part_ids
266+
owner_ids:
267+
type: array
268+
items:
269+
allOf:
270+
- "$ref": "#/$defs/ID"
271+
- maxLength: 8191
272+
ElasticGraph:
273+
type: "[ID!]!"
274+
nameInIndex: owner_ids
275+
owner_id:
276+
anyOf:
277+
- allOf:
278+
- "$ref": "#/$defs/ID"
279+
- maxLength: 8191
280+
- type: 'null'
281+
ElasticGraph:
282+
type: ID
283+
nameInIndex: owner_id
266284
__typename:
267285
type: string
268286
const: Component
@@ -274,6 +292,8 @@ json_schema_version: 1
274292
- position
275293
- tags
276294
- part_ids
295+
- owner_ids
296+
- owner_id
277297
Date:
278298
type: string
279299
format: date

config/schema/artifacts/runtime_metadata.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,8 @@ index_definitions_by_name:
15631563
- direction: desc
15641564
field_path: created_at
15651565
fields_by_path:
1566+
__counts.owner_ids:
1567+
source: __self
15661568
__counts.part_ids:
15671569
source: __self
15681570
__counts.tags:
@@ -1575,6 +1577,10 @@ index_definitions_by_name:
15751577
source: __self
15761578
name:
15771579
source: __self
1580+
owner_id:
1581+
source: __self
1582+
owner_ids:
1583+
source: __self
15781584
part_ids:
15791585
source: __self
15801586
position.x:
@@ -2980,6 +2986,10 @@ object_types_by_name:
29802986
cardinality: one
29812987
name:
29822988
cardinality: one
2989+
owner_id:
2990+
cardinality: one
2991+
owner_ids:
2992+
cardinality: one
29832993
part_ids:
29842994
cardinality: one
29852995
position:

config/schema/artifacts_with_apollo/datastore_config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,10 @@ indices:
15431543
type: integer
15441544
part_ids:
15451545
type: keyword
1546+
owner_ids:
1547+
type: keyword
1548+
owner_id:
1549+
type: keyword
15461550
__counts:
15471551
properties:
15481552
tags:
@@ -1551,6 +1555,8 @@ indices:
15511555
type: integer
15521556
part_ids:
15531557
type: integer
1558+
owner_ids:
1559+
type: integer
15541560
__sources:
15551561
type: keyword
15561562
__versions:

config/schema/artifacts_with_apollo/json_schemas.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ json_schema_version: 1
212212
allOf:
213213
- "$ref": "#/$defs/ID"
214214
- maxLength: 8191
215+
owner_ids:
216+
type: array
217+
items:
218+
allOf:
219+
- "$ref": "#/$defs/ID"
220+
- maxLength: 8191
221+
owner_id:
222+
anyOf:
223+
- allOf:
224+
- "$ref": "#/$defs/ID"
225+
- maxLength: 8191
226+
- type: 'null'
215227
__typename:
216228
type: string
217229
const: Component
@@ -223,6 +235,8 @@ json_schema_version: 1
223235
- position
224236
- tags
225237
- part_ids
238+
- owner_ids
239+
- owner_id
226240
Date:
227241
type: string
228242
format: date

config/schema/artifacts_with_apollo/json_schemas_by_version/v1.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,24 @@ json_schema_version: 1
263263
ElasticGraph:
264264
type: "[ID!]!"
265265
nameInIndex: part_ids
266+
owner_ids:
267+
type: array
268+
items:
269+
allOf:
270+
- "$ref": "#/$defs/ID"
271+
- maxLength: 8191
272+
ElasticGraph:
273+
type: "[ID!]!"
274+
nameInIndex: owner_ids
275+
owner_id:
276+
anyOf:
277+
- allOf:
278+
- "$ref": "#/$defs/ID"
279+
- maxLength: 8191
280+
- type: 'null'
281+
ElasticGraph:
282+
type: ID
283+
nameInIndex: owner_id
266284
__typename:
267285
type: string
268286
const: Component
@@ -274,6 +292,8 @@ json_schema_version: 1
274292
- position
275293
- tags
276294
- part_ids
295+
- owner_ids
296+
- owner_id
277297
Date:
278298
type: string
279299
format: date

config/schema/artifacts_with_apollo/runtime_metadata.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,21 @@ graphql_resolvers_by_name:
15081508
resolver_ref:
15091509
name: ElasticGraph::Apollo::GraphQL::EntitiesFieldResolver
15101510
require_path: elastic_graph/apollo/graphql/entities_field_resolver
1511+
apollo_entity_ref:
1512+
needs_lookahead: false
1513+
resolver_ref:
1514+
name: ElasticGraph::Apollo::GraphQL::ApolloEntityRefResolver::ForSingleId
1515+
require_path: elastic_graph/apollo/graphql/apollo_entity_ref_resolver
1516+
apollo_entity_ref_list:
1517+
needs_lookahead: false
1518+
resolver_ref:
1519+
name: ElasticGraph::Apollo::GraphQL::ApolloEntityRefResolver::ForIdList
1520+
require_path: elastic_graph/apollo/graphql/apollo_entity_ref_resolver
1521+
apollo_entity_ref_paginated:
1522+
needs_lookahead: false
1523+
resolver_ref:
1524+
name: ElasticGraph::Apollo::GraphQL::ApolloEntityRefResolver::ForPaginatedList
1525+
require_path: elastic_graph/apollo/graphql/apollo_entity_ref_resolver
15111526
apollo_service:
15121527
needs_lookahead: false
15131528
resolver_ref:
@@ -1577,6 +1592,8 @@ index_definitions_by_name:
15771592
- direction: desc
15781593
field_path: created_at
15791594
fields_by_path:
1595+
__counts.owner_ids:
1596+
source: __self
15801597
__counts.part_ids:
15811598
source: __self
15821599
__counts.tags:
@@ -1589,6 +1606,10 @@ index_definitions_by_name:
15891606
source: __self
15901607
name:
15911608
source: __self
1609+
owner_id:
1610+
source: __self
1611+
owner_ids:
1612+
source: __self
15921613
part_ids:
15931614
source: __self
15941615
position.x:
@@ -2934,6 +2955,27 @@ object_types_by_name:
29342955
name:
29352956
resolver:
29362957
name: get_record_field_value
2958+
owner:
2959+
name_in_index: owner_id
2960+
resolver:
2961+
config:
2962+
source_id_field: owner_id
2963+
exposed_id_field: token
2964+
name: apollo_entity_ref
2965+
owners:
2966+
name_in_index: owner_ids
2967+
resolver:
2968+
config:
2969+
source_ids_field: owner_ids
2970+
exposed_id_field: token
2971+
name: apollo_entity_ref_list
2972+
owners_paginated:
2973+
name_in_index: owner_ids
2974+
resolver:
2975+
config:
2976+
source_ids_field: owner_ids
2977+
exposed_id_field: token
2978+
name: apollo_entity_ref_paginated
29372979
part_aggregations:
29382980
relation:
29392981
direction: out
@@ -2994,6 +3036,10 @@ object_types_by_name:
29943036
cardinality: one
29953037
name:
29963038
cardinality: one
3039+
owner_id:
3040+
cardinality: one
3041+
owner_ids:
3042+
cardinality: one
29973043
part_ids:
29983044
cardinality: one
29993045
position:
@@ -3135,6 +3181,35 @@ object_types_by_name:
31353181
name_in_index: widget_workspace_id3
31363182
resolver:
31373183
name: object_with_lookahead
3184+
ComponentOwner:
3185+
graphql_fields_by_name:
3186+
token:
3187+
resolver:
3188+
name: get_record_field_value
3189+
ComponentOwnerConnection:
3190+
elasticgraph_category: relay_connection
3191+
graphql_fields_by_name:
3192+
edges:
3193+
resolver:
3194+
name: object_without_lookahead
3195+
nodes:
3196+
resolver:
3197+
name: object_without_lookahead
3198+
page_info:
3199+
resolver:
3200+
name: object_without_lookahead
3201+
total_edge_count:
3202+
resolver:
3203+
name: object_without_lookahead
3204+
ComponentOwnerEdge:
3205+
elasticgraph_category: relay_edge
3206+
graphql_fields_by_name:
3207+
cursor:
3208+
resolver:
3209+
name: object_without_lookahead
3210+
node:
3211+
resolver:
3212+
name: object_without_lookahead
31383213
Country:
31393214
graphql_fields_by_name:
31403215
currency:
@@ -4083,6 +4158,27 @@ object_types_by_name:
40834158
options:
40844159
resolver:
40854160
name: get_record_field_value
4161+
owner:
4162+
name_in_index: owner_id
4163+
resolver:
4164+
config:
4165+
source_id_field: owner_id
4166+
exposed_id_field: token
4167+
name: apollo_entity_ref
4168+
owners:
4169+
name_in_index: owner_ids
4170+
resolver:
4171+
config:
4172+
source_ids_field: owner_ids
4173+
exposed_id_field: token
4174+
name: apollo_entity_ref_list
4175+
owners_paginated:
4176+
name_in_index: owner_ids
4177+
resolver:
4178+
config:
4179+
source_ids_field: owner_ids
4180+
exposed_id_field: token
4181+
name: apollo_entity_ref_paginated
40864182
part_aggregations:
40874183
relation:
40884184
direction: out

0 commit comments

Comments
 (0)