Skip to content

Commit

Permalink
Merge branch 'master' into wrong_type_return
Browse files Browse the repository at this point in the history
  • Loading branch information
mfn committed Nov 30, 2019
2 parents 36f4ff4 + 0f56fe3 commit 0a6e0e8
Show file tree
Hide file tree
Showing 44 changed files with 834 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/3_Support_question.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ labels: question

---
<!--
Alternative you can also use our Slack workspace: https://join.slack.com/t/rebing-graphql/shared_invite/enQtNTE5NjQzNDI5MzQ4LWVjMTMxNzIyZjBlNTFhZGQ5MDVjZDAwZDNjODA3ODE2NjdiOGJkMjMwMTZkZmNhZjhiYTE1MjEyNDk0MWJmMzk
Alternative you can also use our Slack workspace: https://join.slack.com/t/rebing-graphql/shared_invite/enQtNTE5NjQzNDI5MzQ4LTdhNjk0ZGY1N2U1YjE4MGVlYmM2YTc2YjQ0MmIwODY5MWMwZWIwYmY1MWY4NTZjY2Q5MzdmM2Q3NTEyNDYzZjc
-->

### Versions:
Expand Down
3 changes: 3 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Misc. change (internal, infrastructure, maintenance, etc.)

### Checklist
- [ ] Existing tests have been adapted and/or new tests have been added
- [ ] Add a CHANGELOG.md entry
- [ ] Update the README.md
- [ ] Code style has been fixed via `composer fix-style`
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: graphql-laravel CI

on: [push, pull_request]

jobs:
static-analysis:
name: Static Analysis
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1

- name: Setup PHP
run: sudo phpdismod xdebug

- uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: composer install
run: composer install --prefer-dist --no-interaction --no-suggest --no-progress

- name: Run phpstan
run: composer phpstan -- --no-progress

code-style-checker:
name: Code Style checker
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1

- name: Setup PHP
run: sudo phpdismod xdebug

- uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: composer install
run: composer install --prefer-dist --no-interaction --no-suggest --no-progress

- name: Run php-cs
run: composer lint
10 changes: 9 additions & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ return (new MattAllan\LaravelCodeStyle\Config())
->setRules([
'@Laravel' => true,
'@Laravel:risky' => true,
// Project specific
'array_indentation' => true,
'declare_strict_types' => true,
'is_null' => true,
'modernize_types_casting' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
],
])
->setRiskyAllowed(true);
->setRiskyAllowed(true);
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ env:
global:
- INSTALL_LARAVEL=0
- INSTALL_LUMEN=0
- STATIC_ANALYSER=0
- LINT=0

matrix:
include:
Expand All @@ -32,7 +30,7 @@ matrix:
- php: '7.3'
env: LARAVEL='5.8.*'
- php: '7.3'
env: LARAVEL='^6.0' STATIC_ANALYSER=1 INSTALL_LARAVEL=1 INSTALL_LUMEN=1 LINT=1
env: LARAVEL='^6.0' INSTALL_LARAVEL=1 INSTALL_LUMEN=1
- php: '7.3'
env: LARAVEL='dev-master'
- php: '7.4snapshot'
Expand All @@ -59,8 +57,7 @@ before_script:
install:
- |
# Due to version incompatiblity with older Laravels we test, we remove it
# when not linting (we only need to perform linting at one job)
if [[ $LINT = 0 ]]; then composer remove --dev matt-allan/laravel-code-style --no-interaction --no-update; fi
composer remove --dev matt-allan/laravel-code-style --no-interaction --no-update
- composer require "illuminate/support:${LARAVEL}" --no-interaction --no-update
- |
# 6.0 requires lifting other requirements too
Expand All @@ -72,13 +69,11 @@ install:
composer require "illuminate/contracts:${LARAVEL}" --no-interaction --no-update
composer require "orchestra/testbench:${LARAVEL}" --no-interaction --no-update
fi
- if [[ $STATIC_ANALYSER = 0 ]]; then composer remove --dev nunomaduro/larastan --no-interaction --no-update; fi
- composer remove --dev nunomaduro/larastan --no-interaction --no-update
- composer install --prefer-dist --no-interaction --no-suggest
- if [[ $LARAVEL = '5.5.*' ]]; then composer require --dev orchestra/database:3.5 --prefer-dist --no-interaction --no-suggest; fi

script:
- if [[ $LINT = 1 ]]; then composer lint; fi
- if [[ $STATIC_ANALYSER = 1 ]]; then composer phpstan; fi
- vendor/bin/phpunit --colors=always --verbose
- TESTS_ENABLE_LAZYLOAD_TYPES=1 vendor/bin/phpunit --colors=always --verbose
- if [[ $INSTALL_LARAVEL = 1 ]]; then export -f travis_retry ; tests/integration-larvavel.sh; fi
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
CHANGELOG
=========

[Next release](https://github.com/rebing/graphql-laravel/compare/3.1.0...master)
[Next release](https://github.com/rebing/graphql-laravel/compare/4.0.0-rc1...master)
--------------

2019-11-28, 4.0.0-rc1
---------------------
### Added
- Allow passing through an instance of a `Field` [\#521 / georgeboot](https://github.com/rebing/graphql-laravel/pull/521/files)
- Add the ability to alias query and mutations arguments as well as input objects [\#517 / crissi](https://github.com/rebing/graphql-laravel/pull/517/files)
- Classes can now be injected in the Resolve method from the query/mutation similarly to Laravel controller methods [\#520 / crissi](https://github.com/rebing/graphql-laravel/pull/520/files)
### Fixed
- Fix validation rules for non-null list of non-null objects [\#511 / crissi](https://github.com/rebing/graphql-laravel/pull/511/files)
- Add morph type to returned models [\#503 / crissi](https://github.com/rebing/graphql-laravel/pull/503)
- Querying same field multiple times causes an error (e.g. via fragments) [\#537 / edgarsn](https://github.com/rebing/graphql-laravel/pull/537)
- Fixed the custom query not being handled by interface's relations [\#486 / EdwinDayot](https://github.com/rebing/graphql-laravel/pull/486)
### Changed
- Switch Code Style handling from StyleCI to PHP-CS Fixer [\#502 / crissi](https://github.com/rebing/graphql-laravel/pull/502)
- Implemented [ClientAware](https://webonyx.github.io/graphql-php/error-handling/#default-error-formatting) interface on integrated exceptions [\#530 / georgeboot](https://github.com/rebing/graphql-laravel/pull/530)
Expand Down
17 changes: 16 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![codecov](https://codecov.io/gh/rebing/graphql-laravel/branch/master/graph/badge.svg)](https://codecov.io/gh/rebing/graphql-laravel)
[![Build Status](https://travis-ci.org/rebing/graphql-laravel.svg?branch=master)](https://travis-ci.org/rebing/graphql-laravel)
[![License](https://poser.pugx.org/rebing/graphql-laravel/license)](https://packagist.org/packages/rebing/graphql-laravel)
[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://join.slack.com/t/rebing-graphql/shared_invite/enQtNTE5NjQzNDI5MzQ4LWVjMTMxNzIyZjBlNTFhZGQ5MDVjZDAwZDNjODA3ODE2NjdiOGJkMjMwMTZkZmNhZjhiYTE1MjEyNDk0MWJmMzk)
[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://join.slack.com/t/rebing-graphql/shared_invite/enQtNTE5NjQzNDI5MzQ4LTdhNjk0ZGY1N2U1YjE4MGVlYmM2YTc2YjQ0MmIwODY5MWMwZWIwYmY1MWY4NTZjY2Q5MzdmM2Q3NTEyNDYzZjc)

### Note: these are the docs for the current release, [please see the `v1` branch for the 1.* docs](https://github.com/rebing/graphql-laravel/tree/v1#laravel-graphql)

Expand Down Expand Up @@ -1519,6 +1519,21 @@ class HumanType extends GraphQLType
}
```

#### Supporting custom queries on interface relations

If an interface contains a relation with a custom query, it's required to implement `public function types()` returning an array of `GraphQL::type()`, i.e. all the possible types it may resolve to (quite similar as it works for unions) so that it works correctly with `SelectFields`.

Based on the previous code example, the method would look like:
```php
public function types(): array
{
return[
GraphQL::type('Human'),
GraphQL::type('Droid'),
];
}
```

#### Sharing Interface fields

Since you often have to repeat many of the field definitons of the Interface in the concrete types, it makes sense to share the definitions of the Interface.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"scripts": {
"phpstan": "phpstan analyse",
"lint": "php-cs-fixer fix --diff --dry-run",
"lint": "php-cs-fixer fix --diff --diff-format=udiff --dry-run",
"fix-style": "php-cs-fixer fix"
},
"extra": {
Expand Down
6 changes: 4 additions & 2 deletions src/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,12 @@ protected function buildObjectTypeFromClass($type, array $opts = []): Type

if (! $type instanceof TypeConvertible) {
throw new TypeNotFound(
sprintf('Unable to convert %s to a GraphQL type, please add/implement the interface %s',
sprintf(
'Unable to convert %s to a GraphQL type, please add/implement the interface %s',
get_class($type),
TypeConvertible::class
));
)
);
}

foreach ($opts as $key => $value) {
Expand Down
3 changes: 0 additions & 3 deletions src/Support/AliasArguments/AliasArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

class AliasArguments
{
private $typedArgs;
private $arguments;

public function get(array $typedArgs, array $arguments): array
{
$pathsWithAlias = $this->getAliasesInFields($typedArgs, '');
Expand Down
10 changes: 7 additions & 3 deletions src/Support/AliasArguments/ArrayKeyChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private function changeKey(array $target, array $segments, string $replaceKey):
$segment = array_shift($segments);

if (empty($segments)) {
if (isset($target[$segment])) {
if (array_key_exists($segment, $target) && $replaceKey !== $segment) {
$target[$replaceKey] = $target[$segment];
unset($target[$segment]);
}
Expand All @@ -49,13 +49,17 @@ private function changeKey(array $target, array $segments, string $replaceKey):

if ('*' === $segment) {
foreach ($target as $index => $inner) {
$target[$index] = $this->changeKey($inner, $segments, $replaceKey);
if ($inner) {
$target[$index] = $this->changeKey($inner, $segments, $replaceKey);
}
}

return $target;
}

$target[$segment] = $this->changeKey($target[$segment], $segments, $replaceKey);
if (array_key_exists($segment, $target) && is_array($target[$segment])) {
$target[$segment] = $this->changeKey($target[$segment], $segments, $replaceKey);
}

return $target;
}
Expand Down
26 changes: 23 additions & 3 deletions src/Support/InterfaceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ protected function getTypeResolver(): ?Closure
};
}

protected function getTypesResolver(): ?Closure
{
if (! method_exists($this, 'types')) {
return null;
}

$resolver = [$this, 'types'];

return function () use ($resolver): array {
$args = func_get_args();

return call_user_func_array($resolver, $args);
};
}

/**
* Get the attributes from the container.
*
Expand All @@ -34,9 +49,14 @@ public function getAttributes(): array
{
$attributes = parent::getAttributes();

$resolver = $this->getTypeResolver();
if ($resolver) {
$attributes['resolveType'] = $resolver;
$resolverType = $this->getTypeResolver();
if ($resolverType) {
$attributes['resolveType'] = $resolverType;
}

$resolverTypes = $this->getTypesResolver();
if ($resolverTypes) {
$attributes['types'] = $resolverTypes;
}

return $attributes;
Expand Down
12 changes: 8 additions & 4 deletions src/Support/ResolveInfoFieldsAndArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ private function foldSelectionSet(SelectionSetNode $selectionSet, int $descend):
$spreadName = $selectionNode->name->value;
if (isset($this->info->fragments[$spreadName])) {
$fragment = $this->info->fragments[$spreadName];
$fields = array_merge_recursive($this->foldSelectionSet($fragment->selectionSet, $descend),
$fields);
$fields = (array) array_replace_recursive(
$this->foldSelectionSet($fragment->selectionSet, $descend),
$fields
);
}
} elseif ($selectionNode instanceof InlineFragmentNode) {
$fields = array_merge_recursive($this->foldSelectionSet($selectionNode->selectionSet, $descend),
$fields);
$fields = (array) array_replace_recursive(
$this->foldSelectionSet($selectionNode->selectionSet, $descend),
$fields
);
}
}

Expand Down
Loading

0 comments on commit 0a6e0e8

Please sign in to comment.