You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-21Lines changed: 28 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,20 @@
1
-
# Apollo Federation for PHP
1
+
# Apollo Federation PHP
2
2
3
-
This package contains classes and utilities for [`webonyx/graphql-php`](https://github.com/webonyx/graphql-php) for creating GraphQL schemas following the Apollo Federation specification, allowing to create GraphQL microservices that can be combined into a single endpoint by tools like the Apollo Gateway.
3
+
This package provides classes and utilities for [`webonyx/graphql-php`](https://github.com/webonyx/graphql-php) for creating [federated GraphQL subgraphs](https://www.apollographql.com/docs/federation/#subgraph-schemas) in PHP to be consumed by the Apollo Gateway.
4
4
5
-
Please note this is still in active development and it might introduce breaking changes.
5
+
> ⚠️ **IMPORTANT:** This package is still in active development and it might introduce breaking changes.
An entity is a type that can be referenced by another service. Entities create connection points between services and form the basic building blocks of a federated graph. Entities have a primary key whose value uniquely identifies a specific instance of the type, similar to the function of a primary key in a SQL table.
15
+
### Entities
15
16
16
-
Creating an entity is done via the `EntityObjectType`and it takes the same configuration as the default `ObjectType`in addition of a `keyFields` and `__resolveReference` configuration properties.
17
+
An entity is an object type that you define canonically in one subgraph and can then reference and extend in other subgraphs. It can be defined via the `EntityObjectType`which takes the same configuration as the default `ObjectType`plus a `keyFields` and `__resolveReference` properties.
17
18
18
19
```php
19
20
use Apollo\Federation\Types\EntityObjectType;
@@ -27,21 +28,21 @@ $userType = new EntityObjectType([
27
28
'firstName' => ['type' => Type::string()],
28
29
'lastName' => ['type' => Type::string()]
29
30
],
30
-
'__resolveReference' => function ($ref) {
31
-
// .. fetch data from the db.
31
+
'__resolveReference' => static function ($ref) {
32
+
// .. fetch from a data source.
32
33
}
33
34
]);
34
35
```
35
36
36
-
*`keyFields` — determine which fields serve as the unique identifier of the entity.
37
+
*`keyFields` — defines the entity's primary key, which consists of one or more of the type's. An entity's key cannot include fields that return a union or interface.
37
38
38
-
*`__resolveReference` — reference resolvers are a special addition to Apollo Server that allow individual types to be resolved by a reference from another service. They are called when a query references an entity across service boundaries. To learn more about `__resolveReference`, see the [API docs](https://www.apollographql.com/docs/apollo-server/api/apollo-federation).
39
+
*`__resolveReference` — resolves the representation of the entity from the provided reference. Subgraphs use representations to reference entities from other subgraphs. A representation requires only an explicit __typename definition and values for the entity's primary key fields.
39
40
40
-
### Entity reference types
41
+
For more detail on entities, [see the official docs.](https://www.apollographql.com/docs/federation/entities)
41
42
42
-
An entity reference is a type that refers to an entity on another service and only contain enough data so the Apollo Gateway can resolve it, typically the keys.
43
+
### Entity references
43
44
44
-
Creating an entity reference is done via the `EntityRefObjectType`and takes the same configuration values as the base `EntityObjectType` class.
45
+
A subgraph can reference entities from another subgraph by defining a stub including just enough information to know how to interact with the referenced entity. Entity references are created via the `EntityRefObjectType`which takes the same configuration as the base `EntityObjectType`.
45
46
46
47
```php
47
48
use Apollo\Federation\Types\EntityRefObjectType;
@@ -56,9 +57,11 @@ $userType = new EntityRefObjectType([
56
57
]);
57
58
```
58
59
59
-
### Type fields
60
+
For more detail on entity references, [see the official docs.](https://www.apollographql.com/docs/federation/entities/#referencing)
61
+
62
+
### Extending
60
63
61
-
In addition to creating entities and references, fields in object types can be configured with Apollo Federation-specific settings. [Refer to the docs for more info](https://www.apollographql.com/docs/apollo-server/federation/federation-spec).
64
+
A subgraph can add fields to an entity that's defined in another subgraph. This is called extending the entity. When a subgraph extends an entity, the entity's originating subgraph is not aware of the added fields. Only the extending subgraph (along with the gateway) knows about these fields.
62
65
63
66
```php
64
67
use Apollo\Federation\Types\EntityRefObjectType;
@@ -79,13 +82,13 @@ $userType = new EntityRefObjectType([
79
82
]);
80
83
```
81
84
82
-
The following are all the configuration settings supported (click on each one to see the docs.)
85
+
The subgraph can extend using the following configuration properties:
83
86
84
-
***[`isExternal`](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#external) —** marks a field as owned by another service.
87
+
***[`isExternal`](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#external) —** marks a field as owned by another service. This allows service A to use fields from service B while also knowing at runtime the types of that field.
85
88
86
-
***[`provides`](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#provides) —**annotates the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the gateway.
89
+
***[`provides`](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#provides) —**used to annotate the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the gateway.
87
90
88
-
***[`requires`](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#requires) —**annotates the required input fieldset from a base type for a resolver. It is used to develop a query plan where the required fields may not be needed by the client, but the service may need additional information from other services.
91
+
***[`requires`](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#requires) —**used to annotate the required input fieldset from a base type for a resolver. It is used to develop a query plan where the required fields may not be needed by the client, but the service may need additional information from other services.
Documentation in this project include content quoted directly from the [Apollo official documentation](https://www.apollographql.com/docs) to reduce redundancy.
0 commit comments