-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from TomHAnderson/feature/documenatation-provider
Feature/documentation provider
- Loading branch information
Showing
16 changed files
with
233 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
GraphiQL and Documentation | ||
========================== | ||
|
||
Support for GraphiQL was added in v1.0.5 along with support for introspection queries. | ||
|
||
The documentation for each field is created with a DocumentationProvider. Included | ||
with zf-doctrine-graphql is an ApigilityDocumentationProvider. If you have need for | ||
another form of documentation provider please create an issue on github. The more | ||
included providers the merrier. | ||
|
||
|
||
|
||
.. role:: raw-html(raw) | ||
:format: html | ||
|
||
.. note:: | ||
Authored by `API Skeletons <https://apiskeletons.com>`_. All rights reserved. | ||
|
||
|
||
:raw-html:`<script async src="https://www.googletagmanager.com/gtag/js?id=UA-64198835-4"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'UA-64198835-4');</script>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace ZF\Doctrine\GraphQL\Documentation; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class ApigilityDocumentationProvider implements | ||
DocumentationProviderInterface | ||
{ | ||
protected $config; | ||
|
||
public function __construct(array $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
public function getEntity($entityName, array $options) | ||
{ | ||
// Documentation for entities is stored in the documentation.php config file. | ||
// Fetching all those files is outside the scope of work for this class for now. | ||
return 'Doctrine Entity ' . $entityName; | ||
} | ||
|
||
/** | ||
* Populate the field documentation based on teh input filter | ||
* for the first matching entity found in zf-rest configuration | ||
*/ | ||
public function getField($entityName, $fieldName, array $options) | ||
{ | ||
$inputFilter = null; | ||
$description = null; | ||
|
||
if (! isset($this->config['zf-rest'])) { | ||
return null; | ||
} | ||
|
||
foreach ($this->config['zf-rest'] as $controllerName => $restConfig) { | ||
if ($restConfig['entity_class'] == $entityName) { | ||
$inputFilter = $this->config['zf-content-validation'][$controllerName]['input_filter'] ?? null; | ||
break; | ||
} | ||
} | ||
|
||
if ($inputFilter | ||
&& isset($this->config['input_filter_specs']) | ||
&& isset($this->config['input_filter_specs'][$inputFilter])) { | ||
foreach ($this->config['input_filter_specs'][$inputFilter] as $fieldConfig) { | ||
if ($fieldConfig['name'] == $fieldName) { | ||
$description = $fieldConfig['description'] ?? null; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return $description; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Documentation/ApigilityDocumentationProviderFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace ZF\Doctrine\GraphQL\Documentation; | ||
|
||
use Interop\Container\ContainerInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class ApigilityDocumentationProviderFactory | ||
{ | ||
public function __invoke( | ||
ContainerInterface $container, | ||
$requestedName, | ||
array $options = null | ||
) { | ||
$config = $container->get('config'); | ||
|
||
return new ApigilityDocumentationProvider($config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace ZF\Doctrine\GraphQL\Documentation; | ||
|
||
interface DocumentationProviderInterface | ||
{ | ||
public function getField($entityClassName, $fieldName, array $config); | ||
public function getEntity($entityClassName, array $config); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Documentation/HydratorConfigurationDocumentationProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace ZF\Doctrine\GraphQL\Documentation; | ||
|
||
class HydratorConfigurationDocumentationProvider implements | ||
DocumentationProviderInterface | ||
{ | ||
protected $config; | ||
|
||
public function __construct(array $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
public function getEntity($entityClassName, array $options) | ||
{ | ||
$hydratorAlias = 'ZF\\Doctrine\\GraphQL\\Hydrator\\' . str_replace('\\', '_', $entityClassName); | ||
$config = $this->config['zf-doctrine-graphql-hydrator'][$hydratorAlias][$options['hydrator_section']] ?? null; | ||
|
||
return $config['documentation']['_entity'] ?? null; | ||
} | ||
|
||
public function getField($entityClassName, $fieldName, array $options) | ||
{ | ||
$hydratorAlias = 'ZF\\Doctrine\\GraphQL\\Hydrator\\' . str_replace('\\', '_', $entityClassName); | ||
$config = $this->config['zf-doctrine-graphql-hydrator'][$hydratorAlias][$options['hydrator_section']] ?? null; | ||
|
||
return $config['documentation'][$fieldName] ?? null; | ||
} | ||
} |
Oops, something went wrong.