0
# Apollo Federation
1
2
Support for Apollo Federation allowing microservice architecture with federated GraphQL schemas.
3
4
## Capabilities
5
6
### Federated Types
7
8
```python { .api }
9
class FederatedObjectType(ObjectType):
10
"""Object type with Apollo Federation support."""
11
12
def __init__(self, name: str): ...
13
14
def reference_resolver(self, resolver_func: Callable):
15
"""Set entity reference resolver."""
16
17
class FederatedInterfaceType(InterfaceType):
18
"""Interface type with Apollo Federation support."""
19
20
def __init__(self, name: str): ...
21
22
def reference_resolver(self, resolver_func: Callable):
23
"""Set entity reference resolver."""
24
```
25
26
### Federated Schema
27
28
```python { .api }
29
def make_federated_schema(
30
type_defs: Union[str, list[str]],
31
*bindables,
32
**kwargs
33
) -> GraphQLSchema:
34
"""Create Apollo Federation-compatible schema."""
35
```
36
37
## Usage Examples
38
39
```python
40
from ariadne.contrib.federation import FederatedObjectType, make_federated_schema
41
42
type_defs = """
43
extend type User @key(fields: "id") {
44
id: ID! @external
45
posts: [Post!]!
46
}
47
"""
48
49
user_type = FederatedObjectType("User")
50
51
@user_type.reference_resolver
52
def resolve_user_reference(representation):
53
return get_user_by_id(representation["id"])
54
55
schema = make_federated_schema(type_defs, user_type)
56
```