-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9263b23
Showing
33 changed files
with
1,093 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
|
||
[*.{php,php}] | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[*.neon] | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[composer.json] | ||
indent_style = tab | ||
indent_size = 4 |
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,4 @@ | ||
log/* | ||
vendor/* | ||
!.gitignore | ||
composer.lock |
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,6 @@ | ||
tools: | ||
external_code_coverage: true | ||
|
||
checks: | ||
php: | ||
code_rating: true |
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,34 @@ | ||
language: php | ||
|
||
sudo: false | ||
|
||
php: | ||
- 7.1 | ||
|
||
matrix: | ||
include: | ||
- php: 7.1 | ||
env: PHPUNIT_FLAGS="--coverage-clover=coverage.xml" CHECK_CS=false | ||
|
||
install: | ||
# install composer dependencies | ||
- composer install --prefer-source | ||
|
||
script: | ||
# run tests | ||
- vendor/bin/phpunit $PHPUNIT_FLAGS | ||
# check coding standard (defined in composer.json "scripts" section) | ||
#- if [[ "$CHECK_CS" != "" ]]; then composer check-cs; fi | ||
|
||
after_script: | ||
# upload coverage.xml file to Scrutinizer to analyze it | ||
- | | ||
if [[ "$PHPUNIT_FLAGS" != "" ]]; then | ||
wget https://scrutinizer-ci.com/ocular.phar | ||
php ocular.phar code-coverage:upload --format=php-clover coverage.xml | ||
fi | ||
# do not send success notifications, they have no value | ||
notifications: | ||
email: | ||
on_success: never |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017-2018 Tomáš Pilař | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,10 @@ | ||
# GraphQL | ||
|
||
[![Build Status](https://img.shields.io/travis/portiny/graphql.svg?style=flat-square)](https://travis-ci.org/portiny/graphql) | ||
[![Quality Score](https://img.shields.io/scrutinizer/g/portiny/graphql.svg?style=flat-square)](https://scrutinizer-ci.com/g/portiny/graphql) | ||
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/portiny/graphql.svg?style=flat-square)](https://scrutinizer-ci.com/g/portiny/graphql) | ||
[![Downloads this Month](https://img.shields.io/packagist/dt/portiny/graphql.svg?style=flat-square)](https://packagist.org/packages/portiny/graphql) | ||
[![Latest stable](https://img.shields.io/github/release/portiny/graphql.svg?style=flat-square)](https://packagist.org/packages/portiny/graphql) | ||
|
||
Lightweight GraphQL integration extension for Nette framework. | ||
|
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,27 @@ | ||
{ | ||
"name": "portiny/graphql", | ||
"description": "Lightweight GraphQL integration extension for Nette framework.", | ||
"license": ["MIT"], | ||
"require": { | ||
"php": "~7.1", | ||
"nette/http": "^2.4", | ||
"nette/utils": "^2.4", | ||
"tracy/tracy": "^2.4", | ||
"webonyx/graphql-php": "^0.11" | ||
}, | ||
"require-dev": { | ||
"nette/di": "^2.4", | ||
"nette/bootstrap": "^2.4", | ||
"phpunit/phpunit": "^6.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Portiny\\GraphQL\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Portiny\\GraphQL\\Tests\\": "tests" | ||
} | ||
} | ||
} |
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,15 @@ | ||
<phpunit | ||
bootstrap="tests/bootstrap.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,85 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Portiny\GraphQL\Adapter\Nette\DI; | ||
|
||
use Nette\DI\Compiler; | ||
use Nette\DI\CompilerExtension; | ||
use Portiny\GraphQL\Contract\Field\QueryFieldInterface; | ||
use Portiny\GraphQL\Contract\Mutation\MutationFieldInterface; | ||
use Portiny\GraphQL\Contract\Provider\MutationFieldsProviderInterface; | ||
use Portiny\GraphQL\Contract\Provider\QueryFieldsProviderInterface; | ||
use Portiny\GraphQL\GraphQLProcessor; | ||
use Portiny\GraphQL\Provider\MutationFieldsProvider; | ||
use Portiny\GraphQL\Provider\QueryFieldsProvider; | ||
|
||
|
||
final class GraphQLExtension extends CompilerExtension | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function loadConfiguration() | ||
{ | ||
$builder = $this->getContainerBuilder(); | ||
$config = $this->loadFromFile(__DIR__ . '/../config/config.neon'); | ||
Compiler::loadDefinitions($builder, $config['services'] ?: []); | ||
} | ||
|
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function beforeCompile() | ||
{ | ||
$this->setupMutationFieldProvider(); | ||
$this->setupQueryFieldProvider(); | ||
$this->setupGraphQLProcessor(); | ||
} | ||
|
||
|
||
private function setupMutationFieldProvider() | ||
{ | ||
$containerBuilder = $this->getContainerBuilder(); | ||
|
||
$mutationFieldProvider = $containerBuilder->addDefinition($this->prefix('mutationFieldsProvider')) | ||
->setFactory(MutationFieldsProvider::class) | ||
->setType(MutationFieldsProviderInterface::class) | ||
->setInject(FALSE); | ||
|
||
$mutationFieldDefinitions = $containerBuilder->findByType(MutationFieldInterface::class); | ||
foreach ($mutationFieldDefinitions as $mutationFieldDefinition) { | ||
$mutationFieldProvider->addSetup('addField', ['@' . $mutationFieldDefinition->getType()]); | ||
} | ||
} | ||
|
||
|
||
private function setupQueryFieldProvider() | ||
{ | ||
$containerBuilder = $this->getContainerBuilder(); | ||
|
||
$queryFieldProvider = $containerBuilder->addDefinition($this->prefix('queryFieldsProvider')) | ||
->setFactory(QueryFieldsProvider::class) | ||
->setType(QueryFieldsProviderInterface::class) | ||
->setInject(FALSE); | ||
|
||
$queryFieldDefinitions = $containerBuilder->findByType(QueryFieldInterface::class); | ||
foreach ($queryFieldDefinitions as $queryFieldDefinition) { | ||
$queryFieldProvider->addSetup('addField', ['@' . $queryFieldDefinition->getType()]); | ||
} | ||
} | ||
|
||
|
||
private function setupGraphQLProcessor() | ||
{ | ||
$containerBuilder = $this->getContainerBuilder(); | ||
|
||
$containerBuilder->addDefinition($this->prefix('graphQLProcessor')) | ||
->setFactory(GraphQLProcessor::class) | ||
->addSetup('setMutationFieldsProvider', ['@' . MutationFieldsProviderInterface::class]) | ||
->addSetup('setQueryFieldsProvider', ['@' . QueryFieldsProviderInterface::class]); | ||
} | ||
|
||
} |
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,2 @@ | ||
services: | ||
- Portiny\GraphQL\Http\Request\JsonRequestParser |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Portiny\GraphQL\Contract\Field; | ||
|
||
use GraphQL\Type\Definition\Type; | ||
|
||
|
||
interface QueryFieldInterface | ||
{ | ||
|
||
/** | ||
* @return string | ||
*/ | ||
function getName(): string; | ||
|
||
|
||
function getType(): Type; | ||
|
||
|
||
function getDescription(): string; | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
function getArgs(): array; | ||
|
||
|
||
/** | ||
* @param array $root | ||
* @param array $args | ||
* @param mixed|NULL $context | ||
* @return mixed | ||
*/ | ||
function resolve(array $root, array $args, $context = NULL); | ||
|
||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Portiny\GraphQL\Contract\Http\Request; | ||
|
||
|
||
interface RequestParserInterface | ||
{ | ||
|
||
function getQuery(): string; | ||
|
||
|
||
function getVariables(): array; | ||
|
||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Portiny\GraphQL\Contract\Mutation; | ||
|
||
|
||
use GraphQL\Type\Definition\Type; | ||
|
||
|
||
interface MutationFieldInterface | ||
{ | ||
|
||
function getName(): string; | ||
|
||
|
||
function getType(): Type; | ||
|
||
|
||
function getDescription(): string; | ||
|
||
|
||
function getArgs(): array; | ||
|
||
|
||
/** | ||
* @param array $root | ||
* @param array $args | ||
* @param mixed|NULL $context | ||
* @return mixed | ||
*/ | ||
function resolve(array $root, array $args, $context = NULL); | ||
|
||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Portiny\GraphQL\Contract\Provider; | ||
|
||
use Portiny\GraphQL\Contract\Mutation\MutationFieldInterface; | ||
use Portiny\GraphQL\Exception\Provider\ExistingMutationFieldException; | ||
|
||
|
||
interface MutationFieldsProviderInterface | ||
{ | ||
|
||
/** | ||
* @throws ExistingMutationFieldException | ||
*/ | ||
function addField(MutationFieldInterface $mutationField); | ||
|
||
|
||
/** | ||
* @return MutationFieldInterface[] | ||
*/ | ||
function getFields(): array; | ||
|
||
|
||
function convertFieldsToArray(array $allowedMutations = NULL): array; | ||
|
||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Portiny\GraphQL\Contract\Provider; | ||
|
||
use Portiny\GraphQL\Contract\Field\QueryFieldInterface; | ||
use Portiny\GraphQL\Exception\Provider\ExistingQueryFieldException; | ||
|
||
|
||
interface QueryFieldsProviderInterface | ||
{ | ||
|
||
/** | ||
* @throws ExistingQueryFieldException | ||
*/ | ||
function addField(QueryFieldInterface $queryField); | ||
|
||
|
||
/** | ||
* @return QueryFieldInterface[] | ||
*/ | ||
function getFields(): array; | ||
|
||
|
||
function convertFieldsToArray(array $allowedQueries = NULL): array; | ||
|
||
} |
Oops, something went wrong.