1
1
[[federation]]
2
2
= Federation
3
3
4
- Spring for GraphQL provides a small integration layer for the
5
- https://github.com/apollographql/federation-jvm[federation-jvm] library that in turn builds
6
- on GraphQL Java, and helps to initialize the `graphql.schema.GraphQLSchema` for a GraphQL
7
- Java application that is a sub-graph within a federated graph. For more details, see
8
- https://www.apollographql.com/docs/federation/[Apollo Federation] and the
9
- https://www.apollographql.com/docs/federation/subgraph-spec[Subgraph spec].
4
+ Spring for GraphQL provides an integration for the
5
+ 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.
7
+ 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.
10
9
11
- To use the support you can declare a `FederationSchemaFactory` bean in your config, and plug
12
- it into `GraphQlSource.Builder`. In a Spring Boot application you can do this through a
13
- `GraphQlSourceBuilderCustomizer` as follows:
10
+
11
+
12
+ [[federation.config]]
13
+ == Config
14
+
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:
14
17
15
18
[source,java,indent=0,subs="verbatim,quotes"]
16
19
----
@@ -30,7 +33,7 @@ it into `GraphQlSource.Builder`. In a Spring Boot application you can do this th
30
33
}
31
34
----
32
35
33
- Now your sub-graph schema can extend federated types:
36
+ Now the schema for the sub-graph service can extend federated types:
34
37
35
38
[source,graphql,indent=0,subs="verbatim,quotes"]
36
39
----
@@ -46,10 +49,15 @@ type Author {
46
49
}
47
50
----
48
51
49
- To assist with resolving federated types as part of an
50
- https://www.apollographql.com/docs/federation/subgraph-spec/#understanding-query_entities[_entities]
51
- query, you can use `@EntityMapping` methods side by side with `@SchemaMapping` methods
52
- for the data that the subgraph application owns. For example:
52
+
53
+ [[federation.entity-mapping]]
54
+ == `@EntityMapping`
55
+
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.
59
+
60
+ For example:
53
61
54
62
[source,java,indent=0,subs="verbatim,quotes"]
55
63
----
@@ -69,8 +77,14 @@ for the data that the subgraph application owns. For example:
69
77
}
70
78
----
71
79
72
- The `@Argument` method parameters is resolved from the "representation"input map for the entity.
73
- You can also inject the full `Map<String, Object>`. The below shows all supported arguments:
80
+ The `@Argument` method parameters is resolved from the "representation" input map for the entity.
81
+ You can also inject the full "representation" input `Map`.
82
+
83
+
84
+ [[federation.entity-mapping.signature]]
85
+ === Method Signature
86
+
87
+ Entity mapping methods support the following arguments:
74
88
75
89
[cols="1,2"]
76
90
|===
@@ -110,6 +124,10 @@ You can also inject the full `Map<String, Object>`. The below shows all supporte
110
124
111
125
`@EntityMapping` methods can return `Mono`, `CompletableFuture`, `Callable`, or the actual entity.
112
126
127
+
128
+ [[federation.entity-mapping.exception-handling]]
129
+ === Exception Handling
130
+
113
131
You can use `@GraphQlExceptionHandler` methods to map exceptions from `@EntityMapping`
114
132
methods to ``GraphQLError``'s. The errors will be included in the response of the
115
133
"_entities" query. Exception handler methods can be in the same controller or in an
0 commit comments