Skip to content

Commit 61772cc

Browse files
authored
chore: Update licence and docs (#21)
* chore: OS licensing and docs update * chore: Fix version * chore: Remove version * chore: Fix composer lock * fix: Revert composer files * chore: Upgrade graphql-php
1 parent 06b62ae commit 61772cc

File tree

5 files changed

+65
-30
lines changed

5 files changed

+65
-30
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Skillshare
3+
Copyright (c) 2019-present Skillshare
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
# Apollo Federation for PHP
1+
# Apollo Federation PHP
22

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.
44

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.
66
77
## Usage
88

9-
To install latest package release:
10-
`composer require skillshare/apollo-federation-php:dev-master#a277025082eaa72a8b043106f64ebe8d2610be79`
9+
Via composer:
1110

12-
### Entity types
11+
```
12+
composer require skillshare/apollo-federation-php
13+
```
1314

14-
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
1516

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.
1718

1819
```php
1920
use Apollo\Federation\Types\EntityObjectType;
@@ -27,21 +28,21 @@ $userType = new EntityObjectType([
2728
'firstName' => ['type' => Type::string()],
2829
'lastName' => ['type' => Type::string()]
2930
],
30-
'__resolveReference' => function ($ref) {
31-
// .. fetch data from the db.
31+
'__resolveReference' => static function ($ref) {
32+
// .. fetch from a data source.
3233
}
3334
]);
3435
```
3536

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.
3738

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.
3940

40-
### Entity reference types
41+
For more detail on entities, [see the official docs.](https://www.apollographql.com/docs/federation/entities)
4142

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
4344

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`.
4546

4647
```php
4748
use Apollo\Federation\Types\EntityRefObjectType;
@@ -56,9 +57,11 @@ $userType = new EntityRefObjectType([
5657
]);
5758
```
5859

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
6063

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.
6265

6366
```php
6467
use Apollo\Federation\Types\EntityRefObjectType;
@@ -79,13 +82,13 @@ $userType = new EntityRefObjectType([
7982
]);
8083
```
8184

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:
8386

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.
8588

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.
8790

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.
8992

9093
### Federated schema
9194

@@ -101,3 +104,7 @@ $query = 'query GetServiceSDL { _service { sdl } }';
101104

102105
$result = GraphQL::executeQuery($schema, $query);
103106
```
107+
108+
## Disclaimer
109+
110+
Documentation in this project include content quoted directly from the [Apollo official documentation](https://www.apollographql.com/docs) to reduce redundancy.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "skillshare/apollo-federation-php",
3-
"description": "A PHP port of Apollo Federation",
3+
"description": "A PHP port of the Apollo Federation specification.",
44
"type": "library",
55
"license": "MIT",
66
"require": {

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Utils/FederatedSchemaPrinter.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
<?php
22

3+
/**
4+
*
5+
* This source file includes modified code from webonyx/graphql-php.
6+
*
7+
* Copyright (c) 2015-present, Webonyx, LLC.
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in all
17+
* copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
* SOFTWARE.
26+
*
27+
* @copyright Copyright (c) Webonyx, LLC.
28+
* @license https://opensource.org/licenses/MIT MIT License
29+
*/
30+
331
declare(strict_types=1);
432

533
namespace Apollo\Federation\Utils;

0 commit comments

Comments
 (0)