Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasPilar committed Dec 7, 2017
0 parents commit 9263b23
Show file tree
Hide file tree
Showing 33 changed files with 1,093 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
log/*
vendor/*
!.gitignore
composer.lock
6 changes: 6 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tools:
external_code_coverage: true

checks:
php:
code_rating: true
34 changes: 34 additions & 0 deletions .travis.yml
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
21 changes: 21 additions & 0 deletions LICENSE
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.
10 changes: 10 additions & 0 deletions README.md
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.

27 changes: 27 additions & 0 deletions composer.json
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"
}
}
}
15 changes: 15 additions & 0 deletions phpunit.xml
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>
85 changes: 85 additions & 0 deletions src/Adapter/Nette/DI/GraphQLExtension.php
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]);
}

}
2 changes: 2 additions & 0 deletions src/Adapter/Nette/config/config.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
services:
- Portiny\GraphQL\Http\Request\JsonRequestParser
39 changes: 39 additions & 0 deletions src/Contract/Field/QueryFieldInterface.php
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);

}
16 changes: 16 additions & 0 deletions src/Contract/Http/Request/RequestParserInterface.php
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;

}
34 changes: 34 additions & 0 deletions src/Contract/Mutation/MutationFieldInterface.php
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);

}
28 changes: 28 additions & 0 deletions src/Contract/Provider/MutationFieldsProviderInterface.php
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;

}
28 changes: 28 additions & 0 deletions src/Contract/Provider/QueryFieldsProviderInterface.php
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;

}
Loading

0 comments on commit 9263b23

Please sign in to comment.