Skip to content

Commit 43a0da5

Browse files
committed
Document Federation
1 parent 6c0c876 commit 43a0da5

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

.pictures/graphql_federation.png

240 KB
Loading

.pictures/graphql_netbox.png

138 KB
Loading

.pictures/graphql_wfo.png

178 KB
Loading

README.md

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ http://localhost:3000/
5353
```
5454

5555

56-
And to access `netbox` (admin/admin), point your browser to:
56+
To access `netbox` (admin/admin), point your browser to:
5757

5858
```
5959
http://localhost:8000/
6060
```
6161

62+
63+
To access `federation`, point your browser to:
64+
65+
```
66+
http://localhost:4000
67+
```
68+
6269
### Using the example orchestrator
6370

6471
Use the following steps to see the example orchestrator in action:
@@ -187,6 +194,8 @@ for the complete IP address administration and physical and logical
187194
network infrastructure. It has a REST based API that makes it easy to
188195
integrate with the Workflow Orchestrator.
189196

197+
The GraphQL APIs of WFO and NetBox support Federation[^8] through the GraphQL framework Strawberry[^9].
198+
190199
## Example orchestrator
191200

192201
To automate the administration and provisioning of the nodes, core
@@ -1363,6 +1372,112 @@ nodes.
13631372

13641373
<center><img src=".pictures/netbox_node_port_l2vpn.png" alt="Node, port and L2VPN type mapping" width=40% height=40%></center>
13651374

1375+
### Federation
1376+
1377+
WFO and NetBox both use the GraphQL framework Strawberry[^9] which supports Apollo Federation[^8]. This allows to expose both GraphQL backends as a single *supergraph*. WFO can be integrated with any other GraphQL backend that supports[^10] federation and of which you can modify the code. In case of NetBox we don't have direct control over the source code, so we patched it for purposes of demonstration.
1378+
1379+
#### Requirements
1380+
1381+
The following is required to facilitate GraphQL federation on top of WFO and other GraphQL backend(s):
1382+
1383+
* WFO must be configured with `FEDERATION_ENABLED=True`
1384+
* [`docker/orchestrator/orchestrator.env`](docker/orchestrator/orchestrator.env)
1385+
* The other backend must also enable federation
1386+
* NetBox: [`docker/netbox/Dockerfile`](docker/netbox/Dockerfile)
1387+
* In both backends set a federation key on the GraphQL types to join
1388+
* WFO: [`graphql_federation.py`](graphql_federation.py)
1389+
* NetBox: [`docker/netbox/patch_federation.py`](docker/netbox/patch_federation.py)
1390+
* Define the supergraph config with both backends
1391+
* [`docker/federation/supergraph-config.yaml`](docker/federation/supergraph-config.yaml)
1392+
* Compile the supergraph schema with rover[^12]
1393+
* `rover-compose` startup service in [`docker-compose.yml`](docker-compose.yml)
1394+
* Run Apollo Router to serve the supergraph
1395+
* `federation` service in [`docker-compose.yml`](docker-compose.yml)
1396+
1397+
For more information on federating new GraphQL types, or the existing WFO GraphQL types, please refer to our reference documentation[^11].
1398+
1399+
#### Example queries
1400+
1401+
The following queries assume a running docker-compose environment with 2 configured Nodes. We'll demonstrate how 2 separate GraphQL queries can now be performed in 1 federated query.
1402+
1403+
**NetBox**: NetBox device details can be queried from the NetBox GraphQL endpoint at http://localhost:8000/graphql/ (be sure to authenticate first with admin/admin)
1404+
1405+
```graphql
1406+
query GetNetboxDevices {
1407+
device_list {
1408+
id
1409+
name
1410+
device_type {
1411+
manufacturer {
1412+
name
1413+
}
1414+
}
1415+
site {
1416+
name
1417+
}
1418+
}
1419+
}
1420+
```
1421+
1422+
<img src=".pictures/graphql_netbox.png" alt="netbox query" width="75%" height="auto">
1423+
1424+
**WFO**: Node subscriptions can be queried from the WFO GraphQL endpoint at http://localhost:8080/api/graphql
1425+
1426+
```graphql
1427+
query GetSubscriptions {
1428+
subscriptions(filterBy:
1429+
{field: "product", value: "Node"}
1430+
) {
1431+
page {
1432+
... on NodeSubscription {
1433+
subscriptionId
1434+
description
1435+
node {
1436+
imsId
1437+
nodeName
1438+
}
1439+
}
1440+
}
1441+
}
1442+
}
1443+
```
1444+
1445+
<img src=".pictures/graphql_wfo.png" alt="wfo query" width="75%" height="auto">
1446+
1447+
**Federation**: Node subscriptions enriched with NetBox device details can be queried from the Federation endpoint at http://localhost:4000
1448+
1449+
```graphql
1450+
query GetEnrichedSubscriptions {
1451+
subscriptions(filterBy:
1452+
{field: "product", value: "Node"}
1453+
) {
1454+
page {
1455+
... on NodeSubscription {
1456+
subscriptionId
1457+
description
1458+
node {
1459+
imsId
1460+
nodeName
1461+
netboxDevice {
1462+
name
1463+
device_type {
1464+
manufacturer {
1465+
name
1466+
}
1467+
}
1468+
site {
1469+
name
1470+
}
1471+
}
1472+
}
1473+
}
1474+
}
1475+
}
1476+
}
1477+
```
1478+
1479+
<img src=".pictures/graphql_federation.png" alt="federated query" width="75%" height="auto">
1480+
13661481
## Glossary
13671482

13681483
<dl>
@@ -1404,3 +1519,13 @@ https://www.sqlalchemy.org
14041519
https://pydantic.dev/
14051520

14061521
[^7]: Pynetbox Python API - https://github.com/netbox-community/pynetbox
1522+
1523+
[^8]: Apollo Federation - https://www.apollographql.com/docs/federation/
1524+
1525+
[^9]: Strawberry Federation - https://strawberry.rocks/docs/federation/introduction
1526+
1527+
[^10]: Apollo Federation support - https://www.apollographql.com/docs/federation/building-supergraphs/supported-subgraphs
1528+
1529+
[^11]: WFO GraphQL Documentation - https://workfloworchestrator.org/orchestrator-core/reference-docs/graphql/
1530+
1531+
[^12]: Apollo Rover - https://www.apollographql.com/docs/rover/

0 commit comments

Comments
 (0)