Skip to content

Commit c4c7ffa

Browse files
committed
Improved documentation
1 parent 97f0285 commit c4c7ffa

File tree

6 files changed

+524
-13
lines changed

6 files changed

+524
-13
lines changed

Diff for: README.md

+39-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,58 @@
11
# php.demo.api.graphql.slim
2-
Just a DEMO API built around SLIM framework and GraphQL-PHP
32

4-
## Work in progress
3+
This project is a demo project aimed to demonstrate a slightly more advanced implementation of GraphQL in PHP than your average demo tutorial, yet still easy to understand. Featuring multi-endpoints, dynamic types, query and mutation, and APQ, a performent caching mecanism for queries.
4+
5+
## :construction: Work in progress
6+
7+
This is a work in progress still in its early stage of infancy. Ultimately, the purpose of this project is educational and hopefully will evolve to adhere to the most relevant best practices available.
8+
9+
I've got a NodeJS implementation already in the pipe, buty will come out later since it was a practical case and not oriented toward an educational purpose.
10+
11+
## :star: Starring:
12+
13+
* [SLIM Framework](https://www.slimframework.com/)
14+
* [Symfony Cache](https://symfony.com/doc/current/components/cache.html) ([PSR-6](https://symfony.com/doc/current/components/cache.html#basic-usage-psr-6), [Redis](https://symfony.com/doc/current/components/cache/adapters/redis_adapter.html))
15+
* [GraphQL-PHP](https://webonyx.github.io/graphql-php)
16+
* [GraphQL Automatic Persisted Queries](https://www.apollographql.com/docs/apollo-server/performance/apq/)
17+
18+
## Documentations
19+
20+
### Transverse
21+
22+
* [Coding Standards](./docs/CodingStandards.md) : Read more about today's more favored Coding style.
23+
* [GraphQL](./docs/GraphQL.md) : General purpose doc about GQL.
24+
25+
### Classes
26+
27+
* [CacheManager](./docs/CacheManager.md) : For every memoization needs, via Redis persistent connection.
28+
* [SchemaLoader](./docs/SchemaLoader.md) : Automatically find and load php files related to graphql type definition into a coherent GraphQL Schema.
29+
* [Endpoint](./docs/Endpoint.md) : Allows for quick endpoint creation using various schema compositions.
30+
* APQ: @TODO
31+
* Auth: @TODO
32+
33+
## GraphQL
34+
35+
### Endpoints
36+
37+
* `http://127.0.0.1:9632`
38+
* `/graphql/blog` The 'blog' api endpoint and schema.
39+
* `/graphql/refs` Another 'refs' api endpoint with another schema
540

641

742
## Docker
843

944
From the project main directory:
1045

11-
(on windows, you may want to use `winpty` before `docker exec ...`)
12-
1346

1447
```bash
1548
docker-compose build
16-
docker-compose run
1749
docker-compose up -d
1850
docker-compose down
1951
```
2052

2153
Connect to container as CLI (optional)
54+
2255
```bash
56+
# on windows, you may want to consider using the `winpty` command before `docker exec`)
2357
docker exec -ti gql_slim_api sh
2458
```
25-
26-
27-
## GraphQL
28-
29-
### Endpoints
30-
31-
* `/graphql/blog` The 'blog' api endpoint and schema.
32-
* `/graphql/refs` Another 'refs' api endpoint with another schema

Diff for: docs/CacheManager.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Cache Manager
2+
3+
## Namespace
4+
5+
`App\GraphQL\Boilerplate\CacheManager`
6+
7+
## Description
8+
9+
This class is an utility giving the developer an actionnable API to interract with a performent caching mecanism like Redis.
10+
11+
The basic use will be to store key/value pairs with a Time To Live (TTL) expiration time.
12+
13+
## Usages
14+
15+
### With Symfony Contracts
16+
17+
* [Read more](https://symfony.com/doc/current/components/cache.html#cache-contracts)
18+
19+
```php
20+
use App\GraphQL\Boilerplate\CacheManager;
21+
$memoization = CacheManager::getInstance();
22+
$value = $memoization->get('FOO', function (\Symfony\Contracts\Cache\ItemInterface $item) {
23+
$item->expiresAfter(10); //seconds
24+
return 'BAR';
25+
});
26+
```
27+
28+
### Without Symfony Contracts (pure PSR-6)
29+
30+
* [Read more](https://symfony.com/doc/current/components/cache.html#generic-caching-psr-6)
31+
32+
```php
33+
$memoization = CacheManager::getInstance();
34+
$foo = $memoization->getItem('FOO');
35+
if (!$foo->isHit()) {
36+
// foo item does not exist in the cache
37+
$foo->set('BAR')->expiresAfter(10);
38+
$memoization->save($foo);
39+
}
40+
// retrieve the value stored by the item
41+
$value = $foo->get();
42+
```
43+
44+
> TODO: Improving this section of documentation with more detailled and explained use cases.
45+
46+
----
47+
* Back to [README](../README.md)

Diff for: docs/CodingStandards.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Coding Standards
2+
3+
The aim is to follow most of [PSR-12 "Extended Coding Style"](https://www.php-fig.org/psr/psr-12/), as well as [Symfony Coding Standards](https://symfony.com/doc/current/contributing/code/standards.html#symfony-coding-standards-in-detail).
4+
5+
> TODO: Work in Progress: PHP-CS Will be used with the developer's IDE as a code linter/fixer
6+
7+
8+
## Some other practices should be observed
9+
10+
11+
### Equals / Identical comparison
12+
13+
Whenever possible, we SHOULD refrain from using the “equal `==`” operator and use the “Identical `===`” operator instead.
14+
15+
16+
* Equal: `$a == $b` is `true` if `$a` is equal to `$b`, after type juggling. bad practice
17+
* Identical: `$a === $b` is `true` if `$a` is equal to `$b`, and they are of the same type.
18+
19+
[Read more about PHP comparison operators](https://www.php.net/manual/en/language.operators.comparison.php).
20+
21+
22+
### Variable and object instance name
23+
24+
We MUST always refrain from prefixing a variable name with its type.
25+
26+
bad:
27+
```php
28+
$str_c = ‘red’;
29+
$o_myobject = new Car(‘toyota’);
30+
$int_iTab = 0;
31+
```
32+
33+
good:
34+
```php
35+
$color = ‘red’;
36+
$toyotaCar = new Car(‘toyota’);
37+
$tabIndex = 0;
38+
```
39+
40+
When a variable represents an object's Class, it is RECOMMENDED to have PascalCase used. The first letter SHOULD be in uppercase to indicate a complex structure and not a simple scalar value. i.e: `FlyingMachine`
41+
42+
To have a seamless experience reading the code, it is REQUIRED to ease the reading by using variable and constant names that are intuitive and speaking for themselves.
43+
44+
Acronyms should retain their capital letters when placed at the end of a variable’s name:
45+
```php
46+
$lastUpdatedDateUTC = ...
47+
$isAgencyCIA = false;
48+
```
49+
50+
Boolean constant and variables MUST start with ‘is’, ‘has’, ‘had’, ‘was’, ‘were’:
51+
```php
52+
$isBlue = true;
53+
$wasUpdatedLastWeek = true;
54+
$hasAlreadyPaidOnce = true;
55+
$wereBulkImported = false;
56+
```
57+
58+
### Date, DateTimes and TimeZones
59+
60+
NEVER rely on the default value for the default timezone as it can be changed in php files, php config files, and always fallback to the server’s OS config. Depending on where your code is deployed (server locale), and your level of config optimisation, relying on a default timezone will result in inconsistencies with your saved dates in database and server side logic.
61+
62+
All dates MUST be stored and manipulated as from the UTC timezone.
63+
UTC dates SHOULD only be converted to a local date format upon being displayed for a specific user.
64+
65+
```php
66+
$nowUTC = new \DateTime('now', new \DateTimeZone('UTC'));
67+
$nowFR = clone($nowUTC);
68+
$nowFR->setTimezone(new \DateTimeZone('Europe/Paris'));
69+
echo $nowFR->format(\DateTimeInterface::ISO8601);
70+
```
71+
72+
Dates instantiated from a static source like a database fetch, SHOULD be instances of \DateTimeImmutable
73+
74+
75+
### End of file
76+
77+
Each code file must end with an empty new line and not include a closing php tag `?>`
78+
79+
----
80+
* Back to [README](../README.md)

Diff for: docs/Endpoint.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Endpoint
2+
3+
## Namespace
4+
5+
`App\GraphQL\Boilerplate\Endpoint`
6+
7+
## Description
8+
9+
This class is an utility giving the developer an actionnable API to create a graphql-php schema resolving endpoint.
10+
It was built to wrap-up the common code required to resolve a Schema and interact with a [PSR-7](https://www.php-fig.org/psr/psr-7/) compatible Response.
11+
12+
It can be easily integrated with an MVC application featuring Controllers like SLIM and Symfony, but is quite easy to adapt to any kind of application.
13+
14+
## Usages
15+
16+
* Inspect [App\Controller\GraphqlController](../app/src/Controller/GraphqlController.php)
17+
18+
>TODO: Improve this section of the documentation. ( :construction: WiP )
19+
20+
```php
21+
$endpoint = new Endpoint();
22+
$endpoint->executeSchema($SchemaOptions);
23+
```
24+
25+
----
26+
* Back to [README](../README.md)

0 commit comments

Comments
 (0)