Skip to content

Commit

Permalink
Merge baca079 into d21c852
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-de-wit committed Apr 24, 2023
2 parents d21c852 + baca079 commit 26927db
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.0, 8.1, 8.2]
php: [8.1, 8.2]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ Add [Laravel Sanctum](https://github.com/laravel/sanctum) support to [Lighthouse

## Requirements

- [laravel/laravel:^9.0 || ^10.0](https://github.com/laravel/laravel)
- [laravel/sanctum:^2.0 || ^3.0](https://github.com/laravel/sanctum)
- [nuwave/lighthouse:^5.55.1](https://github.com/nuwave/lighthouse)
- [laravel/sanctum:^3.0](https://github.com/laravel/sanctum)
- [nuwave/lighthouse:^6](https://github.com/nuwave/lighthouse)

## Installation

Expand Down
17 changes: 7 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@
],
"homepage": "https://github.com/daniel-de-wit/lighthouse-sanctum",
"require": {
"php": "^8.0.2 || ^8.1.0 || ^8.2.0",
"laravel/framework": "^9.0 || ^10.0",
"laravel/sanctum": "^2.14 || ^3.0",
"nuwave/lighthouse": "^5.55.1"
"php": "^8.1",
"laravel/sanctum": "^3.0",
"nuwave/lighthouse": "^v6.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"mockery/mockery": "^1.5",
"nunomaduro/larastan": "^1.0 || ^2.0",
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0",
"orchestra/testbench-core": "^6.26 || ^7.0",
"phpoption/phpoption": "^1.8",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^8.0",
"orchestra/testbench-core": "^8.0",
"phpstan/phpstan-mockery": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"thecodingmachine/safe": "^2.0"
"phpunit/phpunit": "^10.0"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 8 additions & 14 deletions src/Exceptions/GraphQLValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
namespace DanielDeWit\LighthouseSanctum\Exceptions;

use Exception;
use GraphQL\Error\ClientAware;
use GraphQL\Error\ProvidesExtensions;
use GraphQL\Type\Definition\ResolveInfo;
use Nuwave\Lighthouse\Exceptions\RendersErrorsExtensions;

class GraphQLValidationException extends Exception implements RendersErrorsExtensions
class GraphQLValidationException extends Exception implements ClientAware, ProvidesExtensions
{
protected string $validationMessage;
protected string $field;

/**
* @param string $message
* @param string $field
* @param string|ResolveInfo $path
*/
public function __construct(string $message, string $field, $path)
public function __construct(string $message, string $field, string|ResolveInfo $path)
{
$this->validationMessage = $message;
$this->field = $field;
Expand All @@ -35,12 +31,10 @@ public function isClientSafe(): bool
return true;
}

public function getCategory(): string
{
return 'validation';
}

public function extensionsContent(): array
/**
* @return array<string, array<string, array<int, string>>>
*/
public function getExtensions(): array
{
return [
'validation' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
use Nuwave\Lighthouse\Auth\AuthServiceProvider;
use Nuwave\Lighthouse\LighthouseServiceProvider;
use Nuwave\Lighthouse\Testing\MakesGraphQLRequests;
use Nuwave\Lighthouse\Testing\TestingServiceProvider;
use Nuwave\Lighthouse\Testing\UsesTestSchema;
use Nuwave\Lighthouse\Validation\ValidationServiceProvider;
use Orchestra\Testbench\TestCase;

abstract class AbstractIntegrationTest extends TestCase
abstract class AbstractIntegrationTestCase extends TestCase
{
use MakesGraphQLRequests;
use RefreshDatabase;
use UsesTestSchema;

/**
* @var Application
Expand All @@ -36,6 +39,7 @@ protected function getPackageProviders($app): array
AuthServiceProvider::class,
LighthouseSanctumServiceProvider::class,
LighthouseServiceProvider::class,
TestingServiceProvider::class,
NotificationServiceProvider::class,
SanctumServiceProvider::class,
ValidationServiceProvider::class,
Expand All @@ -53,7 +57,9 @@ protected function defineDatabaseMigrations(): void
protected function defineEnvironment($app): void
{
$app['config']->set('auth.providers.users.model', UserHasApiTokens::class);
$app['config']->set('lighthouse.schema.register', $this->getStubsPath('schema.graphql'));
$app['config']->set('lighthouse.schema_path', $this->getStubsPath('schema.graphql'));
$app['config']->set('lighthouse.schema_cache.enable', false);
$app['config']->set('lighthouse.query_cache.enable', false);
$app['config']->set('lighthouse.guard', 'sanctum');
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Integration/GraphQL/Mutations/ForgotPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace DanielDeWit\LighthouseSanctum\Tests\Integration\GraphQL\Mutations;

use DanielDeWit\LighthouseSanctum\Tests\Integration\AbstractIntegrationTest;
use DanielDeWit\LighthouseSanctum\Tests\Integration\AbstractIntegrationTestCase;
use DanielDeWit\LighthouseSanctum\Tests\stubs\Users\UserHasApiTokens;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;

class ForgotPasswordTest extends AbstractIntegrationTest
class ForgotPasswordTest extends AbstractIntegrationTestCase
{
/**
* @test
Expand Down Expand Up @@ -120,7 +120,7 @@ public function it_returns_an_error_if_the_email_field_is_not_a_string(): void
message
}
}
')->assertGraphQLErrorMessage('Field "forgotPassword" argument "input" requires type String!, found 12345.');
')->assertGraphQLErrorMessage('String cannot represent a non string value: 12345');
}

/**
Expand All @@ -144,7 +144,7 @@ public function it_returns_an_error_if_the_email_field_is_not_an_email(): void
->assertGraphQLErrorMessage('Validation failed for the field [forgotPassword].')
->assertGraphQLValidationError(
'input.email',
'The input.email must be a valid email address.',
'The input.email field must be a valid email address.',
);
}

Expand Down Expand Up @@ -183,7 +183,7 @@ public function it_returns_an_error_if_the_reset_password_url_field_is_not_a_str
message
}
}
')->assertGraphQLErrorMessage('Field "forgotPassword" argument "input" requires type String!, found 12345.');
')->assertGraphQLErrorMessage('String cannot represent a non string value: 12345');
}

/**
Expand All @@ -207,7 +207,7 @@ public function it_returns_an_error_if_the_reset_password_url_field_is_not_a_url
->assertGraphQLErrorMessage('Validation failed for the field [forgotPassword].')
->assertGraphQLValidationError(
'input.reset_password_url.url',
'The input.reset password url.url must be a valid URL.',
'The input.reset password url.url field must be a valid URL.',
);
}
}
37 changes: 17 additions & 20 deletions tests/Integration/GraphQL/Mutations/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@

namespace DanielDeWit\LighthouseSanctum\Tests\Integration\GraphQL\Mutations;

use DanielDeWit\LighthouseSanctum\Tests\Integration\AbstractIntegrationTest;
use DanielDeWit\LighthouseSanctum\Tests\Integration\AbstractIntegrationTestCase;
use DanielDeWit\LighthouseSanctum\Tests\stubs\Users\UserHasApiTokens;
use DanielDeWit\LighthouseSanctum\Tests\stubs\Users\UserHasApiTokensIdentifiedByUsername;
use DanielDeWit\LighthouseSanctum\Tests\stubs\Users\UserMustVerifyEmail;
use Illuminate\Support\Facades\Hash;
use Nuwave\Lighthouse\Testing\UsesTestSchema;

class LoginTest extends AbstractIntegrationTest
class LoginTest extends AbstractIntegrationTestCase
{
use UsesTestSchema;

/**
* @test
*/
Expand Down Expand Up @@ -48,18 +45,6 @@ public function it_logs_a_user_in(): void
*/
public function it_logs_a_user_in_using_custom_user_identifier(): void
{
$this->setUpTestSchema();

$this->app['config']->set('auth.providers.users.model', UserHasApiTokensIdentifiedByUsername::class);
$this->app['config']->set('lighthouse-sanctum.user_identifier_field_name', 'username');

$this->loadMigrationsFrom('./tests/stubs/migrations');

UserHasApiTokensIdentifiedByUsername::factory()->create([
'username' => 'john.doe',
'password' => Hash::make('supersecret'),
]);

$this->schema = /** @lang GraphQL */ '
type Query
Expand All @@ -78,6 +63,18 @@ public function it_logs_a_user_in_using_custom_user_identifier(): void
}
';

$this->setUpTestSchema();

$this->app['config']->set('auth.providers.users.model', UserHasApiTokensIdentifiedByUsername::class);
$this->app['config']->set('lighthouse-sanctum.user_identifier_field_name', 'username');

$this->loadMigrationsFrom('./tests/stubs/migrations');

UserHasApiTokensIdentifiedByUsername::factory()->create([
'username' => 'john.doe',
'password' => Hash::make('supersecret'),
]);

$this->graphQL(/** @lang GraphQL */ '
mutation {
login(input: {
Expand Down Expand Up @@ -190,7 +187,7 @@ public function it_returns_an_error_if_the_email_field_is_not_a_string(): void
token
}
}
')->assertGraphQLErrorMessage('Field "login" argument "input" requires type String!, found 12345.');
')->assertGraphQLErrorMessage('String cannot represent a non string value: 12345');
}

/**
Expand All @@ -211,7 +208,7 @@ public function it_returns_an_error_if_the_email_field_is_not_an_email(): void
->assertGraphQLErrorMessage('Validation failed for the field [login].')
->assertGraphQLValidationError(
'input.email',
'The input.email must be a valid email address.',
'The input.email field must be a valid email address.',
);
}

Expand Down Expand Up @@ -245,6 +242,6 @@ public function it_returns_an_error_if_the_password_field_is_not_a_string(): voi
token
}
}
')->assertGraphQLErrorMessage('Field "login" argument "input" requires type String!, found 12345.');
')->assertGraphQLErrorMessage('String cannot represent a non string value: 12345');
}
}
4 changes: 2 additions & 2 deletions tests/Integration/GraphQL/Mutations/LogoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace DanielDeWit\LighthouseSanctum\Tests\Integration\GraphQL\Mutations;

use DanielDeWit\LighthouseSanctum\Tests\Integration\AbstractIntegrationTest;
use DanielDeWit\LighthouseSanctum\Tests\Integration\AbstractIntegrationTestCase;
use DanielDeWit\LighthouseSanctum\Tests\stubs\Users\UserHasApiTokens;
use Laravel\Sanctum\Sanctum;

class LogoutTest extends AbstractIntegrationTest
class LogoutTest extends AbstractIntegrationTestCase
{
/**
* @test
Expand Down
20 changes: 10 additions & 10 deletions tests/Integration/GraphQL/Mutations/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace DanielDeWit\LighthouseSanctum\Tests\Integration\GraphQL\Mutations;

use Carbon\Carbon;
use DanielDeWit\LighthouseSanctum\Tests\Integration\AbstractIntegrationTest;
use DanielDeWit\LighthouseSanctum\Tests\Integration\AbstractIntegrationTestCase;
use DanielDeWit\LighthouseSanctum\Tests\stubs\Users\UserHasApiTokens;
use DanielDeWit\LighthouseSanctum\Tests\stubs\Users\UserMustVerifyEmail;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Support\Facades\Notification;

class RegisterTest extends AbstractIntegrationTest
class RegisterTest extends AbstractIntegrationTestCase
{
/**
* @test
Expand Down Expand Up @@ -206,7 +206,7 @@ public function it_returns_an_error_if_the_name_field_is_not_a_string(): void
status
}
}
')->assertGraphQLErrorMessage('Field "register" argument "input" requires type String!, found 12345.');
')->assertGraphQLErrorMessage('String cannot represent a non string value: 12345');
}

/**
Expand Down Expand Up @@ -245,7 +245,7 @@ public function it_returns_an_error_if_the_email_field_is_not_a_string(): void
status
}
}
')->assertGraphQLErrorMessage('Field "register" argument "input" requires type String!, found 12345.');
')->assertGraphQLErrorMessage('String cannot represent a non string value: 12345');
}

/**
Expand All @@ -269,7 +269,7 @@ public function it_returns_an_error_if_the_email_field_is_not_an_email(): void
->assertGraphQLErrorMessage('Validation failed for the field [register].')
->assertGraphQLValidationError(
'input.email',
'The input.email must be a valid email address.',
'The input.email field must be a valid email address.',
);
}

Expand Down Expand Up @@ -338,7 +338,7 @@ public function it_returns_an_error_if_the_password_field_is_not_a_string(): voi
status
}
}
')->assertGraphQLErrorMessage('Field "register" argument "input" requires type String!, found 12345.');
')->assertGraphQLErrorMessage('String cannot represent a non string value: 12345');
}

/**
Expand All @@ -362,7 +362,7 @@ public function it_returns_an_error_if_the_password_field_is_not_confirmed(): vo
->assertGraphQLErrorMessage('Validation failed for the field [register].')
->assertGraphQLValidationError(
'input.password',
'The input.password confirmation does not match.',
'The input.password field confirmation does not match.',
);
}

Expand Down Expand Up @@ -402,7 +402,7 @@ public function it_returns_an_error_if_the_password_confirmation_field_is_not_a_
status
}
}
')->assertGraphQLErrorMessage('Field "register" argument "input" requires type String!, found 12345.');
')->assertGraphQLErrorMessage('String cannot represent a non string value: 12345');
}

/**
Expand Down Expand Up @@ -446,7 +446,7 @@ public function it_returns_an_error_if_the_verification_url_field_is_not_a_strin
status
}
}
')->assertGraphQLErrorMessage('Field "register" argument "input" requires type String!, found 12345.');
')->assertGraphQLErrorMessage('String cannot represent a non string value: 12345');
}

/**
Expand All @@ -473,7 +473,7 @@ public function it_returns_an_error_if_the_verification_url_field_is_not_a_url()
->assertGraphQLErrorMessage('Validation failed for the field [register].')
->assertGraphQLValidationError(
'input.verification_url.url',
'The input.verification url.url must be a valid URL.',
'The input.verification url.url field must be a valid URL.',
);
}
}

0 comments on commit 26927db

Please sign in to comment.