Skip to content

Commit 3efc8fd

Browse files
committed
Adding compatibility with Laravel 9 and 10
Laravel 9 and 10 require jumping PHP version. Because thecodingmachine/graphqlite 6.2 uses the newer psr/container (also used by this package) it requires upgrading a number of classes. Therefore, this commit needs to be tagged as a new minor release at least.
1 parent 5ade008 commit 3efc8fd

File tree

7 files changed

+26
-46
lines changed

7 files changed

+26
-46
lines changed

.github/workflows/continuous_integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
install-args: ['', '--prefer-lowest']
19-
php-version: ['7.4', '8.0']
19+
php-version: ['8.1', '8.2']
2020
fail-fast: false
2121

2222
steps:

composer.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@
2020
"test": "phpunit"
2121
},
2222
"require": {
23-
"php": ">=7.2|^8",
24-
"thecodingmachine/graphqlite": "^6.0",
25-
"illuminate/console": "^5.7|^6.0|^7|^8|^9",
26-
"illuminate/container": "^5.7|^6.0|^7|^8|^9",
27-
"illuminate/support": "^5.7|^6.0|^7|^8|^9",
28-
"illuminate/cache": "^5.7|^6.0|^7|^8|^9",
23+
"php": "^8.1",
24+
"thecodingmachine/graphqlite": "^v6.2.1",
25+
"illuminate/console": "^9 || ^10",
26+
"illuminate/container": "^9 || ^10",
27+
"illuminate/support": "^9 || ^10",
28+
"illuminate/cache": "^9 || ^10",
2929
"symfony/psr-http-message-bridge": "^1.3.0 || ^2",
3030
"laminas/laminas-diactoros": "^2.2.2",
31-
"symfony/cache": "^4.3 || ^5 || ^6"
31+
"symfony/cache": "^4.3 || ^5 || ^6",
32+
"psr/container": "^2.0.2"
3233
},
3334
"require-dev": {
34-
"orchestra/testbench": "^3.7.7 || ^4 || ^5",
35-
"phpunit/phpunit": "^7.5.4 || ^8.3",
35+
"orchestra/testbench": "^7 || ^8",
36+
"phpunit/phpunit": "^9.6.6 || ^10.0.19",
3637
"ext-sqlite3": "*"
3738
},
3839
"autoload": {

src/Exceptions/ValidateException.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,11 @@ public static function create(string $message, string $argumentName)
1919
return $exception;
2020
}
2121

22-
/**
23-
* @return bool
24-
*/
25-
public function isClientSafe()
22+
public function isClientSafe(): bool
2623
{
2724
return true;
2825
}
2926

30-
/**
31-
* @return string
32-
*/
33-
public function getCategory()
34-
{
35-
return 'Validate';
36-
}
37-
3827

3928
/**
4029
* Returns the "extensions" object attached to the GraphQL error.

src/Mappers/PaginatorTypeMapper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace TheCodingMachine\GraphQLite\Laravel\Mappers;
66

77
use GraphQL\Type\Definition\InputObjectType;
8+
use GraphQL\Type\Definition\NamedType;
89
use GraphQL\Type\Definition\NullableType;
910
use GraphQL\Type\Definition\OutputType;
1011
use GraphQL\Type\Definition\Type;
@@ -196,11 +197,11 @@ public function canMapNameToType(string $typeName): bool
196197
*
197198
* @param string $typeName The name of the GraphQL type
198199
*
199-
* @return Type&((ResolvableMutableInputInterface&InputObjectType)|MutableObjectType|MutableInterfaceType)
200+
* @return Type&NamedType&((ResolvableMutableInputInterface&InputObjectType)|MutableObjectType|MutableInterfaceType)
200201
*
201202
* @throws CannotMapTypeExceptionInterface
202203
*/
203-
public function mapNameToType(string $typeName): Type
204+
public function mapNameToType(string $typeName): Type&NamedType
204205
{
205206
if (strpos($typeName, 'LengthAwarePaginatorResult_') === 0) {
206207
$subTypeName = substr($typeName, 27);

src/Mappers/Parameters/ParameterValidator.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GraphQL\Type\Definition\InputType;
88
use GraphQL\Type\Definition\ResolveInfo;
9+
use GraphQL\Type\Definition\Type;
910
use Illuminate\Validation\Factory as ValidationFactory;
1011
use TheCodingMachine\GraphQLite\Exceptions\GraphQLAggregateException;
1112
use TheCodingMachine\GraphQLite\Laravel\Exceptions\ValidateException;
@@ -45,11 +46,8 @@ public function __construct(InputTypeParameterInterface $parameter, string $para
4546

4647
/**
4748
* @param array<string, mixed> $args
48-
* @param mixed $context
49-
*
50-
* @return mixed
5149
*/
52-
public function resolve(?object $source, array $args, $context, ResolveInfo $info)
50+
public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): mixed
5351
{
5452
$value = $this->parameter->resolve($source, $args, $context, $info);
5553

@@ -68,7 +66,7 @@ public function resolve(?object $source, array $args, $context, ResolveInfo $inf
6866
return $value;
6967
}
7068

71-
public function getType(): InputType
69+
public function getType(): InputType&Type
7270
{
7371
return $this->parameter->getType();
7472
}
@@ -78,10 +76,7 @@ public function hasDefaultValue(): bool
7876
return $this->parameter->hasDefaultValue();
7977
}
8078

81-
/**
82-
* @return mixed
83-
*/
84-
public function getDefaultValue()
79+
public function getDefaultValue(): mixed
8580
{
8681
return $this->parameter->getDefaultValue();
8782
}

src/SanePsr11ContainerAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function get($id)
5353
*
5454
* @return bool
5555
*/
56-
public function has($id)
56+
public function has($id): bool
5757
{
5858
if (class_exists($id) && !$this->container->has($id)) {
5959
try {

tests/Providers/GraphQLiteServiceProviderTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,19 @@ public function testValidator()
8787
$response->assertJson([
8888
'errors' => [
8989
[
90-
'message' => 'The foo must be a valid email address.',
9190
'extensions' => [
9291
'argument' => 'foo',
93-
'category' => 'Validate'
9492
],
9593
],
9694
[
97-
'message' => 'The bar must be greater than 42.',
9895
'extensions' => [
9996
'argument' => 'bar',
100-
'category' => 'Validate'
10197
],
10298
]
10399
]
104100
]);
101+
$this->assertStringContainsString('must be a valid email address.', $response->json('errors')[0]['message']);
102+
$this->assertStringContainsString('must be greater than 42.', $response->json('errors')[1]['message']);
105103

106104
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
107105
}
@@ -114,34 +112,31 @@ public function testValidatorMultiple()
114112
[
115113
'extensions' => [
116114
'argument' => 'foo',
117-
'category' => 'Validate'
118115
],
119116
],
120117
[
121-
'message' => 'The foo must be a valid IPv4 address.',
122118
'extensions' => [
123119
'argument' => 'foo',
124-
'category' => 'Validate'
125120
],
126121
]
127122
]
128123
]);
129124

130-
$this->assertStringContainsString('The foo must start with one of the following: 192', $response->json('errors')[0]['message']);
125+
$this->assertStringContainsString('must start with one of the following: 192', $response->json('errors')[0]['message']);
126+
$this->assertStringContainsString('must be a valid IPv4 address.', $response->json('errors')[1]['message']);
131127

132128
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
133129
$response = $this->json('POST', '/graphql', ['query' => '{ testValidatorMultiple(foo:"192.168.1") }']);
134130
$response->assertJson([
135131
'errors' => [
136132
[
137-
'message' => 'The foo must be a valid IPv4 address.',
138133
'extensions' => [
139134
'argument' => 'foo',
140-
'category' => 'Validate'
141135
],
142136
]
143137
]
144138
]);
139+
$this->assertStringContainsString('must be a valid IPv4 address.', $response->json('errors')[0]['message']);
145140

146141
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
147142

@@ -152,12 +147,11 @@ public function testValidatorMultiple()
152147
[
153148
'extensions' => [
154149
'argument' => 'foo',
155-
'category' => 'Validate'
156150
],
157151
]
158152
]
159153
]);
160-
$this->assertStringContainsString('The foo must start with one of the following: 192', $response->json('errors')[0]['message']);
154+
$this->assertStringContainsString('must start with one of the following: 192', $response->json('errors')[0]['message']);
161155

162156
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
163157

0 commit comments

Comments
 (0)