Skip to content

Commit 432d982

Browse files
committed
Polishing federation section of the reference
See gh-922
1 parent b1cb364 commit 432d982

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

spring-graphql-docs/modules/ROOT/pages/federation.adoc

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,32 @@
33

44
Spring for GraphQL provides an integration for the
55
https://github.com/apollographql/federation-jvm[federation-jvm] library, which uses
6-
GraphQL Java to initialize the schema of a sub-graph within a federated graph.
6+
GraphQL Java to initialize the schema of a sub-graph within a graph of federated services.
77
See https://www.apollographql.com/docs/federation/[Apollo Federation] and the
8-
https://www.apollographql.com/docs/federation/subgraph-spec[Subgraph spec] for further details.
8+
https://www.apollographql.com/docs/federation/subgraph-spec[Subgraph specification] for details.
99

1010

1111

1212
[[federation.config]]
1313
== Config
1414

15-
To use the integration, declare a `FederationSchemaFactory` bean in your config, and plug
16-
it into `GraphQlSource.Builder`. For example, in a Spring Boot application:
15+
To enable the integration, declare a `FederationSchemaFactory` bean in your config, and plug
16+
it into `GraphQlSource.Builder`. For example, with Spring Boot:
1717

1818
[source,java,indent=0,subs="verbatim,quotes"]
1919
----
2020
@Configuration
2121
public class FederationConfig {
2222
23-
@Bean
24-
public FederationSchemaFactory schemaFactory() {
25-
return new FederationSchemaFactory();
26-
}
27-
2823
@Bean
2924
public GraphQlSourceBuilderCustomizer customizer(FederationSchemaFactory factory) {
3025
return builder -> builder.schemaFactory(factory::createGraphQLSchema);
3126
}
3227
28+
@Bean
29+
public FederationSchemaFactory schemaFactory() {
30+
return new FederationSchemaFactory();
31+
}
3332
}
3433
----
3534

@@ -53,9 +52,9 @@ type Author {
5352
[[federation.entity-mapping]]
5453
== `@EntityMapping`
5554

56-
To resolve federated types in response to the
57-
https://www.apollographql.com/docs/federation/subgraph-spec/#understanding-query_entities[_entities query],
58-
you can use `@EntityMapping` methods along with `@SchemaMapping` methods for types under the entity.
55+
An `@EntityMapping` method can load federated type instances in response to an
56+
https://www.apollographql.com/docs/federation/subgraph-spec/#understanding-query_entities[_entities query]
57+
from the federation gateway. For example:
5958

6059
For example:
6160

@@ -65,26 +64,27 @@ For example:
6564
private static class BookController {
6665
6766
@EntityMapping
68-
public Book book(@Argument int id) {
67+
public Book book(@Argument int id) { // <1>
6968
// ...
7069
}
7170
7271
@SchemaMapping
73-
public Author author(Book book) {
72+
public Author author(Book book) { // <2>
7473
// ...
7574
}
7675
7776
}
7877
----
7978

80-
The `@Argument` method parameters is resolved from the "representation" input map for
81-
the entity. You can also inject the full "representation" input `Map`. See
82-
xref:federation.adoc#federation.entity-mapping.signature[Method Signature] for all
83-
supported method argument and return value types.
79+
<1> The `@Argument` method parameter is resolved from the "representation" input map for
80+
the entity. The full "representation" input `Map` can also be resolved. See
81+
xref:federation.adoc#federation.entity-mapping.signature[Method Signature] for supported
82+
method argument and return value types.
83+
<2> `@SchemaMapping` methods can be used for the rest of the graph.
8484

85-
You can batch load federated entities by returning a `List` of instances from the controller
86-
method and accepting a `List` of argument values. In addition, you can use `@BatchMapping`
87-
methods for subfields.
85+
An `@EntityMapping` method can batch load federated entities of a given type. To do that,
86+
declare the `@Argument` method parameter as a list, and return the corresponding entity
87+
instances as a list in the same order.
8888

8989
For example:
9090

@@ -94,20 +94,21 @@ For example:
9494
private static class BookController {
9595
9696
@EntityMapping
97-
public List<Book> book(@Argument List<Integer> idList) {
98-
// ...
97+
public List<Book> book(@Argument List<Integer> idList) { // <1>
98+
// ... return books in the same order
9999
}
100100
101101
@BatchMapping
102-
public Map<Book, Author> author(List<Book> books) {
102+
public Map<Book, Author> author(List<Book> books) { // <2>
103103
// ...
104104
}
105105
}
106106
----
107107

108-
Note `idList` naming convention for the argument, which helps Spring for GraphQL to
109-
de-pluralize the method parameter name and derive the correct argument name to use.
110-
Alternatively, set the argument name through the annotation.
108+
<1> The `idList` naming convention helps to de-pluralize the parameter name in order to
109+
look up the correct value in the "representation" input map. You can also set the
110+
argument name through the annotation.
111+
<2> `@BatchMapping` methods can be used for the rest of the graph.
111112

112113

113114

0 commit comments

Comments
 (0)