Skip to content

Commit 4741399

Browse files
committed
Merge branch 'master' into make_it_easier_to_extend_select_fields
2 parents 0dcd6d1 + b45cc96 commit 4741399

22 files changed

+101
-51
lines changed

.gitattributes

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
.gitignore export-ignore
55
/.github export-ignore
66
/.php_cs.dist export-ignore
7-
/docker export-ignore
7+
/docker-compose-dev.yml export-ignore
8+
/Dockerfile.dev export-ignore
89
/example export-ignore
10+
/Makefile export-ignore
911
/phpstan-baseline.neon export-ignore
1012
/phpstan.neon.dist export-ignore
1113
/phpunit.xml.dist export-ignore
14+
/README-docker.md export-ignore
1215
/tests export-ignore
1316
/tmp export-ignore
17+
18+
# Github specific: force syntax highlighting to be PHP for stubs
19+
# See https://github.com/github/linguist/blob/master/docs/overrides.md
20+
*.stub linguist-language=PHP

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
/phpunit.xml
44
/composer.lock
55
.phpunit.result.cache
6-
.php_cs.cache
6+
.php-cs-fixer.cache
77
/tmp
File renamed without changes.

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ CHANGELOG
6464
- 1 route for each schema + 1 route for the group prefix (default schema)
6565
- If GraphiQL is enabled: 1 route graphiql route for each schema + 1 for the
6666
graphiql group prefix (default schema)
67-
- This also means that the per schema config key `method` (aka HTTP method)
68-
is not supported anymore
67+
- If provided, the `'method'` argument **must** provide the HTTP method
68+
verbs in uppercase like `POST` or `GET`, `post` or `get` will **not** work.
6969
- It's now possible to prevent the registering of any routes by making the top
7070
level `route` an empty array or null
7171
- `\Rebing\GraphQL\GraphQL::routeNameTransformer` has been removed

Dockerfile.dev

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM php:8.0.10-cli-alpine
2+
3+
COPY --from=mlocati/php-extension-installer:1.2.60 /usr/bin/install-php-extensions /usr/local/bin/
4+
5+
RUN install-php-extensions \
6+
xdebug && \
7+
rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
8+
9+
COPY --from=composer:2.1.8 /usr/bin/composer /usr/local/bin/
10+
11+
COPY ./ /app
12+
13+
WORKDIR /app

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
docker-phpstan:
2+
docker-compose -f docker-compose-dev.yml run --rm php sh -c "php -v ; composer phpstan"
3+
docker-phpstan-baseline:
4+
docker-compose -f docker-compose-dev.yml run --rm php sh -c "php -v ; composer phpstan-baseline"
5+
docker-rebuild:
6+
docker-compose -f docker-compose-dev.yml build php

docker/README.md README-docker.md

File renamed without changes.

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ them, in addition to the global middleware. For example:
289289

290290
],
291291
'middleware' => ['auth'],
292+
// Which HTTP methods to support; must be given in UPPERCASE!
293+
'method' => ['GET', 'POST'],
292294
'execution_middleware' => [
293295
\Rebing\GraphQL\Support\ExecutionMiddleware\UnusedVariablesMiddleware::class,
294296
],
@@ -2520,7 +2522,7 @@ The `macro` function accepts a name as its first argument, and a `Closure` as it
25202522

25212523
Automatic Persisted Queries (APQ) improve network performance by sending smaller requests, with zero build-time configuration.
25222524

2523-
APQ is disabled by default and can be enabled in the config via `apc.enabled=true` or by setting the environment variable `GRAPHQL_APQ_ENABLE=true`.
2525+
APQ is disabled by default and can be enabled in the config via `apq.enabled=true` or by setting the environment variable `GRAPHQL_APQ_ENABLE=true`.
25242526

25252527
A persisted query is an ID or hash that can be generated on the client sent to the server instead of the entire GraphQL query string.
25262528
This smaller signature reduces bandwidth utilization and speeds up client loading times.

composer.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
"require-dev": {
4545
"orchestra/testbench": "4.0.*|5.0.*|^6.0",
4646
"phpunit/phpunit": "~7.0|~8.0|^9",
47-
"nunomaduro/larastan": "0.7.5",
47+
"nunomaduro/larastan": "^0",
4848
"mockery/mockery": "^1.2",
49-
"friendsofphp/php-cs-fixer": "^2.15",
49+
"friendsofphp/php-cs-fixer": "^3",
5050
"ext-pdo_sqlite": "*",
5151
"laravel/legacy-factories": "^1.0",
52-
"mfn/php-cs-fixer-config": "^1"
52+
"mfn/php-cs-fixer-config": "^2"
5353
},
5454
"autoload": {
5555
"psr-4": {
@@ -64,7 +64,7 @@
6464
"scripts": {
6565
"phpstan": "phpstan analyse --memory-limit=512M",
6666
"phpstan-baseline": "phpstan analyse --memory-limit=512M --generate-baseline",
67-
"lint": "php-cs-fixer fix --diff --diff-format=udiff --dry-run",
67+
"lint": "php-cs-fixer fix --diff --dry-run",
6868
"fix-style": "php-cs-fixer fix",
6969
"tests": "phpunit --colors=always --verbose",
7070
"tests-all": [
@@ -86,5 +86,9 @@
8686
}
8787
},
8888
"minimum-stability": "dev",
89-
"prefer-stable": true
89+
"prefer-stable": true,
90+
"config": {
91+
"preferred-install": "dist",
92+
"sort-packages": true
93+
}
9094
}

config/config.php

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
// Laravel HTTP middleware
8888
'middleware' => null,
8989

90+
// Which HTTP methods to support; must be given in UPPERCASE!
91+
'method' => ['GET', 'POST'],
92+
9093
// An array of middlewares, overrides the global ones
9194
'execution_middleware' => null,
9295
],

docker-compose-dev.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
3+
services:
4+
php:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile.dev
8+
volumes:
9+
- ./:/app
10+
working_dir: '/app'

docker/Dockerfile

-13
This file was deleted.

docker/Makefile

-4
This file was deleted.

docker/docker-compose.yml

-8
This file was deleted.

phpstan-baseline.neon

+7-7
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ parameters:
236236
path: src/Support/Rules.php
237237

238238
-
239-
message: "#^Binary operation \"\\.\" between string and array\\|string\\|null results in an error\\.$#"
239+
message: "#^Binary operation \"\\.\" between non\\-empty\\-string and array\\|string\\|null results in an error\\.$#"
240240
count: 1
241241
path: src/Support/SelectFields.php
242242

@@ -391,7 +391,7 @@ parameters:
391391
path: src/Support/Type.php
392392

393393
-
394-
message: "#^Parameter \\#1 \\$callback of function call_user_func_array expects callable\\(\\)\\: mixed, array\\(\\$this\\(Rebing\\\\GraphQL\\\\Support\\\\Type\\), string\\) given\\.$#"
394+
message: "#^Parameter \\#1 \\$callback of function call_user_func_array expects callable\\(\\)\\: mixed, array\\(\\$this\\(Rebing\\\\GraphQL\\\\Support\\\\Type\\), non\\-empty\\-string\\) given\\.$#"
395395
count: 1
396396
path: src/Support/Type.php
397397

@@ -425,11 +425,6 @@ parameters:
425425
count: 1
426426
path: tests/Database/AuthorizeArgsTests/TestAuthorizationArgsQuery.php
427427

428-
-
429-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\AuthorizeArgsTests\\\\TestAuthorizationArgsQuery\\:\\:authorize\\(\\) should return bool but return statement is missing\\.$#"
430-
count: 1
431-
path: tests/Database/AuthorizeArgsTests/TestAuthorizationArgsQuery.php
432-
433428
-
434429
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\AuthorizeArgsTests\\\\TestAuthorizationArgsQuery\\:\\:\\$attributes has no typehint specified\\.$#"
435430
count: 1
@@ -1220,6 +1215,11 @@ parameters:
12201215
count: 1
12211216
path: tests/Support/Objects/ExampleNestedValidationInputObject.php
12221217

1218+
-
1219+
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExampleSchemaWithMethod\\:\\:toConfig\\(\\) should return array\\(\\?'execution_middleware' \\=\\> array\\<class\\-string\\<Rebing\\\\GraphQL\\\\Support\\\\ExecutionMiddleware\\\\AbstractExecutionMiddleware\\>\\>, \\?'method' \\=\\> array\\<string\\>\\|string, \\?'middleware' \\=\\> array\\<string\\>, \\?'mutation' \\=\\> array\\<class\\-string\\>, 'query' \\=\\> array\\<class\\-string\\>, \\?'types' \\=\\> array\\<class\\-string\\>\\) but returns array\\<literal\\-string&non\\-empty\\-string, array\\<string\\>\\|string\\>&nonEmpty\\.$#"
1220+
count: 1
1221+
path: tests/Support/Objects/ExampleSchemaWithMethod.php
1222+
12231223
-
12241224
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExampleType\\:\\:\\$attributes has no typehint specified\\.$#"
12251225
count: 1

src/Support/Contracts/ConfigConvertible.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ interface ConfigConvertible
99
{
1010
/**
1111
* @return array{
12-
* query:array<string,class-string>|array<class-string>,
13-
* mutation?:array<string,class-string>|array<class-string>,
14-
* types?:array<string,class-string>|array<class-string>,
12+
* execution_middleware?:array<class-string<AbstractExecutionMiddleware>>,
13+
* method?:string|string[],
1514
* middleware?:array<string|class-string>,
16-
* execution_middleware?:array<class-string<AbstractExecutionMiddleware>>
15+
* mutation?:array<string,class-string>|array<class-string>,
16+
* query:array<string,class-string>|array<class-string>,
17+
* types?:array<string,class-string>|array<class-string>
1718
* }
1819
*/
1920
public function toConfig(): array;

src/routes.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,23 @@ function (Router $router) use ($config, $routeConfig): void {
3232
$defaultSchema = $config->get('graphql.default_schema', 'default');
3333

3434
foreach ($schemas as $schemaName => $schemaConfig) {
35+
$method = $schemaConfig['method'] ?? ['GET', 'POST'];
3536
$actions = array_filter([
3637
'uses' => $schemaConfig['controller'] ?? $routeConfig['controller'] ?? GraphQLController::class . '@query',
3738
'middleware' => $schemaConfig['middleware'] ?? $routeConfig['middleware'] ?? null,
3839
]);
3940

4041
// Add route for each schema…
4142
$router->addRoute(
42-
['GET', 'POST'],
43+
$method,
4344
$schemaName,
4445
$actions + ['as' => "graphql.$schemaName"]
4546
);
4647

4748
// … and the default schema against the group itself
4849
if ($schemaName === $defaultSchema) {
4950
$router->addRoute(
50-
['GET', 'POST'],
51+
$method,
5152
'',
5253
$actions + ['as' => 'graphql']
5354
);

tests/Database/AuthorizeArgsTests/TestAuthorizationArgsQuery.php

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function authorize(
5050

5151
$selectFields = $getSelectFields();
5252
Assert::assertInstanceOf(SelectFields::class, $selectFields);
53+
54+
return true;
5355
}
5456

5557
public function resolve(): void
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
namespace Rebing\GraphQL\Tests\Support\Objects;
5+
6+
class ExampleSchemaWithMethod extends ExampleSchema
7+
{
8+
public function toConfig(): array
9+
{
10+
return array_merge(parent::toConfig(), ['method' => ['POST']]);
11+
}
12+
}

tests/Unit/GraphQLTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ public function testGetTypes(): void
371371

372372
public function testAddSchema(): void
373373
{
374-
$schema = GraphQL::buildSchemaFromConfig([
374+
$schema = GraphQL::buildSchemaFromConfig(
375+
[
375376
'query' => [
376377
'examplesCustom' => ExamplesQuery::class,
377378
],

tests/Unit/NoRoutesRegisteredTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Routing\Router;
88
use Rebing\GraphQL\Tests\Support\Objects\ExampleMiddleware;
99
use Rebing\GraphQL\Tests\Support\Objects\ExampleSchema;
10+
use Rebing\GraphQL\Tests\Support\Objects\ExampleSchemaWithMethod;
1011
use Rebing\GraphQL\Tests\TestCase;
1112

1213
class NoRoutesRegisteredTest extends TestCase
@@ -27,9 +28,11 @@ protected function getEnvironmentSetUp($app): void
2728
'middleware' => [ExampleMiddleware::class],
2829
],
2930
'with_methods' => [
31+
'method' => ['POST'],
3032
'middleware' => [ExampleMiddleware::class],
3133
],
3234
'class_based' => ExampleSchema::class,
35+
'class_based_with_methods' => ExampleSchemaWithMethod::class,
3336
'shorthand' => BuildSchema::build('
3437
schema {
3538
query: ShorthandExample

tests/Unit/RoutesTest.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Collection;
88
use Rebing\GraphQL\Tests\Support\Objects\ExampleMiddleware;
99
use Rebing\GraphQL\Tests\Support\Objects\ExampleSchema;
10+
use Rebing\GraphQL\Tests\Support\Objects\ExampleSchemaWithMethod;
1011
use Rebing\GraphQL\Tests\TestCase;
1112

1213
class RoutesTest extends TestCase
@@ -30,9 +31,11 @@ protected function getEnvironmentSetUp($app): void
3031
'middleware' => [ExampleMiddleware::class],
3132
],
3233
'with_methods' => [
34+
'method' => ['POST'],
3335
'middleware' => [ExampleMiddleware::class],
3436
],
3537
'class_based' => ExampleSchema::class,
38+
'class_based_with_methods' => ExampleSchemaWithMethod::class,
3639
],
3740
]);
3841
}
@@ -75,9 +78,7 @@ public function testRoutes(): void
7578
],
7679
'graphql.with_methods' => [
7780
'methods' => [
78-
'GET',
7981
'POST',
80-
'HEAD',
8182
],
8283
'uri' => 'graphql_test/with_methods',
8384
'middleware' => [
@@ -95,6 +96,15 @@ public function testRoutes(): void
9596
ExampleMiddleware::class,
9697
],
9798
],
99+
'graphql.class_based_with_methods' => [
100+
'methods' => [
101+
'POST',
102+
],
103+
'uri' => 'graphql_test/class_based_with_methods',
104+
'middleware' => [
105+
ExampleMiddleware::class,
106+
],
107+
],
98108
];
99109

100110
$actual = Collection::make(

0 commit comments

Comments
 (0)