Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Laravel 11 #2508

Merged
merged 26 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
composer-normalize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand All @@ -29,7 +29,7 @@ jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand All @@ -45,7 +45,7 @@ jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand Down
21 changes: 16 additions & 5 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
laravel-version:
- "^9"
- "^10"
- "^11"
composer:
- name: lowest
arg: "--prefer-lowest --prefer-stable"
Expand All @@ -38,9 +39,13 @@ jobs:
exclude:
- php-version: "8.0"
laravel-version: "^10"
- php-version: "8.0"
laravel-version: "^11"
- php-version: "8.1"
laravel-version: "^11"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -86,6 +91,7 @@ jobs:
laravel-version:
- "^9"
- "^10"
- "^11"
os:
- ubuntu-latest
composer:
Expand All @@ -96,6 +102,10 @@ jobs:
exclude:
- php-version: "8.0"
laravel-version: "^10"
- php-version: "8.0"
laravel-version: "^11"
- php-version: "8.1"
laravel-version: "^11"

services:
mysql:
Expand All @@ -113,10 +123,11 @@ jobs:
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: ${{ env.REQUIRED_PHP_EXTENSIONS }}
php-version: ${{ matrix.php-version }}

Expand All @@ -129,7 +140,7 @@ jobs:
- name: "Remove conflicting dependencies that are not needed here"
run: composer remove --dev --no-update larastan/larastan phpstan/phpstan-mockery phpbench/phpbench rector/rector

- if: matrix.laravel-version != '^10'
- if: matrix.laravel-version != '^10' && matrix.laravel-version != '^11'
run: composer remove --dev --no-update laravel/pennant

- run: >
Expand Down Expand Up @@ -169,7 +180,7 @@ jobs:
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -203,7 +214,7 @@ jobs:
- "^10"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ You can find and compare releases at the [GitHub release page](https://github.co

## Unreleased

### Added

- Support Laravel 11 https://github.com/nuwave/lighthouse/pull/2508

## v6.35.0

### Added
Expand Down
28 changes: 13 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
"php": "^8",
"ext-json": "*",
"haydenpierce/class-finder": "^0.4 || ^0.5",
"illuminate/auth": "^9 || ^10",
"illuminate/bus": "^9 || ^10",
"illuminate/contracts": "^9 || ^10",
"illuminate/http": "^9 || ^10",
"illuminate/pagination": "^9 || ^10",
"illuminate/queue": "^9 || ^10",
"illuminate/routing": "^9 || ^10",
"illuminate/support": "^9 || ^10",
"illuminate/validation": "^9 || ^10",
"illuminate/auth": "^9 || ^10 || ^11",
"illuminate/bus": "^9 || ^10 || ^11",
"illuminate/contracts": "^9 || ^10 || ^11",
"illuminate/http": "^9 || ^10 || ^11",
"illuminate/pagination": "^9 || ^10 || ^11",
"illuminate/queue": "^9 || ^10 || ^11",
"illuminate/routing": "^9 || ^10 || ^11",
"illuminate/support": "^9 || ^10 || ^11",
"illuminate/validation": "^9 || ^10 || ^11",
"laragraph/utils": "^1.5 || ^2",
"thecodingmachine/safe": "^1 || ^2",
"webonyx/graphql-php": "^15"
Expand All @@ -50,31 +50,29 @@
"fakerphp/faker": "^1.21",
"google/protobuf": "^3.21",
"larastan/larastan": "^2.6.1",
"laravel/framework": "^9 || ^10",
"laravel/framework": "^9 || ^10 || ^11",
"laravel/legacy-factories": "^1.1.1",
"laravel/lumen-framework": "^9 || ^10 || dev-master",
"laravel/pennant": "^1",
"laravel/scout": "^8 || ^9 || ^10",
"laravel/scout": "^8 || ^9 || ^10 || ^11",
"mattiasgeniar/phpunit-query-count-assertions": "^1.1",
"mll-lab/graphql-php-scalars": "^6",
"mll-lab/php-cs-fixer-config": "^5",
"mockery/mockery": "^1.5",
"nesbot/carbon": "^2.62.1",
"orchestra/testbench": "^7.7 || ^8.8",
"orchestra/testbench": "^7.7 || ^8.8 || ^9",
"phpbench/phpbench": "^1.2.6",
"phpstan/extension-installer": "^1",
"phpstan/phpstan": "^1.10.3",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.1.1",
"phpunit/phpunit": "^9.6.4 || ^10",
"phpunit/phpunit": "^9.6.4 || ^10 || ^11",
"predis/predis": "^1.1 || ^2.1",
"pusher/pusher-php-server": "^5 || ^6 || ^7.0.2",
"rector/rector": "^1",
"thecodingmachine/phpstan-safe-rule": "^1.2"
},
"suggest": {
"ext-protobuf": "Improve protobuf serialization performance (used for tracing)",
"bensampo/laravel-enum": "Convenient enum definitions that can easily be registered in your Schema",
"google/protobuf": "Required when using the tracing driver federated-tracing",
"laravel/pennant": "Required for the @feature directive",
"laravel/scout": "Required for the @search directive",
Expand Down
31 changes: 31 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ parameters:
- src/Pennant
- tests/Integration/Pennant
- src/Tracing/FederatedTracing/Proto # Generated classes from protobuf
# Ignore errors caused by the absence of Lumen in the dev dependencies
- tests/Unit/Testing/TestingTraitDummyLumen.php
ignoreErrors:
# PHPStan does not get it
- '#Parameter \#1 \$callback of static method Closure::fromCallable\(\) expects callable\(\): mixed, array{object, .*} given\.#'
Expand Down Expand Up @@ -64,3 +66,32 @@ parameters:

# Older versions of bensampo/laravel-enum are not generic yet
- '#contains generic type BenSampo\\Enum\\Enum<.+> but class BenSampo\\Enum\\Enum is not generic\.#'

# Ignore errors caused by the absence of Lumen in the dev dependencies
- path: src/Support/AppVersion.php
message: '#PHPDoc tag @var for variable \$container contains unknown class Laravel\\Lumen\\Application.#'
- path: src/Support/AppVersion.php
message: '#Call to method version\(\) on an unknown class Laravel\\Lumen\\Application.#'
- path: src/Subscriptions/SubscriptionRouter.php
messages:
- '#Parameter \$router of method Nuwave\\Lighthouse\\Subscriptions\\SubscriptionRouter::pusher\(\) has invalid type Laravel\\Lumen\\Routing\\Router\.#'
- '#Call to method post\(\) on an unknown class Laravel\\Lumen\\Routing\\Router\.#'
- '#Parameter \$router of method Nuwave\\Lighthouse\\Subscriptions\\SubscriptionRouter::echoRoutes\(\) has invalid type Laravel\\Lumen\\Routing\\Router\.#'
- path: src/Http/routes.php
messages:
- '#PHPDoc tag @var for variable \$router contains unknown class Laravel\\Lumen\\Routing\\Router\.#'
- '#Call to method addRoute\(\) on an unknown class Laravel\\Lumen\\Routing\\Router\.#'

# Recent Mockery versions do not account for the last arg possibly being a closure
- path: tests/Unit/Subscriptions/Iterators/AuthenticatingSyncIteratorTest.php
message: '#Parameter \#2 \.\.\.\$args of static method Mockery::mock\(\) expects array\|class-string<Nuwave\\Lighthouse\\Subscriptions\\SubscriptionGuard>\|Nuwave\\Lighthouse\\Subscriptions\\SubscriptionGuard, Closure given\.#'

- path: tests/Integration/Schema/Directives/BuilderDirectiveTest.php
message: '#Return type of call to static method Mockery::mock\(\) contains unresolvable type\.#'

# Laravel added generics to Arr::first in 11.x, not sure how to handle them for now.
- path: src/OrderBy/OrderByDirective.php
message: '#Unable to resolve the template type TValue in call to method static method Illuminate\\Support\\Arr::first\(\)#'
- path: src/Testing/TestResponseMixin.php
message: '#Unable to resolve the template type TValue in call to method static method Illuminate\\Support\\Arr::first\(\)#'

2 changes: 2 additions & 0 deletions src/Exceptions/ClientSafeModelNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @template TModel of \Illuminate\Database\Eloquent\Model
*
* @extends ModelNotFoundException<TModel>
*/
class ClientSafeModelNotFoundException extends ModelNotFoundException implements ClientAware
Expand All @@ -18,6 +19,7 @@ public function isClientSafe(): bool

/**
* @param ModelNotFoundException<TModel> $laravelException
*
* @return self<TModel>
*/
public static function fromLaravel(ModelNotFoundException $laravelException): self
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Directives/ThrottleDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function handleField(FieldValue $fieldValue): void
$this->handleLimit(
sha1($name . $limit->key),
$limit->maxAttempts,
$limit->decayMinutes,
// Laravel 11 switched to using seconds
$limit->decayMinutes ?? $limit->decaySeconds * 60,
"{$resolveInfo->parentType}.{$resolveInfo->fieldName}",
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/FederatedTracing/Proto/FieldStat.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Tracing/FederatedTracing/Proto/QueryLatencyStats.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Tracing/FederatedTracing/Proto/Trace.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/Integration/Auth/CanDirectiveDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function testFailsToFindSpecificModel(): void
],
]);
}

public function testThrowsCustomExceptionWhenFailsToFindModel(): void
{
$user = new User();
Expand Down Expand Up @@ -129,7 +130,7 @@ public function testThrowsCustomExceptionWhenFailsToFindModel(): void
$previous = $error->getPrevious();

$this->assertNotNull($previous);
$this->assertSame(ClientSafeModelNotFoundException::class, get_class($previous));
$this->assertInstanceOf(ClientSafeModelNotFoundException::class, $previous);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Auth/CanFindDirectiveDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function testThrowsCustomExceptionWhenFailsToFindModel(): void
$previous = $error->getPrevious();

$this->assertNotNull($previous);
$this->assertSame(ClientSafeModelNotFoundException::class, get_class($previous));
$this->assertInstanceOf(ClientSafeModelNotFoundException::class, $previous);
}
}

Expand Down
9 changes: 4 additions & 5 deletions tests/Integration/Schema/Types/InterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use GraphQL\Type\Definition\Type;
use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
use Nuwave\Lighthouse\Schema\TypeRegistry;
use Tests\DBTestCase;
Expand Down Expand Up @@ -341,11 +340,11 @@ interface HasPosts {
$this->assertSame('PostPaginator', $result->json('data.__type.fields.0.type.ofType.name'));
}

/** @return \Illuminate\Database\Eloquent\Collection<int, \Tests\Utils\Models\User|\Tests\Utils\Models\Team> */
public static function fetchResults(): EloquentCollection
/** @return \Illuminate\Support\Collection<int, \Tests\Utils\Models\User|\Tests\Utils\Models\Team> */
public static function fetchResults(): Collection
{
/** @var \Illuminate\Database\Eloquent\Collection<int, \Tests\Utils\Models\User|\Tests\Utils\Models\Team> $results */
$results = new EloquentCollection();
/** @var \Illuminate\Support\Collection<int, \Tests\Utils\Models\User|\Tests\Utils\Models\Team> $results */
$results = new Collection();

return $results
->concat(User::all())
Expand Down
10 changes: 5 additions & 5 deletions tests/Integration/Schema/Types/UnionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Tests\Integration\Schema\Types;

use GraphQL\Error\InvariantViolation;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
use Nuwave\Lighthouse\Schema\TypeRegistry;
use Tests\DBTestCase;
use Tests\Utils\Models\Post;
Expand Down Expand Up @@ -178,11 +178,11 @@ public function testThrowsOnNonOverlappingSchemaMapping(): void
');
}

/** @return \Illuminate\Database\Eloquent\Collection<int, \Tests\Utils\Models\User|\Tests\Utils\Models\Post> */
public static function fetchResults(): EloquentCollection
/** @return \Illuminate\Support\Collection<int, \Tests\Utils\Models\User|\Tests\Utils\Models\Post> */
public static function fetchResults(): Collection
{
/** @var \Illuminate\Database\Eloquent\Collection<int, \Tests\Utils\Models\User|\Tests\Utils\Models\Post> $results */
$results = new EloquentCollection();
/** @var \Illuminate\Support\Collection<int, \Tests\Utils\Models\User|\Tests\Utils\Models\Post> $results */
$results = new Collection();

return $results
->concat(User::all())
Expand Down
Loading
Loading