diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md index e08a75b8e2..801b84de36 100644 --- a/.claude/CLAUDE.md +++ b/.claude/CLAUDE.md @@ -77,6 +77,14 @@ Multiple service providers for optional features (auto-discovered via composer.j Tests use `Tests\Utils\` namespace for test fixtures (Models, Queries, Mutations, etc.). +### GraphQL string style in tests + +- Always annotate GraphQL literals with `/** @lang GraphQL */`. +- Default to nowdoc: `<<<'GRAPHQL'`. +- Use heredoc: `<<schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( arg: ID @eq ): ID @guard } - '; + GRAPHQL; $tester = $this->commandTester(new ValidateSchemaCommand()); $tester->execute([]); @@ -25,11 +25,11 @@ public function testValidatesCorrectSchema(): void public function testFailsValidationUnknownDirective(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID @unknown } - '; + GRAPHQL; $tester = $this->commandTester(new ValidateSchemaCommand()); $this->expectException(DirectiveException::class); @@ -42,11 +42,11 @@ public function testFailsValidationDirectiveInWrongLocation(): void $this->markTestSkipped('This validation needs to be in the upstream webonyx/graphql-php validation'); // @phpstan-ignore-next-line https://github.com/phpstan/phpstan-phpunit/issues/52 - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query @field { foo: ID @eq } - '; + GRAPHQL; $tester = $this->commandTester(new ValidateSchemaCommand()); $tester->execute([]); diff --git a/tests/Integration/Async/AsyncDirectiveTest.php b/tests/Integration/Async/AsyncDirectiveTest.php index bd7a931f75..ec914bc603 100644 --- a/tests/Integration/Async/AsyncDirectiveTest.php +++ b/tests/Integration/Async/AsyncDirectiveTest.php @@ -16,18 +16,18 @@ public function testDispatchesMutation(): void { $this->mockResolver(static fn (mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) => null); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { fooAsync: Boolean! @mock @async } - '; + GRAPHQL; $queue = Queue::fake(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { fooAsync } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'fooAsync' => true, ], @@ -48,18 +48,18 @@ public function testDispatchesMutationOnCustomQueue(): void { $this->mockResolver(static fn (mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) => null); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { fooAsync: Boolean! @mock @async(queue: "custom") } - '; + GRAPHQL; $queue = Queue::fake(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { fooAsync } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'fooAsync' => true, ], @@ -82,10 +82,10 @@ public function testOnlyOnMutations(): void $this->expectExceptionObject(new DefinitionException( 'The @async directive must only be used on root mutation fields, found it on Query.foo.', )); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Boolean! @async } - '); + GRAPHQL); } } diff --git a/tests/Integration/Auth/CanDirectiveDBTest.php b/tests/Integration/Auth/CanDirectiveDBTest.php index b2924feb9b..8a1af82520 100644 --- a/tests/Integration/Auth/CanDirectiveDBTest.php +++ b/tests/Integration/Auth/CanDirectiveDBTest.php @@ -25,7 +25,7 @@ public function testQueriesForSpecificModel(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID @whereKey): User @can(ability: "view", find: "id") @@ -35,15 +35,15 @@ public function testQueriesForSpecificModel(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { name } } - ', [ + GRAPHQL, [ 'id' => $user->getKey(), ])->assertJson([ 'data' => [ @@ -64,7 +64,7 @@ public function testFailsToFindSpecificModel(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID @whereKey): User @can(ability: "view", find: "id") @@ -74,15 +74,15 @@ public function testFailsToFindSpecificModel(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => null, ], @@ -104,7 +104,7 @@ public function testThrowsCustomExceptionWhenFailsToFindModel(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID @whereKey): User @can(ability: "view", find: "id") @@ -114,18 +114,18 @@ public function testThrowsCustomExceptionWhenFailsToFindModel(): void type User { name: String! } - '; + GRAPHQL; $this->rethrowGraphQLErrors(); try { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { name } } - '); + GRAPHQL); } catch (Error $error) { $previous = $error->getPrevious(); @@ -142,7 +142,7 @@ public function testFailsToFindSpecificModelWithFindOrFailFalse(): void $this->mockResolver(null); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID @whereKey): User @can(ability: "view", find: "id", findOrFail: false) @@ -152,15 +152,15 @@ public function testFailsToFindSpecificModelWithFindOrFailFalse(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'user' => null, ], @@ -173,7 +173,7 @@ public function testThrowsIfFindValueIsNotGiven(): void $user->name = UserPolicy::ADMIN; $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID): User @can(ability: "view", find: "some.path") @@ -183,15 +183,15 @@ public function testThrowsIfFindValueIsNotGiven(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertGraphQLError(CanDirective::missingKeyToFindModel('some.path')); + GRAPHQL)->assertGraphQLError(CanDirective::missingKeyToFindModel('some.path')); } public function testFindUsingNestedInputWithDotNotation(): void @@ -200,7 +200,7 @@ public function testFindUsingNestedInputWithDotNotation(): void $this->assertInstanceOf(User::class, $user); $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(input: FindUserInput): User @can(ability: "view", find: "input.id") @@ -214,9 +214,9 @@ public function testFindUsingNestedInputWithDotNotation(): void input FindUserInput { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(input: { id: $id @@ -224,7 +224,7 @@ public function testFindUsingNestedInputWithDotNotation(): void name } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertJson([ 'data' => [ @@ -253,7 +253,7 @@ public function testThrowsIfNotAuthorized(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { post(foo: ID! @whereKey): Post @can(ability: "view", find: "foo") @@ -263,15 +263,15 @@ public function testThrowsIfNotAuthorized(): void type Post { title: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($foo: ID!) { post(foo: $foo) { title } } - ', [ + GRAPHQL, [ 'foo' => $post->id, ])->assertGraphQLErrorMessage(AuthorizationException::MESSAGE); } @@ -292,7 +292,7 @@ public function testHandleMultipleModels(): void $postB->user()->associate($admin); $postB->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { deletePosts(ids: [ID!]! @whereKey): [Post!]! @can(ability: "delete", find: "ids") @@ -302,15 +302,15 @@ public function testHandleMultipleModels(): void type Post { title: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($ids: [ID!]!) { deletePosts(ids: $ids) { title } } - ', [ + GRAPHQL, [ 'ids' => [$postA->id, $postB->id], ])->assertJson([ 'data' => [ @@ -336,7 +336,7 @@ public function testWorksWithSoftDeletes(): void $this->assertInstanceOf(Task::class, $task); $task->delete(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { task(id: ID! @whereKey): Task @can(ability: "adminOnly", find: "id") @@ -347,15 +347,15 @@ public function testWorksWithSoftDeletes(): void type Task { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { task(id: $id, trashed: WITH) { name } } - ', [ + GRAPHQL, [ 'id' => $task->id, ])->assertJson([ 'data' => [ @@ -375,7 +375,7 @@ public function testQueriesForSpecificModelWithQuery(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(name: String! @eq): User @can(ability: "view", query: true) @@ -385,15 +385,15 @@ public function testQueriesForSpecificModelWithQuery(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($name: String!) { user(name: $name) { name } } - ', [ + GRAPHQL, [ 'name' => $user->name, ])->assertJson([ 'data' => [ @@ -414,7 +414,7 @@ public function testFailsToFindSpecificModelWithQuery(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @whereKey): User @can(ability: "view", query: true) @@ -424,15 +424,15 @@ public function testFailsToFindSpecificModelWithQuery(): void type User { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => null, ], @@ -455,7 +455,7 @@ public function testHandleMultipleModelsWithQuery(): void $postB->user()->associate($admin); $postB->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { deletePosts(ids: [ID!]! @whereKey): [Post!]! @can(ability: "delete", query: true) @@ -465,15 +465,15 @@ public function testHandleMultipleModelsWithQuery(): void type Post { title: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($ids: [ID!]!) { deletePosts(ids: $ids) { title } } - ', [ + GRAPHQL, [ 'ids' => [$postA->id, $postB->id], ])->assertJson([ 'data' => [ @@ -499,7 +499,7 @@ public function testWorksWithSoftDeletesWithQuery(): void $this->assertInstanceOf(Task::class, $task); $task->delete(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { task(id: ID! @whereKey): Task @can(ability: "adminOnly", query: true) @@ -510,15 +510,15 @@ public function testWorksWithSoftDeletesWithQuery(): void type Task { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { task(id: $id, trashed: WITH) { name } } - ', [ + GRAPHQL, [ 'id' => $task->id, ])->assertJson([ 'data' => [ @@ -537,7 +537,7 @@ public function testChecksAgainstResolvedModelsFromPaginator(): void $user = factory(User::class)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [User!]! @can(ability: "view", resolved: true) @@ -547,9 +547,9 @@ public function testChecksAgainstResolvedModelsFromPaginator(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 2) { data { @@ -557,7 +557,7 @@ public function testChecksAgainstResolvedModelsFromPaginator(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'data' => [ @@ -583,7 +583,7 @@ public function testChecksAgainstRelation(): void $user->company()->associate($company); $user->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { company: Company @first } @@ -597,9 +597,9 @@ public function testChecksAgainstRelation(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { company { users { @@ -607,7 +607,7 @@ public function testChecksAgainstRelation(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'company' => [ 'users' => [ @@ -628,7 +628,7 @@ public function testChecksAgainstMissingResolvedModelWithFind(): void $user = factory(User::class)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID @whereKey): User @can(ability: "view", resolved: true) @@ -638,15 +638,15 @@ public function testChecksAgainstMissingResolvedModelWithFind(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => null, ], diff --git a/tests/Integration/Auth/CanFindDirectiveDBTest.php b/tests/Integration/Auth/CanFindDirectiveDBTest.php index a6ac5fe73a..d24482bc00 100644 --- a/tests/Integration/Auth/CanFindDirectiveDBTest.php +++ b/tests/Integration/Auth/CanFindDirectiveDBTest.php @@ -24,7 +24,7 @@ public function testQueriesForSpecificModel(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @whereKey): User @canFind(ability: "view", find: "id") @@ -34,15 +34,15 @@ public function testQueriesForSpecificModel(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { name } } - ', [ + GRAPHQL, [ 'id' => $user->getKey(), ])->assertJson([ 'data' => [ @@ -62,7 +62,7 @@ public function testCustomModelName(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { account(id: ID! @whereKey): Account @canFind(ability: "view", find: "id", model: "User") @@ -72,15 +72,15 @@ public function testCustomModelName(): void type Account { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { account(id: $id) { name } } - ', [ + GRAPHQL, [ 'id' => $user->getKey(), ])->assertJson([ 'data' => [ @@ -101,7 +101,7 @@ public function testFailsToFindSpecificModel(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @whereKey): User @canFind(ability: "view", find: "id") @@ -111,15 +111,15 @@ public function testFailsToFindSpecificModel(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => null, ], @@ -141,7 +141,7 @@ public function testThrowsCustomExceptionWhenFailsToFindModel(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @whereKey): User @canFind(ability: "view", find: "id") @@ -151,18 +151,18 @@ public function testThrowsCustomExceptionWhenFailsToFindModel(): void type User { name: String! } - '; + GRAPHQL; $this->rethrowGraphQLErrors(); try { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { name } } - '); + GRAPHQL); } catch (Error $error) { $previous = $error->getPrevious(); @@ -181,7 +181,7 @@ public function testFailsToFindSpecificModelConcealException(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @whereKey): User @canFind(ability: "view", find: "id", action: EXCEPTION_NOT_AUTHORIZED) @@ -191,15 +191,15 @@ public function testFailsToFindSpecificModelConcealException(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => null, ], @@ -220,7 +220,7 @@ public function testDoesntConcealResolverException(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { throwWhenInvoked(id: ID!): User @canFind(ability: "view", find: "id", action: EXCEPTION_NOT_AUTHORIZED) @@ -229,15 +229,15 @@ public function testDoesntConcealResolverException(): void type User { name: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { throwWhenInvoked(id: $id) { name } } - ', [ + GRAPHQL, [ 'id' => $user->getKey(), ])->assertGraphQLErrorMessage(ThrowWhenInvoked::ERROR_MESSAGE); } @@ -250,7 +250,7 @@ public function testFailsToFindSpecificModelWithFindOrFailFalse(): void $this->mockResolver(null); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @whereKey): User @canFind(ability: "view", find: "id", findOrFail: false) @@ -260,15 +260,15 @@ public function testFailsToFindSpecificModelWithFindOrFailFalse(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'user' => null, ], @@ -281,7 +281,7 @@ public function testThrowsIfFindValueIsNotGiven(): void $user->name = UserPolicy::ADMIN; $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID): User @canFind(ability: "view", find: "some.path") @@ -291,15 +291,15 @@ public function testThrowsIfFindValueIsNotGiven(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertGraphQLError(CanDirective::missingKeyToFindModel('some.path')); + GRAPHQL)->assertGraphQLError(CanDirective::missingKeyToFindModel('some.path')); } public function testFindUsingNestedInputWithDotNotation(): void @@ -308,7 +308,7 @@ public function testFindUsingNestedInputWithDotNotation(): void $this->assertInstanceOf(User::class, $user); $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(input: FindUserInput!): User @canFind(ability: "view", find: "input.id") @@ -322,9 +322,9 @@ public function testFindUsingNestedInputWithDotNotation(): void input FindUserInput { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(input: { id: $id @@ -332,7 +332,7 @@ public function testFindUsingNestedInputWithDotNotation(): void name } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertJson([ 'data' => [ @@ -361,7 +361,7 @@ public function testThrowsIfNotAuthorized(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { post(foo: ID! @whereKey): Post @canFind(ability: "view", find: "foo") @@ -371,15 +371,15 @@ public function testThrowsIfNotAuthorized(): void type Post { title: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($foo: ID!) { post(foo: $foo) { title } } - ', [ + GRAPHQL, [ 'foo' => $post->id, ])->assertGraphQLErrorMessage(AuthorizationException::MESSAGE); } @@ -400,7 +400,7 @@ public function testHandleMultipleModels(): void $postB->user()->associate($admin); $postB->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { deletePosts(ids: [ID!]! @whereKey): [Post!]! @canFind(ability: "delete", find: "ids") @@ -410,15 +410,15 @@ public function testHandleMultipleModels(): void type Post { title: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($ids: [ID!]!) { deletePosts(ids: $ids) { title } } - ', [ + GRAPHQL, [ 'ids' => [$postA->id, $postB->id], ])->assertJson([ 'data' => [ @@ -444,7 +444,7 @@ public function testWorksWithSoftDeletes(): void $this->assertInstanceOf(Task::class, $task); $task->delete(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { task(id: ID! @whereKey): Task @canFind(ability: "adminOnly", find: "id") @@ -455,15 +455,15 @@ public function testWorksWithSoftDeletes(): void type Task { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { task(id: $id, trashed: WITH) { name } } - ', [ + GRAPHQL, [ 'id' => $task->id, ])->assertJson([ 'data' => [ diff --git a/tests/Integration/Auth/CanModelDirectiveDBTest.php b/tests/Integration/Auth/CanModelDirectiveDBTest.php index e6f8d893d0..75e5fe46fa 100644 --- a/tests/Integration/Auth/CanModelDirectiveDBTest.php +++ b/tests/Integration/Auth/CanModelDirectiveDBTest.php @@ -15,7 +15,7 @@ public function testDoesntConcealResolverException(): void $admin->name = UserPolicy::ADMIN; $this->be($admin); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { throwWhenInvoked: Task @canModel(ability: "adminOnly", action: EXCEPTION_NOT_AUTHORIZED) @@ -24,14 +24,14 @@ public function testDoesntConcealResolverException(): void type Task { name: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { throwWhenInvoked { name } } - ')->assertGraphQLErrorMessage(ThrowWhenInvoked::ERROR_MESSAGE); + GRAPHQL)->assertGraphQLErrorMessage(ThrowWhenInvoked::ERROR_MESSAGE); } } diff --git a/tests/Integration/Auth/CanQueryDirectiveDBTest.php b/tests/Integration/Auth/CanQueryDirectiveDBTest.php index 669a16f736..5f6f30aa56 100644 --- a/tests/Integration/Auth/CanQueryDirectiveDBTest.php +++ b/tests/Integration/Auth/CanQueryDirectiveDBTest.php @@ -20,7 +20,7 @@ public function testQueriesForSpecificModelWithQuery(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(name: String! @eq): User @canQuery(ability: "view") @@ -30,15 +30,15 @@ public function testQueriesForSpecificModelWithQuery(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($name: String!) { user(name: $name) { name } } - ', [ + GRAPHQL, [ 'name' => $user->name, ])->assertJson([ 'data' => [ @@ -59,7 +59,7 @@ public function testFailsToFindSpecificModelWithQuery(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @whereKey): User @canQuery(ability: "view", query: true) @@ -69,15 +69,15 @@ public function testFailsToFindSpecificModelWithQuery(): void type User { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => null, ], @@ -93,7 +93,7 @@ public function testDoesntConcealResolverException(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { throwWhenInvoked(id: ID!): User @canQuery(ability: "view", action: EXCEPTION_NOT_AUTHORIZED) @@ -102,15 +102,15 @@ public function testDoesntConcealResolverException(): void type User { name: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { throwWhenInvoked(id: $id) { name } } - ', [ + GRAPHQL, [ 'id' => $user->getKey(), ])->assertGraphQLErrorMessage(ThrowWhenInvoked::ERROR_MESSAGE); } @@ -131,7 +131,7 @@ public function testHandleMultipleModelsWithQuery(): void $postB->user()->associate($admin); $postB->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { deletePosts(ids: [ID!]! @whereKey): [Post!]! @canQuery(ability: "delete") @@ -141,15 +141,15 @@ public function testHandleMultipleModelsWithQuery(): void type Post { title: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($ids: [ID!]!) { deletePosts(ids: $ids) { title } } - ', [ + GRAPHQL, [ 'ids' => [$postA->id, $postB->id], ])->assertJson([ 'data' => [ @@ -175,7 +175,7 @@ public function testWorksWithSoftDeletesWithQuery(): void $this->assertInstanceOf(Task::class, $task); $task->delete(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { task(id: ID! @whereKey): Task @canQuery(ability: "adminOnly") @@ -186,15 +186,15 @@ public function testWorksWithSoftDeletesWithQuery(): void type Task { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { task(id: $id, trashed: WITH) { name } } - ', [ + GRAPHQL, [ 'id' => $task->id, ])->assertJson([ 'data' => [ diff --git a/tests/Integration/Auth/CanResolvedDirectiveDBTest.php b/tests/Integration/Auth/CanResolvedDirectiveDBTest.php index a0248458c4..0d83ad4823 100644 --- a/tests/Integration/Auth/CanResolvedDirectiveDBTest.php +++ b/tests/Integration/Auth/CanResolvedDirectiveDBTest.php @@ -17,7 +17,7 @@ public function testChecksAgainstResolvedModelsFromPaginator(): void $user = factory(User::class)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [User!]! @canResolved(ability: "view") @@ -27,9 +27,9 @@ public function testChecksAgainstResolvedModelsFromPaginator(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 2) { data { @@ -37,7 +37,7 @@ public function testChecksAgainstResolvedModelsFromPaginator(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'data' => [ @@ -63,7 +63,7 @@ public function testChecksAgainstRelation(): void $user->company()->associate($company); $user->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { company: Company @first } @@ -77,9 +77,9 @@ public function testChecksAgainstRelation(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { company { users { @@ -87,7 +87,7 @@ public function testChecksAgainstRelation(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'company' => [ 'users' => [ @@ -108,7 +108,7 @@ public function testChecksAgainstMissingResolvedModelWithFind(): void $user = factory(User::class)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @whereKey): User @canResolved(ability: "view") @@ -118,15 +118,15 @@ public function testChecksAgainstMissingResolvedModelWithFind(): void type User { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: "not-present") { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => null, ], diff --git a/tests/Integration/Auth/CanRootDirectiveDBTest.php b/tests/Integration/Auth/CanRootDirectiveDBTest.php index 53f86c0048..2bf2e01c6c 100644 --- a/tests/Integration/Auth/CanRootDirectiveDBTest.php +++ b/tests/Integration/Auth/CanRootDirectiveDBTest.php @@ -15,7 +15,7 @@ public function testDoesntConcealResolverException(): void $admin->name = UserPolicy::ADMIN; $this->be($admin); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { throwWhenInvoked: Task } @@ -23,14 +23,14 @@ public function testDoesntConcealResolverException(): void type Task { name: String! @canRoot(ability: "adminOnly", action: EXCEPTION_NOT_AUTHORIZED) } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { throwWhenInvoked { name } } - ')->assertGraphQLErrorMessage(ThrowWhenInvoked::ERROR_MESSAGE); + GRAPHQL)->assertGraphQLErrorMessage(ThrowWhenInvoked::ERROR_MESSAGE); } } diff --git a/tests/Integration/AutomaticPersistedQueriesTest.php b/tests/Integration/AutomaticPersistedQueriesTest.php index 04c8a49660..c2a925f67a 100644 --- a/tests/Integration/AutomaticPersistedQueriesTest.php +++ b/tests/Integration/AutomaticPersistedQueriesTest.php @@ -149,11 +149,11 @@ public function testConfigDisabled(): void $config->set('lighthouse.query_cache.enable', true); $config->set('lighthouse.persisted_queries', false); - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' { foo } - '; + GRAPHQL; $sha256 = hash('sha256', $query); @@ -192,11 +192,11 @@ public function testCacheDisabled(): void $config->set('lighthouse.query_cache.enable', false); $config->set('lighthouse.persisted_queries', true); - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' { foo } - '; + GRAPHQL; $sha256 = hash('sha256', $query); diff --git a/tests/Integration/Bind/BindDirectiveTest.php b/tests/Integration/Bind/BindDirectiveTest.php index 93330deb1e..67e3592d42 100644 --- a/tests/Integration/Bind/BindDirectiveTest.php +++ b/tests/Integration/Bind/BindDirectiveTest.php @@ -21,7 +21,7 @@ final class BindDirectiveTest extends DBTestCase public function testSchemaValidationFailsWhenClassArgumentDefinedOnFieldArgumentIsNotAClass(): void { - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -29,23 +29,23 @@ public function testSchemaValidationFailsWhenClassArgumentDefinedOnFieldArgument type Query { user(user: ID! @bind(class: "NotAClass")): User! @mock } - GRAPHQL; + GRAPHQL; $this->expectExceptionObject(new DefinitionException( '@bind argument `class` defined on `user.user` must be an existing class, received `NotAClass`.', )); - $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(user: "1") { id } } - GRAPHQL); + GRAPHQL); } public function testSchemaValidationFailsWhenClassArgumentDefinedOnInputFieldIsNotAClass(): void { - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -57,27 +57,25 @@ public function testSchemaValidationFailsWhenClassArgumentDefinedOnInputFieldIsN type Mutation { removeUsers(input: RemoveUsersInput!): Boolean! @mock } - GRAPHQL; + GRAPHQL; $this->expectExceptionObject(new DefinitionException( '@bind argument `class` defined on `RemoveUsersInput.users` must be an existing class, received `NotAClass`.', )); - $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: RemoveUsersInput!) { removeUsers(input: $input) } - GRAPHQL, - [ - 'input' => [ - 'users' => ['1'], - ], + GRAPHQL, [ + 'input' => [ + 'users' => ['1'], ], - ); + ]); } public function testSchemaValidationFailsWhenClassArgumentDefinedOnFieldArgumentIsNotAModelOrCallableClass(): void { - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -85,23 +83,23 @@ public function testSchemaValidationFailsWhenClassArgumentDefinedOnFieldArgument type Query { user(user: ID! @bind(class: "stdClass")): User! @mock } - GRAPHQL; + GRAPHQL; $this->expectExceptionObject(new DefinitionException( '@bind argument `class` defined on `user.user` must extend Illuminate\Database\Eloquent\Model or define the method `__invoke`, but `stdClass` does neither.', )); - $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(user: "1") { id } } - GRAPHQL); + GRAPHQL); } public function testSchemaValidationFailsWhenClassArgumentDefinedOnInputFieldIsNotAModelOrCallableClass(): void { - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -113,22 +111,20 @@ public function testSchemaValidationFailsWhenClassArgumentDefinedOnInputFieldIsN type Mutation { removeUsers(input: RemoveUsersInput!): Boolean! @mock } - GRAPHQL; + GRAPHQL; $this->expectExceptionObject(new DefinitionException( '@bind argument `class` defined on `RemoveUsersInput.users` must extend Illuminate\Database\Eloquent\Model or define the method `__invoke`, but `stdClass` does neither.', )); - $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: RemoveUsersInput!) { removeUsers(input: $input) } - GRAPHQL, - [ - 'input' => [ - 'users' => ['1'], - ], + GRAPHQL, [ + 'input' => [ + 'users' => ['1'], ], - ); + ]); } public function testModelBindingOnFieldArgument(): void @@ -137,7 +133,7 @@ public function testModelBindingOnFieldArgument(): void $this->mockResolver(fn (mixed $root, array $args): User => $args['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -145,17 +141,17 @@ public function testModelBindingOnFieldArgument(): void type Query { user(user: ID! @bind(class: "Tests\\Utils\\Models\\User")): User! @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(user: $id) { id } } - GRAPHQL, - ['id' => $user->getKey()], - ); + GRAPHQL, [ + 'id' => $user->getKey(), + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -168,7 +164,7 @@ public function testModelBindingOnFieldArgument(): void public function testMissingModelBindingOnFieldArgument(): void { - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -176,15 +172,15 @@ public function testMissingModelBindingOnFieldArgument(): void type Query { user(user: ID! @bind(class: "Tests\\Utils\\Models\\User")): User! @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(user: "1") { id } } - GRAPHQL); + GRAPHQL); $response->assertOk(); $response->assertGraphQLValidationError('user', trans('validation.exists', ['attribute' => 'user'])); } @@ -192,7 +188,7 @@ public function testMissingModelBindingOnFieldArgument(): void public function testMissingOptionalModelBindingOnFieldArgument(): void { $this->mockResolver(fn (mixed $root, array $args) => $args['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -202,17 +198,17 @@ public function testMissingOptionalModelBindingOnFieldArgument(): void user: ID! @bind(class: "Tests\\Utils\\Models\\User", required: false) ): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(user: $id) { id } } - GRAPHQL, - ['id' => '1'], - ); + GRAPHQL, [ + 'id' => '1', + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -227,7 +223,7 @@ public function testModelBindingByColumnOnFieldArgument(): void $this->mockResolver(fn (mixed $root, array $args) => $args['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -237,17 +233,17 @@ public function testModelBindingByColumnOnFieldArgument(): void user: String! @bind(class: "Tests\\Utils\\Models\\User", column: "email") ): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($email: String!) { user(user: $email) { id } } - GRAPHQL, - ['email' => $user->email], - ); + GRAPHQL, [ + 'email' => $user->email, + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -269,7 +265,7 @@ public function testModelBindingWithEagerLoadingOnFieldArgument(): void return $args['user']; }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -279,17 +275,17 @@ public function testModelBindingWithEagerLoadingOnFieldArgument(): void user: ID! @bind(class: "Tests\\Utils\\Models\\User", with: ["company"]) ): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(user: $id) { id } } - GRAPHQL, - ['id' => $user->getKey()], - ); + GRAPHQL, [ + 'id' => $user->getKey(), + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -313,7 +309,7 @@ public function testModelBindingWithTooManyResultsOnFieldArgument(): void $user->save(); }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -323,17 +319,17 @@ public function testModelBindingWithTooManyResultsOnFieldArgument(): void user: String! @bind(class: "Tests\\Utils\\Models\\User", column: "name") ): User @mock } - GRAPHQL; + GRAPHQL; - $makeRequest = fn (): TestResponse => $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $makeRequest = fn (): TestResponse => $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($name: String!) { user(user: $name) { id } } - GRAPHQL, - ['name' => $users->first()->name], - ); + GRAPHQL, [ + 'name' => $users->first()->name, + ]); $this->assertThrowsMultipleRecordsFoundException($makeRequest, $users->count()); } @@ -348,7 +344,7 @@ public function testModelCollectionBindingOnFieldArgument(): void return true; }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -358,15 +354,15 @@ public function testModelCollectionBindingOnFieldArgument(): void users: [ID!]! @bind(class: "Tests\\Utils\\Models\\User") ): Boolean! @mock } - GRAPHQL . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($users: [ID!]!) { removeUsers(users: $users) } - GRAPHQL, - ['users' => $users->map(fn (User $user): int => $user->getKey())], - ); + GRAPHQL, [ + 'users' => $users->map(fn (User $user): int => $user->getKey()), + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -385,7 +381,7 @@ public function testMissingModelCollectionBindingOnFieldArgument(): void { $user = factory(User::class)->create(); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -395,17 +391,15 @@ public function testMissingModelCollectionBindingOnFieldArgument(): void users: [ID!]! @bind(class: "Tests\\Utils\\Models\\User") ): Boolean! @mock } - GRAPHQL . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($users: [ID!]!) { removeUsers(users: $users) } - GRAPHQL, - [ - 'users' => [$user->getKey(), '10'], - ], - ); + GRAPHQL, [ + 'users' => [$user->getKey(), '10'], + ]); $response->assertOk(); $response->assertGraphQLValidationError('users.1', trans('validation.exists', ['attribute' => 'users.1'])); } @@ -421,7 +415,7 @@ public function testMissingOptionalModelCollectionBindingOnFieldArgument(): void return true; }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -431,17 +425,15 @@ public function testMissingOptionalModelCollectionBindingOnFieldArgument(): void users: [ID!]! @bind(class: "Tests\\Utils\\Models\\User", required: false) ): Boolean! @mock } - GRAPHQL . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($users: [ID!]!) { removeUsers(users: $users) } - GRAPHQL, - [ - 'users' => [$user->getKey(), '10'], - ], - ); + GRAPHQL, [ + 'users' => [$user->getKey(), '10'], + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -464,7 +456,7 @@ public function testModelCollectionBindingWithTooManyResultsOnFieldArgument(): v $user->save(); }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -474,17 +466,15 @@ public function testModelCollectionBindingWithTooManyResultsOnFieldArgument(): v users: [String!]! @bind(class: "Tests\\Utils\\Models\\User", column: "name") ): Boolean! @mock } - GRAPHQL . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $makeRequest = fn (): TestResponse => $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $makeRequest = fn (): TestResponse => $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($users: [String!]!) { removeUsers(users: $users) } - GRAPHQL, - [ - 'users' => [$users->first()->name], - ], - ); + GRAPHQL, [ + 'users' => [$users->first()->name], + ]); $this->assertThrowsMultipleRecordsFoundException($makeRequest, $users->count()); } @@ -494,7 +484,7 @@ public function testModelBindingOnInputField(): void $this->mockResolver(fn (mixed $root, array $args): User => $args['input']['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -506,21 +496,19 @@ public function testModelBindingOnInputField(): void type Query { user(input: UserInput!): User! @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => $user->getKey(), - ], + GRAPHQL, [ + 'input' => [ + 'user' => $user->getKey(), ], - ); + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -533,7 +521,7 @@ public function testModelBindingOnInputField(): void public function testMissingModelBindingOnInputField(): void { - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -545,21 +533,19 @@ public function testMissingModelBindingOnInputField(): void type Query { user(input: UserInput!): User! @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => '1', - ], + GRAPHQL, [ + 'input' => [ + 'user' => '1', ], - ); + ]); $response->assertOk(); $response->assertGraphQLValidationError('input.user', trans('validation.exists', [ 'attribute' => 'input.user', @@ -570,7 +556,7 @@ public function testMissingOptionalModelBindingOnInputField(): void { $this->mockResolver(fn (mixed $root, array $args) => $args['input']['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -582,21 +568,19 @@ public function testMissingOptionalModelBindingOnInputField(): void type Query { user(input: UserInput!): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => '1', - ], + GRAPHQL, [ + 'input' => [ + 'user' => '1', ], - ); + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -611,7 +595,7 @@ public function testModelBindingByColumnOnInputField(): void $this->mockResolver(fn (mixed $root, array $args) => $args['input']['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -623,21 +607,19 @@ public function testModelBindingByColumnOnInputField(): void type Query { user(input: UserInput!): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => $user->email, - ], + GRAPHQL, [ + 'input' => [ + 'user' => $user->email, ], - ); + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -659,7 +641,7 @@ public function testModelBindingWithEagerLoadingOnInputField(): void return $args['input']['user']; }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -671,21 +653,19 @@ public function testModelBindingWithEagerLoadingOnInputField(): void type Query { user(input: UserInput!): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => $user->getKey(), - ], + GRAPHQL, [ + 'input' => [ + 'user' => $user->getKey(), ], - ); + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -709,7 +689,7 @@ public function testModelBindingWithTooManyResultsOnInputField(): void $user->save(); }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -721,21 +701,19 @@ public function testModelBindingWithTooManyResultsOnInputField(): void type Query { user(input: UserInput!): User @mock } - GRAPHQL; + GRAPHQL; - $makeRequest = fn (): TestResponse => $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $makeRequest = fn (): TestResponse => $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => $users->first()->name, - ], + GRAPHQL, [ + 'input' => [ + 'user' => $users->first()->name, ], - ); + ]); $this->assertThrowsMultipleRecordsFoundException($makeRequest, $users->count()); } @@ -750,7 +728,7 @@ public function testModelCollectionBindingOnInputField(): void return true; }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -762,19 +740,17 @@ public function testModelCollectionBindingOnInputField(): void type Mutation { removeUsers(input: RemoveUsersInput!): Boolean! @mock } - GRAPHQL . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: RemoveUsersInput!) { removeUsers(input: $input) } - GRAPHQL, - [ - 'input' => [ - 'users' => $users->map(fn (User $user): int => $user->getKey()), - ], + GRAPHQL, [ + 'input' => [ + 'users' => $users->map(fn (User $user): int => $user->getKey()), ], - ); + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -794,7 +770,7 @@ public function testMissingModelCollectionBindingOnInputField(): void { $user = factory(User::class)->create(); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -806,19 +782,17 @@ public function testMissingModelCollectionBindingOnInputField(): void type Mutation { removeUsers(input: RemoveUsersInput!): Boolean! @mock } - GRAPHQL . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: RemoveUsersInput!) { removeUsers(input: $input) } - GRAPHQL, - [ - 'input' => [ - 'users' => [$user->getKey(), '10'], - ], + GRAPHQL, [ + 'input' => [ + 'users' => [$user->getKey(), '10'], ], - ); + ]); $response->assertOk(); $response->assertGraphQLValidationError('input.users.1', trans('validation.exists', [ 'attribute' => 'input.users.1', @@ -836,7 +810,7 @@ public function testMissingOptionalModelCollectionBindingOnInputField(): void return true; }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -848,19 +822,17 @@ public function testMissingOptionalModelCollectionBindingOnInputField(): void type Mutation { removeUsers(input: RemoveUsersInput!): Boolean! @mock } - GRAPHQL . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: RemoveUsersInput!) { removeUsers(input: $input) } - GRAPHQL, - [ - 'input' => [ - 'users' => [$user->getKey(), '10'], - ], + GRAPHQL, [ + 'input' => [ + 'users' => [$user->getKey(), '10'], ], - ); + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -884,7 +856,7 @@ public function testModelCollectionBindingWithTooManyResultsOnInputField(): void $user->save(); }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -896,19 +868,17 @@ public function testModelCollectionBindingWithTooManyResultsOnInputField(): void type Mutation { removeUsers(input: RemoveUsersInput!): Boolean! @mock } - GRAPHQL . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $makeRequest = fn (): TestResponse => $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $makeRequest = fn (): TestResponse => $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: RemoveUsersInput!) { removeUsers(input: $input) } - GRAPHQL, - [ - 'input' => [ - 'users' => [$users->first()->name], - ], + GRAPHQL, [ + 'input' => [ + 'users' => [$users->first()->name], ], - ); + ]); $this->assertThrowsMultipleRecordsFoundException($makeRequest, $users->count()); } @@ -919,7 +889,7 @@ public function testCallableClassBindingOnFieldArgument(): void $this->mockResolver(fn (mixed $root, array $args): User => $args['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -927,17 +897,17 @@ public function testCallableClassBindingOnFieldArgument(): void type Query { user(user: ID! @bind(class: "Tests\\Utils\\Bind\\SpyCallableClassBinding")): User! @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(user: $id) { id } } - GRAPHQL, - ['id' => $user->getKey()], - ); + GRAPHQL, [ + 'id' => $user->getKey(), + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -952,7 +922,7 @@ public function testMissingCallableClassBindingOnFieldArgument(): void { $this->instance(SpyCallableClassBinding::class, new SpyCallableClassBinding(null)); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -962,17 +932,17 @@ public function testMissingCallableClassBindingOnFieldArgument(): void user: ID! @bind(class: "Tests\\Utils\\Bind\\SpyCallableClassBinding") ): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(user: $id) { id } } - GRAPHQL, - ['id' => '1'], - ); + GRAPHQL, [ + 'id' => '1', + ]); $response->assertOk(); $response->assertGraphQLValidationError('user', trans('validation.exists', ['attribute' => 'user'])); } @@ -983,7 +953,7 @@ public function testMissingOptionalCallableClassBindingOnFieldArgument(): void $this->mockResolver(fn (mixed $root, array $args) => $args['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -993,17 +963,17 @@ public function testMissingOptionalCallableClassBindingOnFieldArgument(): void user: ID! @bind(class: "Tests\\Utils\\Bind\\SpyCallableClassBinding", required: false) ): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(user: $id) { id } } - GRAPHQL, - ['id' => '1'], - ); + GRAPHQL, [ + 'id' => '1', + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -1019,7 +989,7 @@ public function testCallableClassBindingWithDirectiveArgumentsOnFieldArgument(): $this->mockResolver(fn (mixed $root, array $args) => $args['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -1034,17 +1004,17 @@ class: "Tests\\Utils\\Bind\\SpyCallableClassBinding" ) ): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(user: $id) { id } } - GRAPHQL, - ['id' => '1'], - ); + GRAPHQL, [ + 'id' => '1', + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -1065,7 +1035,7 @@ public function testCallableClassBindingOnInputField(): void $this->mockResolver(fn (mixed $root, array $args): User => $args['input']['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -1077,21 +1047,19 @@ public function testCallableClassBindingOnInputField(): void type Query { user(input: UserInput!): User! @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => $user->getKey(), - ], + GRAPHQL, [ + 'input' => [ + 'user' => $user->getKey(), ], - ); + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -1106,7 +1074,7 @@ public function testMissingCallableClassBindingOnInputField(): void { $this->instance(SpyCallableClassBinding::class, new SpyCallableClassBinding(null)); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -1118,21 +1086,19 @@ public function testMissingCallableClassBindingOnInputField(): void type Query { user(input: UserInput!): User! @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => '1', - ], + GRAPHQL, [ + 'input' => [ + 'user' => '1', ], - ); + ]); $response->assertOk(); $response->assertGraphQLValidationError('input.user', trans('validation.exists', ['attribute' => 'input.user'])); } @@ -1143,7 +1109,7 @@ public function testMissingOptionalCallableClassBindingOnInputField(): void $this->mockResolver(fn (mixed $root, array $args) => $args['input']['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -1155,21 +1121,19 @@ public function testMissingOptionalCallableClassBindingOnInputField(): void type Query { user(input: UserInput!): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => '1', - ], + GRAPHQL, [ + 'input' => [ + 'user' => '1', ], - ); + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ @@ -1185,7 +1149,7 @@ public function testCallableClassBindingWithDirectiveArgumentsOnInputField(): vo $this->mockResolver(fn (mixed $root, array $args) => $args['input']['user']); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -1202,21 +1166,19 @@ class: "Tests\\Utils\\Bind\\SpyCallableClassBinding" type Query { user(input: UserInput!): User @mock } - GRAPHQL; + GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($input: UserInput!) { user(input: $input) { id } } - GRAPHQL, - [ - 'input' => [ - 'user' => '1', - ], + GRAPHQL, [ + 'input' => [ + 'user' => '1', ], - ); + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ @@ -1243,7 +1205,7 @@ public function testMultipleBindingsInSameRequest(): void return true; }); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -1258,18 +1220,16 @@ public function testMultipleBindingsInSameRequest(): void company: ID! @bind(class: "Tests\\Utils\\Models\\Company") ): Boolean! @mock } - GRAPHQL . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($user: ID!, $company: ID!) { addUserToCompany(user: $user, company: $company) } - GRAPHQL, - [ - 'user' => $user->getKey(), - 'company' => $company->getKey(), - ], - ); + GRAPHQL, [ + 'user' => $user->getKey(), + 'company' => $company->getKey(), + ]); $response->assertGraphQLErrorFree(); $response->assertJson([ 'data' => [ diff --git a/tests/Integration/Cache/CacheDirectiveTest.php b/tests/Integration/Cache/CacheDirectiveTest.php index aa0edebd19..cee9be8d4a 100644 --- a/tests/Integration/Cache/CacheDirectiveTest.php +++ b/tests/Integration/Cache/CacheDirectiveTest.php @@ -30,7 +30,7 @@ public function testStoreResolverResultInCache(): void 'name' => 'foobar', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String @cache @@ -39,15 +39,15 @@ public function testStoreResolverResultInCache(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foobar', @@ -60,7 +60,7 @@ public function testStoreResolverResultInCache(): void public function testCacheKeyIsValidOnFieldDefinition(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String @cache @@ -70,7 +70,7 @@ public function testCacheKeyIsValidOnFieldDefinition(): void type Query { user: User @first } - '; + GRAPHQL; $schemaValidator = $this->app->make(SchemaValidator::class); @@ -87,7 +87,7 @@ public function testPlaceCacheKeyOnAnyField(): void 'email' => 'foo@bar.com', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String @cache @@ -97,15 +97,15 @@ public function testPlaceCacheKeyOnAnyField(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foobar', @@ -124,7 +124,7 @@ public function testCacheKeyWithRenameDirective(): void 'email_name' => 'foo@bar.com', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String @cache @@ -134,15 +134,15 @@ public function testCacheKeyWithRenameDirective(): void type Query { user: User @mock } - '; + GRAPHQL; - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foobar', @@ -160,7 +160,7 @@ public function testIDCacheKeyWithRenameDirective(): void 'name' => 'foobar', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! @rename(attribute: "id_") name: String @cache @@ -169,15 +169,15 @@ public function testIDCacheKeyWithRenameDirective(): void type Query { user: User @mock } - '; + GRAPHQL; - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foobar', @@ -199,7 +199,7 @@ public function testStoreResolverResultInPrivateCache(): void 'name' => 'foobar', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String @cache(private: true) @@ -208,15 +208,15 @@ public function testStoreResolverResultInPrivateCache(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foobar', @@ -234,7 +234,7 @@ public function testStoreResolverResultInCacheWhenUsingNodeDirective(): void 'name' => 'foobar', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! } @@ -247,15 +247,15 @@ public function testStoreResolverResultInCacheWhenUsingNodeDirective(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foobar', @@ -273,7 +273,7 @@ public function testFallsBackToPublicCacheIfUserIsNotAuthenticated(): void 'name' => 'foobar', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String @cache(private: true) @@ -282,15 +282,15 @@ public function testFallsBackToPublicCacheIfUserIsNotAuthenticated(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foobar', @@ -305,7 +305,7 @@ public function testStorePaginateResolverInCache(): void { factory(User::class, 5)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -314,9 +314,9 @@ public function testStorePaginateResolverInCache(): void type Query { users: [User] @paginate(type: PAGINATOR, model: "User") @cache } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 5) { paginatorInfo { @@ -328,7 +328,7 @@ public function testStorePaginateResolverInCache(): void } } } - '); + GRAPHQL); $result = $this->cache->get('lighthouse:Query::users:first:5'); @@ -347,7 +347,7 @@ public function testCacheHasManyResolver(): void $post->save(); }); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! title: String @@ -362,9 +362,9 @@ public function testCacheHasManyResolver(): void type Query { user(id: ID! @eq): User @find(model: "User") } - '; + GRAPHQL; - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { id @@ -376,7 +376,7 @@ public function testCacheHasManyResolver(): void } } } - '; + GRAPHQL; $dbQueryCountForPost = 0; DB::listen(static function (QueryExecuted $query) use (&$dbQueryCountForPost): void { @@ -418,7 +418,7 @@ public function testAttachTagsToCache(): void $tags = ['lighthouse:User:1', 'lighthouse:User:1:posts']; - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! title: String @@ -433,9 +433,9 @@ public function testAttachTagsToCache(): void type Query { user(id: ID! @eq): User @find(model: "User") @cache } - '; + GRAPHQL; - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { id @@ -447,7 +447,7 @@ public function testAttachTagsToCache(): void } } } - '; + GRAPHQL; $dbQueryCountForPost = 0; DB::listen(static function (QueryExecuted $query) use (&$dbQueryCountForPost): void { @@ -486,7 +486,7 @@ public function testUseFalsyResultsInCache(): void 'field_integer' => 1, ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! field_boolean: Boolean @cache @@ -497,7 +497,7 @@ public function testUseFalsyResultsInCache(): void type Query { user: User @mock } - '; + GRAPHQL; $this->cache->setMultiple([ 'lighthouse:User:1:field_boolean' => false, @@ -505,7 +505,7 @@ public function testUseFalsyResultsInCache(): void 'lighthouse:User:1:field_integer' => 0, ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { field_boolean @@ -513,7 +513,7 @@ public function testUseFalsyResultsInCache(): void field_integer } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'field_boolean' => false, diff --git a/tests/Integration/Cache/ClearCacheDirectiveTest.php b/tests/Integration/Cache/ClearCacheDirectiveTest.php index a9f62c413c..4313b3fcbf 100644 --- a/tests/Integration/Cache/ClearCacheDirectiveTest.php +++ b/tests/Integration/Cache/ClearCacheDirectiveTest.php @@ -20,11 +20,11 @@ protected function setUp(): void public function testClearCacheForEntireType(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { foo: Int! @clearCache(type: "Foo") } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $taggedCache = $this->cache->tags(['lighthouse:Foo:']); @@ -33,22 +33,22 @@ public function testClearCacheForEntireType(): void $this->assertTrue($taggedCache->has($key)); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { foo } - ')->assertGraphQLErrorFree(); + GRAPHQL)->assertGraphQLErrorFree(); $this->assertFalse($taggedCache->has($key)); } public function testClearCacheForAllFieldsOfType(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { foo: Int! @clearCache(type: "Foo", field: "bar") } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $taggedCache = $this->cache->tags(['lighthouse:Foo::bar']); @@ -57,22 +57,22 @@ public function testClearCacheForAllFieldsOfType(): void $this->assertTrue($taggedCache->has($key)); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { foo } - ')->assertGraphQLErrorFree(); + GRAPHQL)->assertGraphQLErrorFree(); $this->assertFalse($taggedCache->has($key)); } public function testClearCacheForTypeWithIDByArgument(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { foo(id: ID!): Int! @clearCache(type: "Foo", idSource: { argument: "id" }) } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $taggedCache = $this->cache->tags(['lighthouse:Foo:1']); @@ -81,18 +81,18 @@ public function testClearCacheForTypeWithIDByArgument(): void $this->assertTrue($taggedCache->has($key)); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { foo(id: 1) } - ')->assertGraphQLErrorFree(); + GRAPHQL)->assertGraphQLErrorFree(); $this->assertFalse($taggedCache->has($key)); } public function testClearCacheForTypeWithIDByArgumentNestedPath(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' input FooInput { id: ID! } @@ -100,7 +100,7 @@ public function testClearCacheForTypeWithIDByArgumentNestedPath(): void type Mutation { foo(input: FooInput!): Int! @clearCache(type: "Foo", idSource: { argument: "input.id" }) } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $taggedCache = $this->cache->tags(['lighthouse:Foo:1']); @@ -109,11 +109,11 @@ public function testClearCacheForTypeWithIDByArgumentNestedPath(): void $this->assertTrue($taggedCache->has($key)); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { foo(input: { id: 1 }) } - ')->assertGraphQLErrorFree(); + GRAPHQL)->assertGraphQLErrorFree(); $this->assertFalse($taggedCache->has($key)); } @@ -124,7 +124,7 @@ public function testClearCacheForTypeWithIDByField(): void 'bar' => 2, ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo { bar: Int! } @@ -134,7 +134,7 @@ public function testClearCacheForTypeWithIDByField(): void @mock @clearCache(type: "Foo", idSource: { field: "bar" }) } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $taggedCache = $this->cache->tags(['lighthouse:Foo:2']); @@ -143,13 +143,13 @@ public function testClearCacheForTypeWithIDByField(): void $this->assertTrue($taggedCache->has($key)); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { foo { bar } } - ')->assertGraphQLErrorFree(); + GRAPHQL)->assertGraphQLErrorFree(); $this->assertFalse($taggedCache->has($key)); } @@ -166,7 +166,7 @@ public function testClearCacheForMultipleTypesWithIDByField(): void ], ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo { bar: Int! } @@ -176,7 +176,7 @@ public function testClearCacheForMultipleTypesWithIDByField(): void @mock @clearCache(type: "Foo", idSource: { field: "*.bar" }) } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $taggedCache1 = $this->cache->tags(['lighthouse:Foo:1']); $taggedCache2 = $this->cache->tags(['lighthouse:Foo:2']); @@ -188,13 +188,13 @@ public function testClearCacheForMultipleTypesWithIDByField(): void $this->assertTrue($taggedCache1->has($key)); $this->assertTrue($taggedCache2->has($key)); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { foos { bar } } - ')->assertGraphQLErrorFree(); + GRAPHQL)->assertGraphQLErrorFree(); $this->assertFalse($taggedCache1->has($key)); $this->assertFalse($taggedCache2->has($key)); @@ -208,7 +208,7 @@ public function testClearCacheForTypeWithIDByFieldNestedPath(): void ], ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Bar { baz: Int! } @@ -222,7 +222,7 @@ public function testClearCacheForTypeWithIDByFieldNestedPath(): void @mock @clearCache(type: "Foo", idSource: { field: "bar.baz" }) } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $taggedCache = $this->cache->tags(['lighthouse:Foo:3']); @@ -231,7 +231,7 @@ public function testClearCacheForTypeWithIDByFieldNestedPath(): void $this->assertTrue($taggedCache->has($key)); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { foo { bar { @@ -239,18 +239,18 @@ public function testClearCacheForTypeWithIDByFieldNestedPath(): void } } } - ')->assertGraphQLErrorFree(); + GRAPHQL)->assertGraphQLErrorFree(); $this->assertFalse($taggedCache->has($key)); } public function testClearCacheForTypeWithIDByArgumentForField(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { foo(id: ID!): Int! @clearCache(type: "Foo", idSource: { argument: "id" }, field: "baz") } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $taggedCache = $this->cache->tags(['lighthouse:Foo:1:baz']); @@ -259,11 +259,11 @@ public function testClearCacheForTypeWithIDByArgumentForField(): void $this->assertTrue($taggedCache->has($key)); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { foo(id: 1) } - ')->assertGraphQLErrorFree(); + GRAPHQL)->assertGraphQLErrorFree(); $this->assertFalse($taggedCache->has($key)); } diff --git a/tests/Integration/CacheControl/CacheControlDirectiveTest.php b/tests/Integration/CacheControl/CacheControlDirectiveTest.php index 67a0ec4012..5fa6d55c25 100644 --- a/tests/Integration/CacheControl/CacheControlDirectiveTest.php +++ b/tests/Integration/CacheControl/CacheControlDirectiveTest.php @@ -18,7 +18,7 @@ public function testDefaultAppResponseHeader(): void 'name' => 'foobar', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String @@ -27,15 +27,15 @@ public function testDefaultAppResponseHeader(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertHeader('Cache-Control', 'no-cache, private'); + GRAPHQL)->assertHeader('Cache-Control', 'no-cache, private'); } public function testInheritance(): void @@ -44,7 +44,7 @@ public function testInheritance(): void 'id' => 1, ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -52,15 +52,15 @@ public function testInheritance(): void type Query { me: User @mock @cacheControl(maxAge: 5, scope: PRIVATE) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { me { id } } - ')->assertHeader('Cache-Control', 'max-age=5, private'); + GRAPHQL)->assertHeader('Cache-Control', 'max-age=5, private'); } /** @dataProvider rootScalarDataProvider */ @@ -69,12 +69,12 @@ public function testRootScalar(string $query, string $expectedHeaderString): voi { $this->mockResolver(1); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { default: ID @mock withDirective: ID @mock @cacheControl(maxAge: 5) } - '; + GRAPHQL; $this->graphQL($query) ->assertHeader('Cache-Control', $expectedHeaderString); @@ -83,26 +83,26 @@ public function testRootScalar(string $query, string $expectedHeaderString): voi /** @return iterable */ public static function rootScalarDataProvider(): iterable { - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { default } - ', + GRAPHQL, 'no-cache, private', ]; - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { withDirective } - ', + GRAPHQL, 'max-age=5, public', ]; - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { default withDirective } - ', + GRAPHQL, 'no-cache, private', ]; } @@ -114,7 +114,7 @@ public function testInheritanceWithNonScalar(): void 'self' => null, ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! child: User @@ -123,9 +123,9 @@ public function testInheritanceWithNonScalar(): void type Query { me: User @mock @cacheControl(maxAge: 5, scope: PRIVATE) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { me { child { @@ -133,7 +133,7 @@ public function testInheritanceWithNonScalar(): void } } } - ')->assertHeader('Cache-Control', 'no-cache, private'); + GRAPHQL)->assertHeader('Cache-Control', 'no-cache, private'); } /** @dataProvider argumentsDataProvider */ @@ -145,7 +145,7 @@ public function testDirectiveArguments(string $directive, string $expectedHeader 'name' => 'foobar', ]); - $this->schema = /** @lang GraphQL */ " + $this->schema = /** @lang GraphQL */ <<graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertHeader('Cache-Control', $expectedHeaderString); + GRAPHQL)->assertHeader('Cache-Control', $expectedHeaderString); } /** @return iterable */ @@ -180,7 +180,7 @@ public static function argumentsDataProvider(): iterable #[DataProvider('nestedQueryDataProvider')] public function testUseDirectiveNested(string $query, string $expectedHeaderString): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany @cacheControl(maxAge: 50) posts: [Post!]! @hasMany @@ -206,7 +206,7 @@ public function testUseDirectiveNested(string $query, string $expectedHeaderStri team: Team @first @cacheControl teamWithCache: Team @first @cacheControl(maxAge: 20) } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -230,7 +230,7 @@ public function testUseDirectiveNested(string $query, string $expectedHeaderStri /** @return iterable */ public static function nestedQueryDataProvider(): iterable { - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks { @@ -239,10 +239,10 @@ public static function nestedQueryDataProvider(): iterable } } } - ', + GRAPHQL, 'max-age=5, private', ]; - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks { @@ -250,10 +250,10 @@ public static function nestedQueryDataProvider(): iterable } } } - ', + GRAPHQL, 'max-age=5, private', ]; - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { team { users { @@ -263,10 +263,10 @@ public static function nestedQueryDataProvider(): iterable } } } - ', + GRAPHQL, 'no-cache, public', ]; - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { team { users { @@ -276,10 +276,10 @@ public static function nestedQueryDataProvider(): iterable } } } - ', + GRAPHQL, 'no-cache, public', ]; - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { teamWithCache { users { @@ -289,10 +289,10 @@ public static function nestedQueryDataProvider(): iterable } } } - ', + GRAPHQL, 'max-age=20, public', ]; - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { teamWithCache { users { @@ -302,10 +302,10 @@ public static function nestedQueryDataProvider(): iterable } } } - ', + GRAPHQL, 'no-cache, public', ]; - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { teamWithCache { users { @@ -316,14 +316,14 @@ public static function nestedQueryDataProvider(): iterable } } } - ', + GRAPHQL, 'no-cache, private', ]; } public function testUsePaginate(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: PAGINATOR) @cacheControl(maxAge: 50) } @@ -337,7 +337,7 @@ public function testUsePaginate(): void type Query { users: [User] @paginate @cacheControl(maxAge: 5, scope: PRIVATE) } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -345,7 +345,7 @@ public function testUsePaginate(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 10) { paginatorInfo { @@ -361,7 +361,7 @@ public function testUsePaginate(): void } } } - ') + GRAPHQL) ->assertHeader('Cache-Control', 'max-age=5, private'); } @@ -369,7 +369,7 @@ public function testUsePaginate(): void #[DataProvider('typeLevelCacheDataProvider')] public function testTypeLevelCache(string $query, string $expectedHeaderString): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany tasksWithCache: [Task!]! @hasMany(relation: "tasks") @cacheControl(maxAge: 20) @@ -384,7 +384,7 @@ public function testTypeLevelCache(string $query, string $expectedHeaderString): type Query { user: User @first @cacheControl(maxAge: 50, scope: PRIVATE) } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -399,7 +399,7 @@ public function testTypeLevelCache(string $query, string $expectedHeaderString): /** @return iterable */ public static function typeLevelCacheDataProvider(): iterable { - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks { @@ -408,11 +408,11 @@ public static function typeLevelCacheDataProvider(): iterable } } } - ', + GRAPHQL, 'max-age=10, private', ]; - yield [/** @lang GraphQL */ ' + yield [/** @lang GraphQL */ <<<'GRAPHQL' { user { tasksWithCache { @@ -421,7 +421,7 @@ public static function typeLevelCacheDataProvider(): iterable } } } - ', + GRAPHQL, 'max-age=20, private', ]; } diff --git a/tests/Integration/CustomDefaultResolverTest.php b/tests/Integration/CustomDefaultResolverTest.php index a316cba684..f16e40e44f 100644 --- a/tests/Integration/CustomDefaultResolverTest.php +++ b/tests/Integration/CustomDefaultResolverTest.php @@ -15,7 +15,7 @@ public function testSpecifyACustomDefaultResolver(): void 'bar' => 'should not be returned', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Foo @mock } @@ -23,19 +23,19 @@ public function testSpecifyACustomDefaultResolver(): void type Foo { bar: Int } - '; + GRAPHQL; $previous = Executor::getDefaultFieldResolver(); Executor::setDefaultFieldResolver(static fn (): int => self::CUSTOM_RESOLVER_RESULT); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { bar } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => [ 'bar' => self::CUSTOM_RESOLVER_RESULT, diff --git a/tests/Integration/DefaultSchemaTest.php b/tests/Integration/DefaultSchemaTest.php index 79ec0e00fb..9302328c63 100644 --- a/tests/Integration/DefaultSchemaTest.php +++ b/tests/Integration/DefaultSchemaTest.php @@ -48,24 +48,24 @@ public function testPassesValidation(): void public function testFindRequiresExactlyOneArgument(): void { $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { id } } - ') + GRAPHQL) ->assertGraphQLValidationError('email', 'The email field is required when id is not present.') ->assertGraphQLValidationError('id', 'The id field is required when email is not present.'); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: 1, email: "foo@bar.baz") { id } } - ') + GRAPHQL) ->assertGraphQLValidationError('email', 'The email field prohibits id from being present.') ->assertGraphQLValidationError('id', 'The id field prohibits email from being present.'); } @@ -76,13 +76,13 @@ public function testFindById(): void $user = factory(User::class)->create(); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $user->id, ]) ->assertExactJson([ @@ -97,7 +97,7 @@ public function testFindById(): void public function testEmptyUsers(): void { $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { data { @@ -105,7 +105,7 @@ public function testEmptyUsers(): void } } } - ') + GRAPHQL) ->assertExactJson([ 'data' => [ 'users' => [ @@ -121,7 +121,7 @@ public function testAllUsers(): void factory(User::class)->times($amount)->create(); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { data { @@ -129,7 +129,7 @@ public function testAllUsers(): void } } } - ') + GRAPHQL) ->assertJsonCount(2, 'data.users.data'); } @@ -156,7 +156,7 @@ public function testUsersByName(): void private function usersByName(string $name): TestResponse { - return $this->graphQL(/** @lang GraphQL */ ' + return $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($name: String!) { users(name: $name) { data { @@ -164,7 +164,7 @@ private function usersByName(string $name): TestResponse } } } - ', + GRAPHQL, [ 'name' => $name, ], diff --git a/tests/Integration/Defer/DeferDBTest.php b/tests/Integration/Defer/DeferDBTest.php index b111fc0481..47357fcbb1 100644 --- a/tests/Integration/Defer/DeferDBTest.php +++ b/tests/Integration/Defer/DeferDBTest.php @@ -33,7 +33,7 @@ public function testDeferBelongsToFields(): void $this->mockResolver($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { name: String! } @@ -46,11 +46,11 @@ public function testDeferBelongsToFields(): void type Query { user: User @mock } - '; + GRAPHQL; $this->countQueries($queryCount); - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { email @@ -59,7 +59,7 @@ public function testDeferBelongsToFields(): void } } } - '); + GRAPHQL); $this->assertSame(1, $queryCount); $this->assertCount(2, $chunks); @@ -91,7 +91,7 @@ public function testDeferNestedRelationshipFields(): void $this->mockResolver($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { name: String! users: [User] @hasMany @@ -105,11 +105,11 @@ public function testDeferNestedRelationshipFields(): void type Query { user: User @mock } - '; + GRAPHQL; $this->countQueries($queryCount); - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { email @@ -121,7 +121,7 @@ public function testDeferNestedRelationshipFields(): void } } } - '); + GRAPHQL); $this->assertSame(2, $queryCount); $this->assertCount(3, $chunks); @@ -162,7 +162,7 @@ public function testDeferNestedListFields(): void $this->mockResolver($companies); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { name: String! users: [User] @hasMany @@ -176,11 +176,11 @@ public function testDeferNestedListFields(): void type Query { companies: [Company] @mock } - '; + GRAPHQL; $this->countQueries($queryCount); - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { companies { name @@ -192,7 +192,7 @@ public function testDeferNestedListFields(): void } } } - '); + GRAPHQL); $this->assertSame(2, $queryCount); $this->assertCount(3, $chunks); diff --git a/tests/Integration/Defer/DeferIncludeSkipTest.php b/tests/Integration/Defer/DeferIncludeSkipTest.php index f937903ea8..7d82337b96 100644 --- a/tests/Integration/Defer/DeferIncludeSkipTest.php +++ b/tests/Integration/Defer/DeferIncludeSkipTest.php @@ -7,10 +7,10 @@ final class DeferIncludeSkipTest extends TestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' directive @include(if: Boolean!) on FIELD directive @skip(if: Boolean!) on FIELD - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . "\n" . self::PLACEHOLDER_QUERY; protected function getPackageProviders($app): array { @@ -22,33 +22,33 @@ protected function getPackageProviders($app): array public function testDoesNotDeferWithIncludeFalse(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo @defer @include(if: false) } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [], ]); } public function testDoesDeferWithIncludeTrue(): void { - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo @defer @include(if: true) } - '); + GRAPHQL); $this->assertCount(2, $chunks); } public function testDoesNotDeferWithIncludeFalseFromVariable(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($include: Boolean!) { foo @defer @include(if: $include) } - ', [ + GRAPHQL, [ 'include' => false, ])->assertExactJson([ 'data' => [], @@ -57,33 +57,33 @@ public function testDoesNotDeferWithIncludeFalseFromVariable(): void public function testDoesNotDeferWithSkipTrue(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo @defer @skip(if: true) } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [], ]); } public function testDoesDeferWithSkipFalse(): void { - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo @defer @skip(if: false) } - '); + GRAPHQL); $this->assertCount(2, $chunks); } public function testDoesNotDeferWithSkipTrueFromVariable(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($skip: Boolean!) { foo @defer @skip(if: $skip) } - ', [ + GRAPHQL, [ 'skip' => true, ])->assertExactJson([ 'data' => [], diff --git a/tests/Integration/Defer/DeferTest.php b/tests/Integration/Defer/DeferTest.php index 5e90c9b6a0..44a603dc6d 100644 --- a/tests/Integration/Defer/DeferTest.php +++ b/tests/Integration/Defer/DeferTest.php @@ -28,7 +28,7 @@ protected function getPackageProviders($app): array public function testAddsTheDeferClientDirective(): void { - $introspection = $this->graphQL(/** @lang GraphQL */ ' + $introspection = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query IntrospectionQuery { __schema { directives { @@ -36,7 +36,7 @@ public function testAddsTheDeferClientDirective(): void } } } - '); + GRAPHQL); $this->assertContains( 'defer', @@ -53,7 +53,7 @@ public function testDeferFields(): void ], ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User @@ -62,9 +62,9 @@ public function testDeferFields(): void type Query { user: User @mock } - '; + GRAPHQL; - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name @@ -73,7 +73,7 @@ public function testDeferFields(): void } } } - '); + GRAPHQL); $this->assertSame( [ @@ -110,7 +110,7 @@ public function testDeferNestedFields(): void ]; $this->mockResolver($data); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User @@ -119,9 +119,9 @@ public function testDeferNestedFields(): void type Query { user: User @mock } - '; + GRAPHQL; - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name @@ -133,7 +133,7 @@ public function testDeferNestedFields(): void } } } - '); + GRAPHQL); $this->assertCount(3, $chunks); @@ -160,7 +160,7 @@ public function testDeferNestedFieldsOnMutations(): void ], ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User @@ -173,9 +173,9 @@ public function testDeferNestedFieldsOnMutations(): void type Mutation { updateUser(name: String!): User @mock } - '; + GRAPHQL; - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser( name: "Foo" @@ -186,7 +186,7 @@ public function testDeferNestedFieldsOnMutations(): void } } } - '); + GRAPHQL); $this->assertSame( [ @@ -228,7 +228,7 @@ public function testDeferListFields(): void ]; $this->mockResolver($data); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { title: String author: User @@ -241,9 +241,9 @@ public function testDeferListFields(): void type Query { posts: [Post] @mock } - '; + GRAPHQL; - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts { title @@ -252,7 +252,7 @@ public function testDeferListFields(): void } } } - '); + GRAPHQL); $this->assertCount(2, $chunks); @@ -290,7 +290,7 @@ public function testDeferGroupedListFields(): void ]; $this->mockResolver($data); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Comment { message: String } @@ -308,9 +308,9 @@ public function testDeferGroupedListFields(): void type Query { posts: [Post] @mock } - '; + GRAPHQL; - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts { title @@ -322,7 +322,7 @@ public function testDeferGroupedListFields(): void } } } - '); + GRAPHQL); $this->assertCount(2, $chunks); @@ -357,7 +357,7 @@ public function testCancelsDefermentAfterMaxExecutionTime(): void ]; $this->mockResolver($data); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User @@ -366,14 +366,14 @@ public function testCancelsDefermentAfterMaxExecutionTime(): void type Query { user: User @mock } - '; + GRAPHQL; $defer = $this->app->make(Defer::class); // Set max execution time to now so we immediately resolve deferred fields $defer->setMaxExecutionTime(microtime(true)); - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name @@ -385,7 +385,7 @@ public function testCancelsDefermentAfterMaxExecutionTime(): void } } } - '); + GRAPHQL); // If we didn't hit the max execution time we would have 3 items in the array $this->assertCount(2, $chunks); @@ -413,7 +413,7 @@ public function testCancelsDefermentAfterMaxNestedFields(): void ]; $this->mockResolver($data); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User @@ -422,13 +422,13 @@ public function testCancelsDefermentAfterMaxNestedFields(): void type Query { user: User @mock } - '; + GRAPHQL; $defer = $this->app->make(Defer::class); $defer->setMaxNestedFields(1); - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name @@ -440,7 +440,7 @@ public function testCancelsDefermentAfterMaxNestedFields(): void } } } - '); + GRAPHQL); $this->assertCount(2, $chunks); @@ -463,7 +463,7 @@ public function testThrowsExceptionOnNunNullableFields(): void ], ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User! @@ -472,9 +472,9 @@ public function testThrowsExceptionOnNunNullableFields(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name @@ -483,7 +483,7 @@ public function testThrowsExceptionOnNunNullableFields(): void } } } - ')->assertGraphQLErrorMessage(DeferrableDirective::THE_DEFER_DIRECTIVE_CANNOT_BE_USED_ON_A_NON_NULLABLE_FIELD); + GRAPHQL)->assertGraphQLErrorMessage(DeferrableDirective::THE_DEFER_DIRECTIVE_CANNOT_BE_USED_ON_A_NON_NULLABLE_FIELD); } public function testDoesNotDeferWithIncludeAndSkipDirectives(): void @@ -496,7 +496,7 @@ public function testDoesNotDeferWithIncludeAndSkipDirectives(): void 'skipped', ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' directive @include(if: Boolean!) on FIELD directive @skip(if: Boolean!) on FIELD @@ -508,9 +508,9 @@ public function testDoesNotDeferWithIncludeAndSkipDirectives(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name @@ -519,7 +519,7 @@ public function testDoesNotDeferWithIncludeAndSkipDirectives(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'user' => [ 'name' => 'John Doe', @@ -527,7 +527,7 @@ public function testDoesNotDeferWithIncludeAndSkipDirectives(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($include: Boolean!, $skip: Boolean!) { userInclude: user { name @@ -554,7 +554,7 @@ public function testDoesNotDeferWithIncludeAndSkipDirectives(): void } } } - ', [ + GRAPHQL, [ 'include' => false, 'skip' => true, ])->assertExactJson([ @@ -585,7 +585,7 @@ public function testRequiresDeferDirectiveOnAllFieldDeclarations(): void ]; $this->mockResolver($data); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User @@ -594,9 +594,9 @@ public function testRequiresDeferDirectiveOnAllFieldDeclarations(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' fragment UserWithParent on User { name parent { @@ -611,7 +611,7 @@ public function testRequiresDeferDirectiveOnAllFieldDeclarations(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => $data, ], @@ -624,7 +624,7 @@ public function testThrowsIfTryingToDeferRootMutationFields(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User @@ -633,15 +633,15 @@ public function testThrowsIfTryingToDeferRootMutationFields(): void type Mutation { updateUser(name: String!): User @mock } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation UpdateUser { updateUser(name: "John Doe") @defer { name } } - ')->assertGraphQLErrorMessage(DeferrableDirective::THE_DEFER_DIRECTIVE_CANNOT_BE_USED_ON_A_ROOT_MUTATION_FIELD); + GRAPHQL)->assertGraphQLErrorMessage(DeferrableDirective::THE_DEFER_DIRECTIVE_CANNOT_BE_USED_ON_A_ROOT_MUTATION_FIELD); } public function testDoesNotDeferFieldsIfFalse(): void @@ -654,7 +654,7 @@ public function testDoesNotDeferFieldsIfFalse(): void ]; $this->mockResolver($data); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User @@ -663,9 +663,9 @@ public function testDoesNotDeferFieldsIfFalse(): void type Query { user: User @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name @@ -674,7 +674,7 @@ public function testDoesNotDeferFieldsIfFalse(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => $data, ], @@ -695,7 +695,7 @@ public function testIncludesErrorsForDeferredFields(): void 'throw', ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! parent: User @mock(key: "throw") @@ -704,9 +704,9 @@ public function testIncludesErrorsForDeferredFields(): void type Query { user: User @mock } - '; + GRAPHQL; - $chunks = $this->streamGraphQL(/** @lang GraphQL */ ' + $chunks = $this->streamGraphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name @@ -715,7 +715,7 @@ public function testIncludesErrorsForDeferredFields(): void } } } - '); + GRAPHQL); $this->assertCount(2, $chunks); diff --git a/tests/Integration/ErrorHandlersTest.php b/tests/Integration/ErrorHandlersTest.php index c86f2fc4c4..de5dd173cc 100644 --- a/tests/Integration/ErrorHandlersTest.php +++ b/tests/Integration/ErrorHandlersTest.php @@ -17,17 +17,17 @@ public function testErrorHandlerReturningNull(): void throw new \Exception(); }); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => null, ], diff --git a/tests/Integration/ErrorTest.php b/tests/Integration/ErrorTest.php index ab42c1af2c..d137aa26ef 100644 --- a/tests/Integration/ErrorTest.php +++ b/tests/Integration/ErrorTest.php @@ -31,18 +31,19 @@ public function testRejectsEmptyRequest(): void public function testRejectsEmptyQuery(): void { - $this->graphQL('') + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + GRAPHQL) ->assertStatus(200) ->assertGraphQLErrorMessage('GraphQL Request must include at least one of those two parameters: "query" or "queryId"'); } public function testRejectsInvalidQuery(): void { - $result = $this->graphQL(/** @lang GraphQL */ ' - { - nonExistingField - } - '); + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + nonExistingField + } + GRAPHQL); $result->assertStatus(200); $this->assertStringContainsString( @@ -61,17 +62,17 @@ public function testReturnsFullGraphQLError(bool $parseSourceLocations): void $message = 'some error'; $this->mockResolver(static fn (): Error => new Error($message)); - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: ID @mock - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: ID @mock + } + GRAPHQL; $response = $this ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' - { - foo - } + { + foo + } GRAPHQL) ->assertStatus(200) ->assertJson([ @@ -108,7 +109,9 @@ public function testIgnoresInvalidJSONVariables(): void { $this ->postGraphQL([ - 'query' => /** @lang GraphQL */ '{}', + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' + {} + GRAPHQL, 'variables' => '{}', ]) ->assertStatus(200); @@ -119,18 +122,18 @@ public function testHandlesErrorInResolver(): void $message = 'foo'; $this->mockResolver(static fn () => throw new Error($message)); - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: ID @mock - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: ID @mock + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL) ->assertStatus(200) ->assertJson([ 'data' => [ @@ -151,50 +154,50 @@ public function testRethrowsInternalExceptions(): void $this->mockResolver(static fn () => throw new \Exception('foo')); - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: ID @mock - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: ID @mock + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL) ->assertStatus(200) ->assertJsonCount(1, 'errors'); $config->set('lighthouse.debug', DebugFlag::RETHROW_INTERNAL_EXCEPTIONS); $this->expectException(\Exception::class); - $this->graphQL(/** @lang GraphQL */ ' - { - foo - } - '); + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL); } public function testReturnsMultipleErrors(): void { - $this->schema = /** @lang GraphQL */ ' - input TestInput { - string: String! - integer: Int! - } - - type Query { - foo(input: TestInput): ID - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + input TestInput { + string: String! + integer: Int! + } + + type Query { + foo(input: TestInput): ID + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo(input: {}) - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo(input: {}) + } + GRAPHQL) ->assertStatus(200) ->assertGraphQLErrorMessage('Field TestInput.string of required type String! was not provided.') ->assertGraphQLErrorMessage('Field TestInput.integer of required type Int! was not provided.'); @@ -205,12 +208,12 @@ public function testSplitsErrorsForMultipleOperations(): void $config = $this->app->make(ConfigRepository::class); $config->set('lighthouse.debug', DebugFlag::INCLUDE_DEBUG_MESSAGE); - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: Int - bar: String - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: Int + bar: String + } + GRAPHQL; $dispatcher = $this->app->make(EventsDispatcher::class); $dispatcher->listen( @@ -221,19 +224,19 @@ public function testSplitsErrorsForMultipleOperations(): void $this ->postGraphQL([ [ - 'query' => /** @lang GraphQL */ ' - query Foo { - foo - } - ', + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' + query Foo { + foo + } + GRAPHQL, 'operationName' => 'Foo', ], [ - 'query' => /** @lang GraphQL */ ' - query Bar { - bar - } - ', + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' + query Bar { + bar + } + GRAPHQL, 'operationName' => 'Bar', ], ]) @@ -274,19 +277,19 @@ public function testReturnsPartialDataIfNullableFieldFails(): void $error = new \Exception('fail'); $this->mockResolver(static fn () => throw $error, 'fail'); - $this->schema = /** @lang GraphQL */ ' - type Query { - success: Int! @mock(key: "success") - fail: Int @mock(key: "fail") - } - '; - - $this->graphQL(/** @lang GraphQL */ ' - { - success - fail - } - ') + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + success: Int! @mock(key: "success") + fail: Int @mock(key: "fail") + } + GRAPHQL; + + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + success + fail + } + GRAPHQL) ->assertStatus(200) ->assertJson([ 'data' => [ @@ -308,19 +311,19 @@ public function testReturnsNoDataIfNonNullableFieldFails(): void $error = new \Exception('fail'); $this->mockResolver(static fn () => throw $error, 'fail'); - $this->schema = /** @lang GraphQL */ ' - type Query { - success: Int! @mock(key: "success") - fail: Int! @mock(key: "fail") - } - '; - - $this->graphQL(/** @lang GraphQL */ ' - { - success - fail - } - ') + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + success: Int! @mock(key: "success") + fail: Int! @mock(key: "fail") + } + GRAPHQL; + + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + success + fail + } + GRAPHQL) ->assertStatus(200) ->assertJsonMissingPath('data') ->assertGraphQLError($error); @@ -328,18 +331,18 @@ public function testReturnsNoDataIfNonNullableFieldFails(): void public function testUnknownTypeInVariableDefinition(): void { - $this->schema = /** @lang GraphQL */ ' - type Query { - foo(bar: ID): ID - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo(bar: ID): ID + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - query ($bar: UnknownType) { - foo(bar: $bar) - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + query ($bar: UnknownType) { + foo(bar: $bar) + } + GRAPHQL) ->assertGraphQLErrorMessage('Unknown type "UnknownType".'); } @@ -352,18 +355,18 @@ public function testAssertGraphQLDebugMessage(): void $this->mockResolver(static fn () => throw new \Exception($message)); - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: ID @mock - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: ID @mock + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL) ->assertStatus(200) /** @see FormattedError::$internalErrorMessage */ ->assertGraphQLErrorMessage('Internal server error') @@ -376,18 +379,18 @@ public function testAssertGraphQLErrorClientSafe(): void $this->mockResolver(static fn () => throw $error); - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: ID @mock - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: ID @mock + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL) ->assertStatus(200) ->assertGraphQLError($error); } @@ -401,18 +404,18 @@ public function testAssertGraphQLErrorNonClientSafe(): void $this->mockResolver(static fn () => throw $exception); - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: ID @mock - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: ID @mock + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL) ->assertStatus(200) /** @see FormattedError::$internalErrorMessage */ ->assertGraphQLErrorMessage('Internal server error') diff --git a/tests/Integration/Events/FieldDirective.php b/tests/Integration/Events/FieldDirective.php index 3525b84d8a..e46ffb5e19 100644 --- a/tests/Integration/Events/FieldDirective.php +++ b/tests/Integration/Events/FieldDirective.php @@ -9,10 +9,10 @@ final class FieldDirective extends BaseDirective public static function definition(): string { return /** @lang GraphQL */ <<<'GRAPHQL' -""" -An alternate @field. -""" -directive @field on FIELD_DEFINITION -GRAPHQL; + """ + An alternate @field. + """ + directive @field on FIELD_DEFINITION + GRAPHQL; } } diff --git a/tests/Integration/Execution/ArgBuilderDirectiveTest.php b/tests/Integration/Execution/ArgBuilderDirectiveTest.php index aae8966fee..1bb3ded777 100644 --- a/tests/Integration/Execution/ArgBuilderDirectiveTest.php +++ b/tests/Integration/Execution/ArgBuilderDirectiveTest.php @@ -8,19 +8,19 @@ final class ArgBuilderDirectiveTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String email: String } - '; + GRAPHQL; public function testAttachNeqFilterToQuery(): void { $users = factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -28,19 +28,19 @@ public function testAttachNeqFilterToQuery(): void type Query { users(id: ID @neq): [User!]! @all } - '; + GRAPHQL; $user = $users->first(); $this->assertInstanceOf(User::class, $user); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID) { users(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $user->id, ]) ->assertJsonCount(2, 'data.users'); @@ -56,7 +56,7 @@ public function testAttachInFilterToQuery(): void $user2 = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user2); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -64,16 +64,16 @@ public function testAttachInFilterToQuery(): void type Query { users(include: [Int] @in(key: "id")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($ids: [Int]) { users(include: $ids) { id } } - ', [ + GRAPHQL, [ 'ids' => [ $user1->id, $user2->id, @@ -92,7 +92,7 @@ public function testAttachNotInFilterToQuery(): void $user2 = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user2); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -100,16 +100,16 @@ public function testAttachNotInFilterToQuery(): void type Query { users(exclude: [Int] @notIn(key: "id")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($ids: [Int]) { users(exclude: $ids) { id } } - ', [ + GRAPHQL, [ 'ids' => [ $user1->id, $user2->id, @@ -122,7 +122,7 @@ public function testAttachWhereFilterToQuery(): void { $users = factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -130,19 +130,19 @@ public function testAttachWhereFilterToQuery(): void type Query { users(id: Int @where(operator: ">")): [User!]! @all } - '; + GRAPHQL; $user = $users->first(); $this->assertInstanceOf(User::class, $user); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($userId: Int) { users(id: $userId) { id } } - ', [ + GRAPHQL, [ 'userId' => $user->id, ]) ->assertJsonCount(2, 'data.users'); @@ -152,7 +152,7 @@ public function testAttachTwoWhereFilterWithTheSameKeyToQuery(): void { factory(User::class, 5)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -163,9 +163,9 @@ public function testAttachTwoWhereFilterWithTheSameKeyToQuery(): void end: Int @where(key: "id", operator: "<") ): [User!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( start: 1 @@ -174,12 +174,12 @@ public function testAttachTwoWhereFilterWithTheSameKeyToQuery(): void id } } - ')->assertJsonCount(3, 'data.users'); + GRAPHQL)->assertJsonCount(3, 'data.users'); } public function testAttachWhereBetweenFilterToQuery(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -189,7 +189,7 @@ public function testAttachWhereBetweenFilterToQuery(): void createdBetween: [String!]! @whereBetween(key: "created_at") ): [User!]! @all } - '; + GRAPHQL; factory(User::class, 2)->create(); @@ -198,7 +198,7 @@ public function testAttachWhereBetweenFilterToQuery(): void $user->created_at = now()->subDay(); $user->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($between: [String!]!) { users( createdBetween: $between @@ -206,7 +206,7 @@ public function testAttachWhereBetweenFilterToQuery(): void id } } - ', [ + GRAPHQL, [ 'between' => [ now()->subDay()->startOfDay()->format('Y-m-d H:i:s'), now()->subDay()->endOfDay()->format('Y-m-d H:i:s'), @@ -216,7 +216,7 @@ public function testAttachWhereBetweenFilterToQuery(): void public function testUseInputObjectsForWhereBetweenFilter(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Query { users( created: TimeRange @whereBetween(key: "created_at") @@ -227,7 +227,7 @@ public function testUseInputObjectsForWhereBetweenFilter(): void start: String! end: String! } - '; + GRAPHQL; factory(User::class, 2)->create(); @@ -236,7 +236,7 @@ public function testUseInputObjectsForWhereBetweenFilter(): void $user->created_at = now()->subDay(); $user->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($start: String!, $end: String!) { users( created: { @@ -247,7 +247,7 @@ public function testUseInputObjectsForWhereBetweenFilter(): void id } } - ', [ + GRAPHQL, [ 'start' => now()->subDay()->startOfDay()->format('Y-m-d H:i:s'), 'end' => now()->subDay()->endOfDay()->format('Y-m-d H:i:s'), ])->assertJsonCount(1, 'data.users'); @@ -255,13 +255,13 @@ public function testUseInputObjectsForWhereBetweenFilter(): void public function testAttachWhereNotBetweenFilterToQuery(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Query { users( notCreatedBetween: [String!]! @whereNotBetween(key: "created_at") ): [User!]! @all } - '; + GRAPHQL; factory(User::class, 2)->create(); @@ -270,7 +270,7 @@ public function testAttachWhereNotBetweenFilterToQuery(): void $user->created_at = now()->subDay(); $user->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($between: [String!]!) { users( notCreatedBetween: $between @@ -278,7 +278,7 @@ public function testAttachWhereNotBetweenFilterToQuery(): void id } } - ', [ + GRAPHQL, [ 'between' => [ now()->subDay()->startOfDay()->format('Y-m-d H:i:s'), now()->subDay()->endOfDay()->format('Y-m-d H:i:s'), @@ -288,13 +288,13 @@ public function testAttachWhereNotBetweenFilterToQuery(): void public function testAttachWhereClauseFilterToQuery(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Query { users( created_at: String! @where(clause: "whereYear") ): [User!]! @all } - '; + GRAPHQL; factory(User::class, 2)->create(); @@ -305,68 +305,68 @@ public function testAttachWhereClauseFilterToQuery(): void $user->created_at = $oneYearAgo; $user->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($created_at: String!) { users(created_at: $created_at) { id } } - ', [ + GRAPHQL, [ 'created_at' => $oneYearAgo->format('Y'), ])->assertJsonCount(1, 'data.users'); } public function testOnlyProcessesFilledArguments(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Query { users( id: ID @eq name: String @where(operator: "like") ): [User!]! @all } - '; + GRAPHQL; $users = factory(User::class, 3)->create(); $user = $users->first(); $this->assertInstanceOf(User::class, $user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($name: String) { users(name: $name) { id } } - ', [ + GRAPHQL, [ 'name' => $user->name, ])->assertJsonCount(1, 'data.users'); } public function testDoesNotProcessUnusedVariable(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Query { users( ids: [ID!] @in ): [User!]! @all } - '; + GRAPHQL; factory(User::class, 3)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($ids: [ID!]) { users(ids: $ids) { id } } - ')->assertJsonCount(3, 'data.users'); + GRAPHQL)->assertJsonCount(3, 'data.users'); } public function testAttachMultipleWhereFiltersToQuery(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { posts( content: String @@ -378,7 +378,7 @@ public function testAttachMultipleWhereFiltersToQuery(): void type Post { id: Int! } - '; + GRAPHQL; $content = 'foo'; @@ -399,13 +399,13 @@ public function testAttachMultipleWhereFiltersToQuery(): void $titleAndBody->save(); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($content: String) { posts(content: $content) { id } } - ', [ + GRAPHQL, [ 'content' => $content, ]) ->assertExactJson([ diff --git a/tests/Integration/Execution/DataLoader/RelationBatchLoaderTest.php b/tests/Integration/Execution/DataLoader/RelationBatchLoaderTest.php index be3066f249..5d7eff84dc 100644 --- a/tests/Integration/Execution/DataLoader/RelationBatchLoaderTest.php +++ b/tests/Integration/Execution/DataLoader/RelationBatchLoaderTest.php @@ -17,7 +17,7 @@ final class RelationBatchLoaderTest extends DBTestCase { public function testResolveBatchedFieldsFromBatchedRequests(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID } @@ -29,7 +29,7 @@ public function testResolveBatchedFieldsFromBatchedRequests(): void type Query { user(id: ID! @eq): User @find } - '; + GRAPHQL; $userCount = 2; $tasksPerUser = 3; @@ -41,7 +41,7 @@ public function testResolveBatchedFieldsFromBatchedRequests(): void ); }); - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' query User($id: ID!) { user(id: $id) { tasks { @@ -49,7 +49,7 @@ public function testResolveBatchedFieldsFromBatchedRequests(): void } } } - '; + GRAPHQL; $this ->postGraphQL([ @@ -75,7 +75,7 @@ public function testResolveBatchedFieldsFromBatchedRequests(): void #[DataProvider('batchloadRelationsSetting')] public function testBatchloadRelations(bool $batchloadRelations, int $expectedQueryCount): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID } @@ -87,7 +87,7 @@ public function testBatchloadRelations(bool $batchloadRelations, int $expectedQu type Query { users: [User!]! @all } - '; + GRAPHQL; $userCount = 2; $tasksPerUser = 3; @@ -103,7 +103,7 @@ public function testBatchloadRelations(bool $batchloadRelations, int $expectedQu $this->assertQueryCountMatches($expectedQueryCount, function () use ($userCount, $tasksPerUser): void { $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { tasks { @@ -111,7 +111,7 @@ public function testBatchloadRelations(bool $batchloadRelations, int $expectedQu } } } - ') + GRAPHQL) ->assertJsonCount($userCount, 'data.users') ->assertJsonCount($tasksPerUser, 'data.users.0.tasks') ->assertJsonCount($tasksPerUser, 'data.users.1.tasks'); @@ -120,7 +120,7 @@ public function testBatchloadRelations(bool $batchloadRelations, int $expectedQu public function testDoesNotBatchloadRelationsWithDifferentDatabaseConnections(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type AlternateConnection { id: ID } @@ -132,7 +132,7 @@ public function testDoesNotBatchloadRelationsWithDifferentDatabaseConnections(): type Query { users: [User!]! @all } - '; + GRAPHQL; $userCount = 2; $alternateConnectionsPerUser = 3; @@ -147,7 +147,7 @@ public function testDoesNotBatchloadRelationsWithDifferentDatabaseConnections(): $this->countQueries($queryCount); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { alternateConnections { @@ -155,7 +155,7 @@ public function testDoesNotBatchloadRelationsWithDifferentDatabaseConnections(): } } } - ') + GRAPHQL) ->assertJsonCount($userCount, 'data.users') ->assertJsonCount($alternateConnectionsPerUser, 'data.users.0.alternateConnections') ->assertJsonCount($alternateConnectionsPerUser, 'data.users.1.alternateConnections'); @@ -165,7 +165,7 @@ public function testDoesNotBatchloadRelationsWithDifferentDatabaseConnections(): public function testDoesNotBatchloadRelationsWithNullDatabaseConnections(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type NullConnection { users: [User!]! @hasMany } @@ -177,7 +177,7 @@ public function testDoesNotBatchloadRelationsWithNullDatabaseConnections(): void type Query { nullConnections: [NullConnection!]! @all } - '; + GRAPHQL; $nullConnectionsCount = 2; $usersPerNullConnection = 3; @@ -193,7 +193,7 @@ public function testDoesNotBatchloadRelationsWithNullDatabaseConnections(): void $this->assertQueryCountMatches(2, function () use ($nullConnectionsCount, $usersPerNullConnection): void { $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { nullConnections { users { @@ -201,7 +201,7 @@ public function testDoesNotBatchloadRelationsWithNullDatabaseConnections(): void } } } - ') + GRAPHQL) ->assertJsonCount($nullConnectionsCount, 'data.nullConnections') ->assertJsonCount($usersPerNullConnection, 'data.nullConnections.0.users') ->assertJsonCount($usersPerNullConnection, 'data.nullConnections.1.users'); @@ -217,7 +217,7 @@ public static function batchloadRelationsSetting(): iterable public function testCombineEagerLoadsThatAreTheSame(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID } @@ -230,12 +230,12 @@ public function testCombineEagerLoadsThatAreTheSame(): void type Query { users: [User!]! @all } - '; + GRAPHQL; factory(User::class, 2)->create(); $this->assertQueryCountMatches(2, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { tasks { @@ -243,21 +243,21 @@ public function testCombineEagerLoadsThatAreTheSame(): void } } } - '); + GRAPHQL); }); $this->assertQueryCountMatches(2, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { name } } - '); + GRAPHQL); }); $this->assertQueryCountMatches(2, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { name @@ -266,13 +266,13 @@ public function testCombineEagerLoadsThatAreTheSame(): void } } } - '); + GRAPHQL); }); } public function testSplitsEagerLoadsByScopes(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID } @@ -285,12 +285,12 @@ public function testSplitsEagerLoadsByScopes(): void type Query { users: [User!]! @all } - '; + GRAPHQL; factory(User::class, 2)->create(); $this->assertQueryCountMatches(3, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { name @@ -299,13 +299,13 @@ public function testSplitsEagerLoadsByScopes(): void } } } - '); + GRAPHQL); }); } public function testSplitsEagerLoadsWithArguments(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID } @@ -318,12 +318,12 @@ public function testSplitsEagerLoadsWithArguments(): void type Query { users: [User!]! @all } - '; + GRAPHQL; factory(User::class, 2)->create(); $this->assertQueryCountMatches(3, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { name @@ -332,13 +332,13 @@ public function testSplitsEagerLoadsWithArguments(): void } } } - '); + GRAPHQL); }); } public function testTwoBatchLoadedQueriesWithDifferentResults(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID } @@ -350,7 +350,7 @@ public function testTwoBatchLoadedQueriesWithDifferentResults(): void type Query { user(id: ID! @eq): User @find } - '; + GRAPHQL; factory(User::class, 2) ->create() @@ -361,7 +361,7 @@ public function testTwoBatchLoadedQueriesWithDifferentResults(): void }); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: 1) { tasks { @@ -369,7 +369,7 @@ public function testTwoBatchLoadedQueriesWithDifferentResults(): void } } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'user' => [ @@ -389,7 +389,7 @@ public function testTwoBatchLoadedQueriesWithDifferentResults(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: 2) { tasks { @@ -397,7 +397,7 @@ public function testTwoBatchLoadedQueriesWithDifferentResults(): void } } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'user' => [ @@ -420,7 +420,7 @@ public function testTwoBatchLoadedQueriesWithDifferentResults(): void /** @return never */ public function testCombineEagerLoadsThatAreTheSameRecursively(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { task(id: Int! @eq): Task @find } @@ -437,7 +437,7 @@ public function testCombineEagerLoadsThatAreTheSameRecursively(): void type User { id: ID! } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -456,7 +456,7 @@ public function testCombineEagerLoadsThatAreTheSameRecursively(): void $this->countQueries($queryCount); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: Int!) { task(id: $id) { name @@ -467,7 +467,7 @@ public function testCombineEagerLoadsThatAreTheSameRecursively(): void } } } - ', [ + GRAPHQL, [ 'id' => $task->id, ]) ->assertJson([ @@ -491,7 +491,7 @@ public function testCombineEagerLoadsThatAreTheSameRecursively(): void public function testBatchLoaderWithExpiredCacheEntry(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { posts: [Post!]! @all @cache(maxAge: 20) } @@ -509,7 +509,7 @@ public function testBatchLoaderWithExpiredCacheEntry(): void type User { id: ID! } - '; + GRAPHQL; $user1 = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user1); @@ -539,7 +539,7 @@ public function testBatchLoaderWithExpiredCacheEntry(): void $comment->save(); } - $firstRequest = $this->graphQL(/** @lang GraphQL */ ' + $firstRequest = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query { posts { comments { @@ -549,7 +549,7 @@ public function testBatchLoaderWithExpiredCacheEntry(): void } } } - '); + GRAPHQL); Cache::forget( (new CacheKeyAndTagsGenerator())->key( @@ -563,7 +563,7 @@ public function testBatchLoaderWithExpiredCacheEntry(): void ), ); - $secondRequest = $this->graphQL(/** @lang GraphQL */ ' + $secondRequest = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query { posts { comments { @@ -573,7 +573,7 @@ public function testBatchLoaderWithExpiredCacheEntry(): void } } } - '); + GRAPHQL); $this->assertSame($firstRequest->json(), $secondRequest->json()); } diff --git a/tests/Integration/Execution/DataLoader/RelationCountBatchLoaderTest.php b/tests/Integration/Execution/DataLoader/RelationCountBatchLoaderTest.php index 2473edd9b5..d5d2d96dc5 100644 --- a/tests/Integration/Execution/DataLoader/RelationCountBatchLoaderTest.php +++ b/tests/Integration/Execution/DataLoader/RelationCountBatchLoaderTest.php @@ -20,7 +20,7 @@ public function testResolveBatchedCountsFromBatchedRequests(): void }); }); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID name: String @@ -37,15 +37,15 @@ public function testResolveBatchedCountsFromBatchedRequests(): void user(id: ID! @eq): User @find users: [User!]! @all } - '; + GRAPHQL; - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { tasks_count } } - '; + GRAPHQL; $this ->postGraphQL([ diff --git a/tests/Integration/Execution/FieldBuilderDirectiveTest.php b/tests/Integration/Execution/FieldBuilderDirectiveTest.php index b236351053..2ad8a1a898 100644 --- a/tests/Integration/Execution/FieldBuilderDirectiveTest.php +++ b/tests/Integration/Execution/FieldBuilderDirectiveTest.php @@ -9,21 +9,21 @@ final class FieldBuilderDirectiveTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: Int! } - '; + GRAPHQL; public function testLimitPostByAuthenticatedUser(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Query { posts: [Post!]! @all @whereAuth(relation: "user") } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -36,13 +36,13 @@ public function testLimitPostByAuthenticatedUser(): void $this->be($user); - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query { posts { id } } - '); + GRAPHQL); $this->assertSame( $ownedPosts->pluck('id')->all(), @@ -52,7 +52,7 @@ public function testLimitPostByAuthenticatedUser(): void public function testChangeGuard(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Query { posts: [Post!]! @all @@ -61,7 +61,7 @@ public function testChangeGuard(): void guards: ["web"] ) } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); $ownedPosts = factory(Post::class, 3)->make(); @@ -75,13 +75,13 @@ public function testChangeGuard(): void $authFactory->guard('web')->setUser($user); $response = $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query { posts { id } } - '); + GRAPHQL); $this->assertSame( $ownedPosts->pluck('id')->all(), diff --git a/tests/Integration/Execution/MutationExecutor/BelongsToManyTest.php b/tests/Integration/Execution/MutationExecutor/BelongsToManyTest.php index 967935b8dd..e164f7b50f 100644 --- a/tests/Integration/Execution/MutationExecutor/BelongsToManyTest.php +++ b/tests/Integration/Execution/MutationExecutor/BelongsToManyTest.php @@ -10,7 +10,7 @@ final class BelongsToManyTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Role { id: ID! name: String @@ -106,11 +106,11 @@ final class BelongsToManyTest extends DBTestCase id: ID! # role ID meta: String } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; public function testSyncWithoutDetaching(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "user1" @@ -144,7 +144,7 @@ public function testSyncWithoutDetaching(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createUser' => [ 'id' => '1', @@ -174,7 +174,7 @@ public function testSyncWithoutDetaching(): void public function testCreateWithNewBelongsToMany(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createRole(input: { name: "foobar" @@ -197,7 +197,7 @@ public function testCreateWithNewBelongsToMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createRole' => [ 'id' => '1', @@ -215,7 +215,7 @@ public function testCreateWithNewBelongsToMany(): void public function testUpsertWithBelongsToManyOnNonExistentData(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertRole(input: { id: 1 @@ -241,7 +241,7 @@ public function testUpsertWithBelongsToManyOnNonExistentData(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertRole' => [ 'id' => '1', @@ -326,7 +326,7 @@ public function testCreateAndConnectWithBelongsToMany(): void $user->name = 'user_two'; $user->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createRole(input: { name: "foobar" @@ -342,7 +342,7 @@ public function testCreateAndConnectWithBelongsToMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createRole' => [ 'id' => '1', @@ -374,7 +374,7 @@ public function testUpsertUsingCreationAndConnectWithBelongsToMany(): void $user->name = 'user_two'; $user->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertRole(input: { id: 1 @@ -391,7 +391,7 @@ public function testUpsertUsingCreationAndConnectWithBelongsToMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertRole' => [ 'id' => '1', @@ -418,7 +418,7 @@ public function testCreateWithBelongsToMany(): void $role->name = 'is_admin'; $role->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateRole(input: { id: 1 @@ -442,7 +442,7 @@ public function testCreateWithBelongsToMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateRole' => [ 'id' => '1', @@ -470,7 +470,7 @@ public function testAllowsNullOperations(): void { factory(Role::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateRole(input: { id: 1 @@ -494,7 +494,7 @@ public function testAllowsNullOperations(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateRole' => [ 'id' => '1', @@ -512,7 +512,7 @@ public function testUpsertUsingCreationWithBelongsToMany(): void $role->name = 'is_admin'; $role->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateRole(input: { id: 1 @@ -538,7 +538,7 @@ public function testUpsertUsingCreationWithBelongsToMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateRole' => [ 'id' => '1', @@ -830,7 +830,7 @@ public function testSyncExistingUsersDuringCreateToABelongsToManyRelation(): voi { factory(User::class, 2)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createRole(input: { name: "foobar" @@ -845,7 +845,7 @@ public function testSyncExistingUsersDuringCreateToABelongsToManyRelation(): voi } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createRole' => [ 'id' => '1', @@ -867,7 +867,7 @@ public function testSyncExistingUsersDuringCreateUsingUpsertToABelongsToManyRela { factory(User::class, 2)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertRole(input: { id: 1 @@ -883,7 +883,7 @@ public function testSyncExistingUsersDuringCreateUsingUpsertToABelongsToManyRela } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertRole' => [ 'id' => '1', @@ -914,7 +914,7 @@ public function testDisconnectAllRelatedModelsOnEmptySync(string $action): void $this->assertCount(1, $role->users); - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<assertJson([ + GRAPHQL)->assertJson([ 'data' => [ "{$action}Role" => [ 'id' => '1', @@ -955,7 +955,7 @@ public function testConnectUserWithRoleAndPivotMetaByUsingSync(): void $meta = Lorem::sentence(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($meta: String) { pivotsUpdateUser(input: { id: 1, @@ -979,7 +979,7 @@ public function testConnectUserWithRoleAndPivotMetaByUsingSync(): void } } } - ', [ + GRAPHQL, [ 'meta' => $meta, ])->assertJson([ 'data' => [ @@ -1014,7 +1014,7 @@ public function testConnectUserWithRoleAndPivotMetaByUsingSyncWithoutDetach(): v $meta = Lorem::sentence(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($meta: String) { pivotsUpdateUser(input: { id: 1, @@ -1034,7 +1034,7 @@ public function testConnectUserWithRoleAndPivotMetaByUsingSyncWithoutDetach(): v } } } - ', [ + GRAPHQL, [ 'meta' => $meta, ])->assertJson([ 'data' => [ @@ -1063,7 +1063,7 @@ public function testConnectUserWithRoleAndPivotMetaByUsingConnect(): void $meta = Lorem::sentence(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($meta: String) { pivotsUpdateUser(input: { id: 1, @@ -1083,7 +1083,7 @@ public function testConnectUserWithRoleAndPivotMetaByUsingConnect(): void } } } - ', [ + GRAPHQL, [ 'meta' => $meta, ])->assertJson([ 'data' => [ diff --git a/tests/Integration/Execution/MutationExecutor/BelongsToTest.php b/tests/Integration/Execution/MutationExecutor/BelongsToTest.php index 65f56e4721..660a9f4575 100644 --- a/tests/Integration/Execution/MutationExecutor/BelongsToTest.php +++ b/tests/Integration/Execution/MutationExecutor/BelongsToTest.php @@ -12,7 +12,7 @@ final class BelongsToTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -81,14 +81,14 @@ final class BelongsToTest extends DBTestCase disconnect: Boolean delete: Boolean } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; public function testCreateAndConnectWithBelongsTo(): void { $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -103,7 +103,7 @@ public function testCreateAndConnectWithBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -118,7 +118,7 @@ public function testCreateAndConnectWithBelongsTo(): void public function testBelongsToExplicitNullHasNoEffect(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -131,7 +131,7 @@ public function testBelongsToExplicitNullHasNoEffect(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -147,7 +147,7 @@ public function testUpsertUsingCreateAndConnectWithBelongsTo(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -163,7 +163,7 @@ public function testUpsertUsingCreateAndConnectWithBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -181,7 +181,7 @@ public function testAllowsNullOperations(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -202,7 +202,7 @@ public function testAllowsNullOperations(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -215,7 +215,7 @@ public function testAllowsNullOperations(): void public function testCreateWithNewBelongsTo(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -232,7 +232,7 @@ public function testCreateWithNewBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -247,7 +247,7 @@ public function testCreateWithNewBelongsTo(): void public function testUpsertWithNewBelongsTo(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -265,7 +265,7 @@ public function testUpsertWithNewBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -345,7 +345,7 @@ public function testUpsertBelongsToWithIDNull(): void public function testUpsertUsingCreateWithNewBelongsTo(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -363,7 +363,7 @@ public function testUpsertUsingCreateWithNewBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -378,7 +378,7 @@ public function testUpsertUsingCreateWithNewBelongsTo(): void public function testUpsertUsingCreateWithNewUpsertBelongsTo(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -397,7 +397,7 @@ public function testUpsertUsingCreateWithNewUpsertBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -417,7 +417,7 @@ public function testCreateAndUpdateBelongsTo(): void $user->name = 'foo'; $user->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -436,7 +436,7 @@ public function testCreateAndUpdateBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -457,7 +457,7 @@ public function testUpsertUsingCreateAndUpdateBelongsTo(): void $user->name = 'foo'; $user->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -477,7 +477,7 @@ public function testUpsertUsingCreateAndUpdateBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -494,7 +494,7 @@ public function testUpsertUsingCreateAndUpdateBelongsTo(): void /** @see https://github.com/nuwave/lighthouse/pull/2570 */ public function testSavesOnlyOnceWithMultipleBelongsTo(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateUser(input: UpdateUserInput! @spread): User! @update } @@ -540,7 +540,7 @@ public function testSavesOnlyOnceWithMultipleBelongsTo(): void id: ID! name: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $user = factory(User::class)->make(); $this->assertInstanceOf(User::class, $user); @@ -554,7 +554,7 @@ public function testSavesOnlyOnceWithMultipleBelongsTo(): void $queries[] = $query->sql; }); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: 1 @@ -584,7 +584,7 @@ public function testSavesOnlyOnceWithMultipleBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateUser' => [ 'id' => '1', @@ -612,7 +612,7 @@ public function testUpsertUsingCreateAndUpdateUsingUpsertBelongsTo(): void $user->name = 'foo'; $user->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -632,7 +632,7 @@ public function testUpsertUsingCreateAndUpdateUsingUpsertBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -678,7 +678,7 @@ public function testUpdateAndDisconnectBelongsTo(string $action): void } } } -GRAPHQL + GRAPHQL, )->assertJson([ 'data' => [ "{$action}Task" => [ @@ -708,7 +708,7 @@ public function testCreateUsingUpsertAndDisconnectBelongsTo(): void $task->user()->associate($user); $task->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -724,7 +724,7 @@ public function testCreateUsingUpsertAndDisconnectBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -774,7 +774,7 @@ public function testUpdateAndDeleteBelongsTo(string $action): void } } } -GRAPHQL + GRAPHQL, )->assertJson([ 'data' => [ "{$action}Task" => [ @@ -802,7 +802,7 @@ public function testCreateUsingUpsertAndDeleteBelongsTo(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -818,7 +818,7 @@ public function testCreateUsingUpsertAndDeleteBelongsTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -868,7 +868,7 @@ public function testDoesNotDeleteOrDisconnectOnFalsyValues(string $action): void } } } -GRAPHQL + GRAPHQL, )->assertJson([ 'data' => [ "{$action}Task" => [ @@ -895,7 +895,7 @@ public function testDoesNotDeleteOrDisconnectOnFalsyValues(string $action): void public function testUpsertAcrossTwoNestedBelongsToRelations(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! roles: [Role!] @belongsToMany @@ -929,9 +929,9 @@ public function testUpsertAcrossTwoNestedBelongsToRelations(): void input UpsertRoleInput { name: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertUser(input: { name: "foo" @@ -951,7 +951,7 @@ public function testUpsertAcrossTwoNestedBelongsToRelations(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertUser' => [ 'name' => 'foo', @@ -967,7 +967,7 @@ public function testUpsertAcrossTwoNestedBelongsToRelations(): void public function testUpsertAcrossTwoNestedBelongsToRelationsAndOverrideExistingModel(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -1011,10 +1011,10 @@ public function testUpsertAcrossTwoNestedBelongsToRelationsAndOverrideExistingMo input UpsertRoleUsersRelation { sync: [ID!] } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; // Create the first User with a Role. - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertUser(input: { name: "foo" @@ -1036,7 +1036,7 @@ public function testUpsertAcrossTwoNestedBelongsToRelationsAndOverrideExistingMo } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertUser' => [ 'id' => '1', @@ -1059,7 +1059,7 @@ public function testUpsertAcrossTwoNestedBelongsToRelationsAndOverrideExistingMo $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertUser(input: { id: "1" @@ -1087,7 +1087,7 @@ public function testUpsertAcrossTwoNestedBelongsToRelationsAndOverrideExistingMo } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertUser' => [ 'id' => '1', @@ -1102,7 +1102,7 @@ public function testUpsertAcrossTwoNestedBelongsToRelationsAndOverrideExistingMo public function testCreateMultipleBelongsToThatDontExistYet(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type RoleUserPivot { id: ID! user: User! @@ -1148,9 +1148,9 @@ public function testCreateMultipleBelongsToThatDontExistYet(): void id: ID! name: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createRoleUser(input: { id: "1" @@ -1178,7 +1178,7 @@ public function testCreateMultipleBelongsToThatDontExistYet(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createRoleUser' => [ 'id' => '1', @@ -1197,7 +1197,7 @@ public function testCreateMultipleBelongsToThatDontExistYet(): void public function testCreateMultipleBelongsToThatDontExistYetWithExistingRecords(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type RoleUserPivot { id: ID! meta: String @@ -1245,9 +1245,9 @@ public function testCreateMultipleBelongsToThatDontExistYetWithExistingRecords() id: ID name: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' mutation { createRoleUser(input: { meta: "asdf" @@ -1273,7 +1273,8 @@ public function testCreateMultipleBelongsToThatDontExistYetWithExistingRecords() name } } - }'; + } + GRAPHQL; // This must first create a user, then a role, then attach them to the pivot $this->graphQL($query)->assertJson([ diff --git a/tests/Integration/Execution/MutationExecutor/HasManyTest.php b/tests/Integration/Execution/MutationExecutor/HasManyTest.php index a66bed5c47..bf564e1de9 100644 --- a/tests/Integration/Execution/MutationExecutor/HasManyTest.php +++ b/tests/Integration/Execution/MutationExecutor/HasManyTest.php @@ -11,7 +11,7 @@ final class HasManyTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -83,11 +83,11 @@ final class HasManyTest extends DBTestCase id: ID name: String } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; public function testCreateWithNewHasMany(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "foo" @@ -107,7 +107,7 @@ public function testCreateWithNewHasMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createUser' => [ 'id' => '1', @@ -131,7 +131,7 @@ public function testCreateWithConnectHasMany(): void $task2 = factory(Task::class)->create(); $this->assertInstanceOf(Task::class, $task2); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: CreateUserInput!) { createUser(input: $input) { name @@ -141,7 +141,7 @@ public function testCreateWithConnectHasMany(): void } } } - ', + GRAPHQL, [ 'input' => [ 'name' => 'foo', @@ -176,7 +176,7 @@ public function testAllowsNullOperations(): void { factory(User::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: 1 @@ -194,7 +194,7 @@ public function testAllowsNullOperations(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateUser' => [ 'name' => 'foo', @@ -206,7 +206,7 @@ public function testAllowsNullOperations(): void public function testUpsertWithNewHasMany(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "foo" @@ -225,7 +225,7 @@ public function testUpsertWithNewHasMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createUser' => [ 'id' => '1', @@ -243,7 +243,7 @@ public function testUpsertWithNewHasMany(): void public function testUpsertHasManyWithoutId(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertUser(input: { name: "foo" @@ -261,7 +261,7 @@ public function testUpsertHasManyWithoutId(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertUser' => [ 'id' => '1', @@ -279,7 +279,7 @@ public function testUpsertHasManyWithoutId(): void public function testCreateUsingUpsertWithNewHasMany(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertUser(input: { id: 1 @@ -299,7 +299,7 @@ public function testCreateUsingUpsertWithNewHasMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertUser' => [ 'id' => '1', @@ -443,7 +443,7 @@ public function testUpsertHasMany(string $action): void } } } -GRAPHQL + GRAPHQL, )->assertJson([ 'data' => [ "{$action}User" => [ @@ -489,7 +489,7 @@ public function testDeleteHasMany(string $action): void } } } -GRAPHQL + GRAPHQL, )->assertJson([ 'data' => [ "{$action}User" => [ @@ -516,7 +516,7 @@ public function testConnectHasMany(string $action): void $actionInputName = ucfirst($action); - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ << [ 'id' => $user->id, @@ -578,7 +578,7 @@ public function testDisconnectHasMany(string $action): void $actionInputName = ucfirst($action); - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ << [ 'id' => $user->id, 'name' => 'foo', @@ -619,7 +619,7 @@ public function testDisconnectHasMany(string $action): void public function testUpsertAcrossPivotTableOverrideExistingModel(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -654,10 +654,10 @@ public function testUpsertAcrossPivotTableOverrideExistingModel(): void input UpsertRoleUsersRelation { sync: [ID!] } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; // Create the first User with a Role. - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertUser(input: { name: "foo" @@ -675,7 +675,7 @@ public function testUpsertAcrossPivotTableOverrideExistingModel(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertUser' => [ 'id' => '1', @@ -697,7 +697,7 @@ public function testUpsertAcrossPivotTableOverrideExistingModel(): void // Create another User. factory(User::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertUser(input: { id: "1" @@ -720,7 +720,7 @@ public function testUpsertAcrossPivotTableOverrideExistingModel(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertUser' => [ 'id' => '1', @@ -735,7 +735,7 @@ public function testUpsertAcrossPivotTableOverrideExistingModel(): void public function testConnectModelWithCustomKey(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User @first } @@ -771,11 +771,11 @@ public function testConnectModelWithCustomKey(): void connect: [ID!] disconnect: [ID!] } - '; + GRAPHQL; factory(CustomPrimaryKey::class, 3)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "foo" @@ -790,7 +790,7 @@ public function testConnectModelWithCustomKey(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createUser' => [ 'id' => '1', @@ -810,7 +810,7 @@ public function testConnectModelWithCustomKey(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: "1" @@ -826,7 +826,7 @@ public function testConnectModelWithCustomKey(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateUser' => [ 'id' => '1', @@ -849,7 +849,7 @@ public function testUpdateNestedHasMany(): void $task = factory(Task::class)->create(); $this->assertInstanceOf(Task::class, $task); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: UpdateUserInput!) { updateUser(input: $input) { id @@ -860,7 +860,7 @@ public function testUpdateNestedHasMany(): void } } } - ', [ + GRAPHQL, [ 'input' => [ 'id' => $user->id, 'name' => 'foo', diff --git a/tests/Integration/Execution/MutationExecutor/HasOneTest.php b/tests/Integration/Execution/MutationExecutor/HasOneTest.php index 3780e60abd..b6856e22c7 100644 --- a/tests/Integration/Execution/MutationExecutor/HasOneTest.php +++ b/tests/Integration/Execution/MutationExecutor/HasOneTest.php @@ -9,7 +9,7 @@ final class HasOneTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -77,11 +77,11 @@ final class HasOneTest extends DBTestCase id: ID title: String } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; public function testCreateWithNewHasOne(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -99,7 +99,7 @@ public function testCreateWithNewHasOne(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -115,7 +115,7 @@ public function testCreateWithNewHasOne(): void public function testUpsertWithNewHasOne(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -134,7 +134,7 @@ public function testUpsertWithNewHasOne(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -150,7 +150,7 @@ public function testUpsertWithNewHasOne(): void public function testCreateUsingUpsertWithNewHasOne(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 2 @@ -170,7 +170,7 @@ public function testCreateUsingUpsertWithNewHasOne(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '2', @@ -186,7 +186,7 @@ public function testCreateUsingUpsertWithNewHasOne(): void public function testUpsertHasOneWithoutID(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { name: "foo" @@ -204,7 +204,7 @@ public function testUpsertHasOneWithoutID(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -220,7 +220,7 @@ public function testUpsertHasOneWithoutID(): void public function testUpsertHasOneWithIDNull(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { name: "foo" @@ -239,7 +239,7 @@ public function testUpsertHasOneWithIDNull(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', diff --git a/tests/Integration/Execution/MutationExecutor/MorphManyTest.php b/tests/Integration/Execution/MutationExecutor/MorphManyTest.php index fdcb73ef13..497cd79de4 100644 --- a/tests/Integration/Execution/MutationExecutor/MorphManyTest.php +++ b/tests/Integration/Execution/MutationExecutor/MorphManyTest.php @@ -9,7 +9,7 @@ final class MorphManyTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -81,11 +81,11 @@ final class MorphManyTest extends DBTestCase id: ID url: String } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; public function testCreateWithNewMorphMany(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -102,7 +102,7 @@ public function testCreateWithNewMorphMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -119,7 +119,7 @@ public function testCreateWithNewMorphMany(): void public function testCreateWithUpsertMorphMany(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -137,7 +137,7 @@ public function testCreateWithUpsertMorphMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -157,7 +157,7 @@ public function testCreateWithConnectMorphMany(): void $image1 = factory(Image::class)->create(); $this->assertInstanceOf(Image::class, $image1); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: CreateTaskInput!) { createTask(input: $input) { id @@ -167,7 +167,7 @@ public function testCreateWithConnectMorphMany(): void } } } - ', [ + GRAPHQL, [ 'input' => [ 'name' => 'foo', 'images' => [ @@ -192,7 +192,7 @@ public function testCreateWithConnectMorphMany(): void public function testUpsertMorphManyWithoutId(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { name: "foo" @@ -210,7 +210,7 @@ public function testUpsertMorphManyWithoutId(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'id' => '1', @@ -230,7 +230,7 @@ public function testAllowsNullOperations(): void { factory(Task::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateTask(input: { id: 1 @@ -248,7 +248,7 @@ public function testAllowsNullOperations(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateTask' => [ 'name' => 'foo', @@ -289,7 +289,7 @@ public function testUpdateWithNewMorphMany(string $action): void } } } -GRAPHQL + GRAPHQL, )->assertJson([ 'data' => [ "{$action}Task" => [ @@ -336,7 +336,7 @@ public function testUpdateAndUpdateMorphMany(string $action): void } } } -GRAPHQL + GRAPHQL, )->assertJson([ 'data' => [ "{$action}Task" => [ diff --git a/tests/Integration/Execution/MutationExecutor/MorphOneTest.php b/tests/Integration/Execution/MutationExecutor/MorphOneTest.php index 5402b21914..915e287a39 100644 --- a/tests/Integration/Execution/MutationExecutor/MorphOneTest.php +++ b/tests/Integration/Execution/MutationExecutor/MorphOneTest.php @@ -9,7 +9,7 @@ final class MorphOneTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -76,11 +76,11 @@ final class MorphOneTest extends DBTestCase id: ID url: String } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; public function testCreateWithNewMorphOne(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -97,7 +97,7 @@ public function testCreateWithNewMorphOne(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -112,7 +112,7 @@ public function testCreateWithNewMorphOne(): void public function testCreateWithUpsertMorphOne(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -130,7 +130,7 @@ public function testCreateWithUpsertMorphOne(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', @@ -181,7 +181,7 @@ public function testAllowsNullOperations(): void { factory(Task::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateTask(input: { id: 1 @@ -199,7 +199,7 @@ public function testAllowsNullOperations(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateTask' => [ 'name' => 'foo', @@ -382,7 +382,7 @@ public function testNestedConnectMorphOne(): void $image = factory(Image::class)->create(); $this->assertInstanceOf(Image::class, $image); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($input: UpdateTaskInput!) { updateTask(input: $input) { id @@ -392,7 +392,7 @@ public function testNestedConnectMorphOne(): void } } } - ', [ + GRAPHQL, [ 'input' => [ 'id' => $task->id, 'name' => 'foo', diff --git a/tests/Integration/Execution/MutationExecutor/MorphToManyTest.php b/tests/Integration/Execution/MutationExecutor/MorphToManyTest.php index 6a1bcd4885..2114e23f3b 100644 --- a/tests/Integration/Execution/MutationExecutor/MorphToManyTest.php +++ b/tests/Integration/Execution/MutationExecutor/MorphToManyTest.php @@ -7,7 +7,7 @@ final class MorphToManyTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { createTask(input: CreateTaskInput! @spread): Task @create upsertTask(input: UpsertTaskInput! @spread): Task @upsert @@ -57,7 +57,7 @@ final class MorphToManyTest extends DBTestCase id: ID! name: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; public function testCreateATaskWithExistingTagsByUsingConnect(): void { @@ -66,7 +66,7 @@ public function testCreateATaskWithExistingTagsByUsingConnect(): void $tag->name = 'php'; $tag->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "Finish tests" @@ -79,7 +79,7 @@ public function testCreateATaskWithExistingTagsByUsingConnect(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'tags' => [ @@ -94,7 +94,7 @@ public function testCreateATaskWithExistingTagsByUsingConnect(): void public function testAllowsNullOperations(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "Finish tests" @@ -111,7 +111,7 @@ public function testAllowsNullOperations(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'name' => 'Finish tests', @@ -128,7 +128,7 @@ public function testUpsertATaskWithExistingTagsByUsingConnect(): void $tag->name = 'php'; $tag->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -142,7 +142,7 @@ public function testUpsertATaskWithExistingTagsByUsingConnect(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'tags' => [ @@ -162,7 +162,7 @@ public function testCreateATaskWithExistingTagsByUsingSync(): void $tag->name = 'php'; $tag->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "Finish tests" @@ -175,7 +175,7 @@ public function testCreateATaskWithExistingTagsByUsingSync(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'tags' => [ @@ -195,7 +195,7 @@ public function testUpsertATaskWithExistingTagsByUsingSync(): void $tag->name = 'php'; $tag->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -209,7 +209,7 @@ public function testUpsertATaskWithExistingTagsByUsingSync(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'tags' => [ @@ -224,7 +224,7 @@ public function testUpsertATaskWithExistingTagsByUsingSync(): void public function testCreateANewTagRelationByUsingCreate(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "Finish tests" @@ -242,7 +242,7 @@ public function testCreateANewTagRelationByUsingCreate(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'tags' => [ @@ -258,7 +258,7 @@ public function testCreateANewTagRelationByUsingCreate(): void public function testUpsertANewTagRelationByUsingCreate(): void { - $this->graphQL(' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -277,7 +277,7 @@ public function testUpsertANewTagRelationByUsingCreate(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'tags' => [ @@ -293,7 +293,7 @@ public function testUpsertANewTagRelationByUsingCreate(): void public function testUpsertANewTagRelationByUsingUpsert(): void { - $this->graphQL(' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertTask(input: { id: 1 @@ -313,7 +313,7 @@ public function testUpsertANewTagRelationByUsingUpsert(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertTask' => [ 'tags' => [ diff --git a/tests/Integration/Execution/MutationExecutor/MorphToTest.php b/tests/Integration/Execution/MutationExecutor/MorphToTest.php index 39202732b3..8e97a19039 100644 --- a/tests/Integration/Execution/MutationExecutor/MorphToTest.php +++ b/tests/Integration/Execution/MutationExecutor/MorphToTest.php @@ -12,7 +12,7 @@ final class MorphToTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID name: String @@ -90,7 +90,7 @@ final class MorphToTest extends DBTestCase disconnect: Boolean delete: Boolean } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; public function testConnectsMorphTo(): void { @@ -99,13 +99,13 @@ public function testConnectsMorphTo(): void $task->name = 'first_task'; $task->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createImage(input: { url: "foo" imageable: { connect: { - type: "Tests\\\Utils\\\Models\\\Task" + type: "Tests\\Utils\\Models\\Task" id: 1 } } @@ -118,7 +118,7 @@ public function testConnectsMorphTo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createImage' => [ 'id' => '1', @@ -147,7 +147,7 @@ public function testConnectsMorphToWithEnumType(): void $task->name = 'first_task'; $task->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createImageWithEnumType(input: { url: "foo" @@ -166,7 +166,7 @@ public function testConnectsMorphToWithEnumType(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createImageWithEnumType' => [ 'id' => '1', @@ -187,14 +187,14 @@ public function testConnectsMorphToWithUpsert(): void $task->name = 'first_task'; $task->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertImage(input: { id: 1 url: "foo" imageable: { connect: { - type: "Tests\\\Utils\\\Models\\\Task" + type: "Tests\\Utils\\Models\\Task" id: 1 } } @@ -207,7 +207,7 @@ public function testConnectsMorphToWithUpsert(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertImage' => [ 'id' => '1', @@ -225,7 +225,7 @@ public function testAllowsNullOperations(): void { factory(Image::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateImage(input: { id: 1 @@ -242,7 +242,7 @@ public function testAllowsNullOperations(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateImage' => [ 'url' => 'foo', diff --git a/tests/Integration/Federation/FederationEntitiesModelTest.php b/tests/Integration/Federation/FederationEntitiesModelTest.php index 69f0dcae0a..dc3b2a8356 100644 --- a/tests/Integration/Federation/FederationEntitiesModelTest.php +++ b/tests/Integration/Federation/FederationEntitiesModelTest.php @@ -20,11 +20,11 @@ protected function getPackageProviders($app): array public function testCallsEntityResolverModel(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User @key(fields: "id") { id: ID! @external } - '; + GRAPHQL; $user = factory(User::class)->create(); @@ -33,7 +33,7 @@ public function testCallsEntityResolverModel(): void 'id' => (string) $user->getKey(), ]; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($representations: [_Any!]!) { _entities(representations: $representations) { __typename @@ -42,7 +42,7 @@ public function testCallsEntityResolverModel(): void } } } - ', [ + GRAPHQL, [ 'representations' => [ $userRepresentation, ], @@ -57,7 +57,7 @@ public function testCallsEntityResolverModel(): void public function testCallsNestedEntityResolverModel(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User @key(fields: "company { id }") { id: ID! @external company: Company! @belongsTo @@ -66,7 +66,7 @@ public function testCallsNestedEntityResolverModel(): void type Company { id: ID! } - '; + GRAPHQL; $company = factory(Company::class)->create(); $this->assertInstanceOf(Company::class, $company); @@ -84,7 +84,7 @@ public function testCallsNestedEntityResolverModel(): void ], ]; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($representations: [_Any!]!) { _entities(representations: $representations) { __typename @@ -93,7 +93,7 @@ public function testCallsNestedEntityResolverModel(): void } } } - ', [ + GRAPHQL, [ 'representations' => [ $userRepresentation, ], @@ -111,11 +111,11 @@ public function testCallsNestedEntityResolverModel(): void public function testCallsEntityResolverModelWithGlobalId(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User @key(fields: "id") { id: ID! @external @globalId } - '; + GRAPHQL; $user = factory(User::class)->create(); @@ -124,7 +124,7 @@ public function testCallsEntityResolverModelWithGlobalId(): void 'id' => $this->app->get(GlobalId::class)->encode('User', $user->getKey()), ]; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($representations: [_Any!]!) { _entities(representations: $representations) { __typename @@ -133,7 +133,7 @@ public function testCallsEntityResolverModelWithGlobalId(): void } } } - ', [ + GRAPHQL, [ 'representations' => [ $userRepresentation, ], @@ -148,12 +148,12 @@ public function testCallsEntityResolverModelWithGlobalId(): void public function testHydratesExternalFields(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User @key(fields: "id") { id: ID! externallyProvided: String! @external } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -164,7 +164,7 @@ public function testHydratesExternalFields(): void 'externallyProvided' => 'some value that we know nothing about', ]; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($representations: [_Any!]!) { _entities(representations: $representations) { __typename @@ -174,7 +174,7 @@ public function testHydratesExternalFields(): void } } } - ', [ + GRAPHQL, [ 'representations' => [ $userRepresentation, ], diff --git a/tests/Integration/Federation/FederationEntitiesTest.php b/tests/Integration/Federation/FederationEntitiesTest.php index 7197d2022b..4bcc7e141f 100644 --- a/tests/Integration/Federation/FederationEntitiesTest.php +++ b/tests/Integration/Federation/FederationEntitiesTest.php @@ -21,7 +21,7 @@ protected function getPackageProviders($app): array public function testCallsEntityResolverClass(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! @external foo: String! @@ -30,14 +30,14 @@ public function testCallsEntityResolverClass(): void type Query { foo: Int! } - '; + GRAPHQL; $foo = [ '__typename' => 'Foo', 'id' => '42', ]; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($representations: [_Any!]!) { _entities(representations: $representations) { __typename @@ -46,7 +46,7 @@ public function testCallsEntityResolverClass(): void } } } - ', [ + GRAPHQL, [ 'representations' => [ $foo, ], @@ -61,7 +61,7 @@ public function testCallsEntityResolverClass(): void public function testCallsBatchedEntityResolverClass(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type BatchedFoo @key(fields: "id") { id: ID! @external foo: String! @@ -70,7 +70,7 @@ public function testCallsBatchedEntityResolverClass(): void type Query { foo: Int! } - '; + GRAPHQL; $foo1 = [ '__typename' => 'BatchedFoo', @@ -82,7 +82,7 @@ public function testCallsBatchedEntityResolverClass(): void 'id' => '69', ]; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($representations: [_Any!]!) { _entities(representations: $representations) { __typename @@ -91,7 +91,7 @@ public function testCallsBatchedEntityResolverClass(): void } } } - ', [ + GRAPHQL, [ 'representations' => [ $foo1, $foo2, @@ -109,7 +109,7 @@ public function testCallsBatchedEntityResolverClass(): void /** https://github.com/apollographql/apollo-federation-subgraph-compatibility/issues/70. */ public function testMaintainsOrderOfRepresentationsInResult(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! @external foo: String! @@ -123,7 +123,7 @@ public function testMaintainsOrderOfRepresentationsInResult(): void type Query { foo: Int! } - '; + GRAPHQL; $foo1 = [ '__typename' => 'BatchedFoo', @@ -140,7 +140,7 @@ public function testMaintainsOrderOfRepresentationsInResult(): void 'id' => '9001', ]; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($representations: [_Any!]!) { _entities(representations: $representations) { __typename @@ -152,7 +152,7 @@ public function testMaintainsOrderOfRepresentationsInResult(): void } } } - ', [ + GRAPHQL, [ 'representations' => [ $foo1, $foo2, @@ -171,14 +171,14 @@ public function testMaintainsOrderOfRepresentationsInResult(): void public function testThrowsWhenTypeIsUnknown(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! @external foo: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { _entities( representations: [ @@ -190,7 +190,7 @@ public function testThrowsWhenTypeIsUnknown(): void } } } - '); + GRAPHQL); $this->assertStringContainsString( EntityResolverProvider::unknownTypename('Unknown'), @@ -200,14 +200,14 @@ public function testThrowsWhenTypeIsUnknown(): void public function testThrowsWhenRepresentationIsNotArray(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! @external foo: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { _entities( representations: [ @@ -219,7 +219,7 @@ public function testThrowsWhenRepresentationIsNotArray(): void } } } - '); + GRAPHQL); $this->assertStringContainsString( Any::isNotArray(), @@ -229,14 +229,14 @@ public function testThrowsWhenRepresentationIsNotArray(): void public function testThrowsWhenTypeIsNotString(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! @external foo: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { _entities( representations: [ @@ -248,7 +248,7 @@ public function testThrowsWhenTypeIsNotString(): void } } } - '); + GRAPHQL); $this->assertStringContainsString( Any::typenameIsNotString(), @@ -258,17 +258,17 @@ public function testThrowsWhenTypeIsNotString(): void public function testThrowsWhenTypeIsInvalidName(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! @external foo: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $isValidNameError = Utils::isValidNameError('1'); $this->assertInstanceOf(Error::class, $isValidNameError); - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { _entities( representations: [ @@ -280,7 +280,7 @@ public function testThrowsWhenTypeIsInvalidName(): void } } } - '); + GRAPHQL); $this->assertStringContainsString( Any::typenameIsInvalidName($isValidNameError), @@ -290,14 +290,14 @@ public function testThrowsWhenTypeIsInvalidName(): void public function testThrowsWhenNoKeySelectionIsSatisfied(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! @external foo: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { _entities( representations: [ @@ -309,7 +309,7 @@ public function testThrowsWhenNoKeySelectionIsSatisfied(): void } } } - '); + GRAPHQL); $this->assertStringContainsString( 'Representation does not satisfy any set of uniquely identifying keys', @@ -319,14 +319,14 @@ public function testThrowsWhenNoKeySelectionIsSatisfied(): void public function testThrowsWhenMissingResolver(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type MissingResolver @key(fields: "id") { id: ID! @external foo: String! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { _entities( representations: [ @@ -341,7 +341,7 @@ public function testThrowsWhenMissingResolver(): void } } } - '); + GRAPHQL); $this->assertStringContainsString( EntityResolverProvider::missingResolver('MissingResolver'), diff --git a/tests/Integration/Federation/FederationSchemaTest.php b/tests/Integration/Federation/FederationSchemaTest.php index 36448390fa..0c5dc1311f 100644 --- a/tests/Integration/Federation/FederationSchemaTest.php +++ b/tests/Integration/Federation/FederationSchemaTest.php @@ -9,8 +9,8 @@ final class FederationSchemaTest extends TestCase { private const FEDERATION_V2_SCHEMA_EXTENSION = /** @lang GraphQL */ <<<'GRAPHQL' - extend schema @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@composeDirective", "@extends", "@external", "@inaccessible", "@interfaceObject", "@key", "@override", "@provides", "@requires", "@shareable", "@tag"]) - GRAPHQL; + extend schema @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@composeDirective", "@extends", "@external", "@inaccessible", "@interfaceObject", "@key", "@override", "@provides", "@requires", "@shareable", "@tag"]) + GRAPHQL; protected function getPackageProviders($app): array { @@ -57,12 +57,14 @@ public function testServiceQueryShouldReturnValidSdlWithoutQuery(): void $sdl = $this->_serviceSdl(); $this->assertStringContainsString($typeFoo, $sdl); - $this->assertStringNotContainsString(/** @lang GraphQL */ 'type Query', $sdl); + $this->assertStringNotContainsString(/** @lang GraphQL */ <<<'GRAPHQL' + type Query + GRAPHQL, $sdl); } public function testFederatedSchemaShouldContainCorrectEntityUnion(): void { - $schema = $this->buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! @external foo: String! @@ -76,7 +78,7 @@ public function testFederatedSchemaShouldContainCorrectEntityUnion(): void type Query { foo: Int! } - '); + GRAPHQL); $_Entity = $schema->getType('_Entity'); $this->assertInstanceOf(UnionType::class, $_Entity); @@ -175,13 +177,13 @@ public function testPaginationTypesAreMarkedAsSharableWhenUsingFederationV2(): v private function _serviceSdl(): string { - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { _service { sdl } } - '); + GRAPHQL); return $response->json('data._service.sdl'); } diff --git a/tests/Integration/FieldMiddlewareTest.php b/tests/Integration/FieldMiddlewareTest.php index 83c6998929..69d9394d68 100644 --- a/tests/Integration/FieldMiddlewareTest.php +++ b/tests/Integration/FieldMiddlewareTest.php @@ -10,7 +10,7 @@ final class FieldMiddlewareTest extends TestCase { public function testTransformsArgsBeforeCustomFieldMiddleware(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(id: ID! @trim): Foo @customFieldMiddleware } @@ -18,15 +18,15 @@ public function testTransformsArgsBeforeCustomFieldMiddleware(): void type Foo { id: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(id: " foo ") { id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => [ 'id' => 'foo', @@ -37,7 +37,7 @@ public function testTransformsArgsBeforeCustomFieldMiddleware(): void public function testFieldMiddlewareResolveInDefinitionOrder(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @guard @@ -48,15 +48,15 @@ public function testFieldMiddlewareResolveInDefinitionOrder(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertGraphQLErrorMessage(AuthenticationException::MESSAGE); + GRAPHQL)->assertGraphQLErrorMessage(AuthenticationException::MESSAGE); } public function testHydratesGlobalFieldMiddleware(): void @@ -65,17 +65,17 @@ public function testHydratesGlobalFieldMiddleware(): void GlobalFieldMiddlewareDirective::class, ]]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Boolean } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => true, ], diff --git a/tests/Integration/FileUploadTest.php b/tests/Integration/FileUploadTest.php index c0b88548f9..e1de18a539 100644 --- a/tests/Integration/FileUploadTest.php +++ b/tests/Integration/FileUploadTest.php @@ -8,23 +8,23 @@ final class FileUploadTest extends TestCase { - protected string $schema = /** @lang GraphQL */ ' - scalar Upload @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Upload") + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload") type Mutation { upload(file: Upload): Boolean } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; /** https://github.com/jaydenseric/graphql-multipart-request-spec#single-file. */ public function testResolvesUploadViaMultipartRequest(): void { $operations = [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file: Upload!) { upload(file: $file) } - ', + GRAPHQL, 'variables' => [ 'file' => null, ], @@ -50,11 +50,11 @@ public function testResolvesUploadViaMultipartRequest(): void public function testUploadNull(): void { $operations = [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file: Upload) { upload(file: $file) } - ', + GRAPHQL, 'variables' => [ 'file' => null, ], @@ -77,12 +77,12 @@ public function testUploadNull(): void public function testResolvesUploadViaBatchedMultipartRequest(): void { $operations = [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file1: Upload!, $file2: Upload!) { first: upload(file: $file1) second: upload(file: $file2) } - ', + GRAPHQL, 'variables' => [ 'file1' => null, 'file2' => null, diff --git a/tests/Integration/GlobalErrorRendererTest.php b/tests/Integration/GlobalErrorRendererTest.php index 40395c8be5..776085c473 100644 --- a/tests/Integration/GlobalErrorRendererTest.php +++ b/tests/Integration/GlobalErrorRendererTest.php @@ -31,17 +31,17 @@ protected function resolveApplicationExceptionHandler($app): void public function testCatchesErrorWithExtensions(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'errors' => [ [ 'message' => self::MESSAGE, diff --git a/tests/Integration/GlobalId/NodeDirectiveDBTest.php b/tests/Integration/GlobalId/NodeDirectiveDBTest.php index 60aff30853..0325473674 100644 --- a/tests/Integration/GlobalId/NodeDirectiveDBTest.php +++ b/tests/Integration/GlobalId/NodeDirectiveDBTest.php @@ -33,31 +33,31 @@ protected function setUp(): void public function testResolveNodes(): void { - $this->schema .= /** @lang GraphQL */ ' - type User @node(resolver: "Tests\\\Integration\\\GlobalId\\\NodeDirectiveDBTest@resolveNode") { + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type User @node(resolver: "Tests\\Integration\\GlobalId\\NodeDirectiveDBTest@resolveNode") { name: String! } - '; + GRAPHQL; $firstGlobalId = $this->globalIdResolver->encode('User', self::TEST_TUPLES[1]['id']); $secondGlobalId = $this->globalIdResolver->encode('User', self::TEST_TUPLES[2]['id']); - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'first' => [ 'id' => $firstGlobalId, @@ -73,27 +73,27 @@ public function testResolveNodes(): void public function testResolveNodesViaInterface(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' interface IUser { name: String! } - type User implements IUser @node(resolver: "Tests\\\Integration\\\GlobalId\\\NodeDirectiveDBTest@resolveNode") { + type User implements IUser @node(resolver: "Tests\\Integration\\GlobalId\\NodeDirectiveDBTest@resolveNode") { name: String! } - '; + GRAPHQL; $globalId = $this->globalIdResolver->encode('User', self::TEST_TUPLES[1]['id']); - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'node' => [ 'id' => $globalId, @@ -105,20 +105,20 @@ interface IUser { public function testUnknownNodeType(): void { - $this->schema .= /** @lang GraphQL */ ' - type User @node(resolver: "Tests\\\Integration\\\GlobalId\\\NodeDirectiveDBTest@resolveNode") { + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type User @node(resolver: "Tests\\Integration\\GlobalId\\NodeDirectiveDBTest@resolveNode") { name: String! } - '; + GRAPHQL; $globalId = $this->globalIdResolver->encode('WrongClass', self::TEST_TUPLES[1]['id']); - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'node' => null, ], @@ -132,24 +132,24 @@ public function testUnknownNodeType(): void public function testTypeWithoutNodeDirective(): void { - $this->schema .= /** @lang GraphQL */ ' - type User @node(resolver: "Tests\\\Integration\\\Schema\\\NodeDirectiveDBTest@resolveNode") { + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type User @node(resolver: "Tests\\Integration\\Schema\\NodeDirectiveDBTest@resolveNode") { name: String! } type User2 { name: String! } - '; + GRAPHQL; $globalId = $this->globalIdResolver->encode('User2', self::TEST_TUPLES[1]['id']); - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'node' => null, ], @@ -171,11 +171,11 @@ public static function resolveNode(int|string $id): array #[DataProvider('modelNodeDirectiveStyles')] public function testResolveModelsNodes(string $directiveDefinition): void { - $this->schema .= /** @lang GraphQL */ " + $this->schema .= /** @lang GraphQL */ <<make(); $this->assertInstanceOf(User::class, $user); @@ -184,16 +184,16 @@ public function testResolveModelsNodes(string $directiveDefinition): void $globalId = $this->globalIdResolver->encode('User', $user->getKey()); - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'node' => [ 'id' => $globalId, @@ -213,11 +213,11 @@ public static function modelNodeDirectiveStyles(): iterable public function testThrowsWhenNodeDirectiveIsDefinedOnNonObjectType(): void { $this->expectException(DefinitionException::class); - $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' input Foo @node { bar: ID } - '); + GRAPHQL); } public function testPreservesCustomNodeField(): void @@ -225,7 +225,7 @@ public function testPreservesCustomNodeField(): void $result = 42; $this->mockResolver($result); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Query { # Nonsensical example, just done this way for ease of testing. # Usually customization would have the purpose of adding middleware. @@ -235,13 +235,13 @@ public function testPreservesCustomNodeField(): void type User @node { name: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { node } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'node' => $result, ], diff --git a/tests/Integration/GraphQLTest.php b/tests/Integration/GraphQLTest.php index b24ae5bbff..5a3a11ca50 100644 --- a/tests/Integration/GraphQLTest.php +++ b/tests/Integration/GraphQLTest.php @@ -8,21 +8,21 @@ final class GraphQLTest extends TestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int bar: String } - '; + GRAPHQL; public function testResolvesQueryViaPostRequest(): void { $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ') + GRAPHQL) ->assertGraphQLErrorFree() ->assertExactJson([ 'data' => [ @@ -38,11 +38,11 @@ public function testResolvesQueryViaGetRequest(): void 'graphql?' . http_build_query( [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' { foo } - ', + GRAPHQL, ], ), ) @@ -57,14 +57,14 @@ public function testResolvesNamedOperation(): void { $this ->postGraphQL([ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' query Foo { foo } query Bar { bar } - ', + GRAPHQL, 'operationName' => 'Bar', ]) ->assertExactJson([ @@ -79,18 +79,18 @@ public function testResolveBatchedQueries(): void $this ->postGraphQL([ [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' { foo } - ', + GRAPHQL, ], [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' { bar } - ', + GRAPHQL, ], ]) ->assertExactJson([ diff --git a/tests/Integration/IntrospectionTest.php b/tests/Integration/IntrospectionTest.php index 8ef219db4f..4af8df8556 100644 --- a/tests/Integration/IntrospectionTest.php +++ b/tests/Integration/IntrospectionTest.php @@ -21,11 +21,11 @@ protected function setUp(): void public function testFindsTypesFromSchema(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Foo { bar: Int } - '; + GRAPHQL; $this->assertNotNull( $this->introspectType('Foo'), diff --git a/tests/Integration/LifecycleEventsTest.php b/tests/Integration/LifecycleEventsTest.php index 2eb14e2c8f..661fb763c5 100644 --- a/tests/Integration/LifecycleEventsTest.php +++ b/tests/Integration/LifecycleEventsTest.php @@ -35,17 +35,17 @@ public function testDispatchesProperLifecycleEvents(): void $this->mockResolver(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); [ $startRequest, diff --git a/tests/Integration/Models/PropertyAccessTest.php b/tests/Integration/Models/PropertyAccessTest.php index a95583e589..29372d2731 100644 --- a/tests/Integration/Models/PropertyAccessTest.php +++ b/tests/Integration/Models/PropertyAccessTest.php @@ -16,7 +16,7 @@ public function testLaravelDatabaseProperty(): void $user->name = $name; $user->save(); - $this->schema = /** @lang GraphQL */ <<schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -27,13 +27,13 @@ public function testLaravelDatabaseProperty(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { name } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertJson([ 'data' => [ @@ -49,7 +49,7 @@ public function testLaravelFunctionProperty(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ <<schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! laravel_function_property: String! @@ -60,13 +60,13 @@ public function testLaravelFunctionProperty(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { laravel_function_property } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertJson([ 'data' => [ @@ -83,7 +83,7 @@ public function testPhpProperty(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ <<schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! php_property: String @@ -94,13 +94,13 @@ public function testPhpProperty(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { php_property } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertJson([ 'data' => [ @@ -118,7 +118,7 @@ public function testPrefersAttributeAccessorThatShadowsPhpProperty(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ <<schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! incrementing: String! @@ -129,13 +129,13 @@ public function testPrefersAttributeAccessorThatShadowsPhpProperty(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { incrementing } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertJson([ 'data' => [ @@ -152,7 +152,7 @@ public function testPrefersAttributeAccessorNullThatShadowsPhpProperty(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ <<schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! exists: Boolean @@ -163,13 +163,13 @@ public function testPrefersAttributeAccessorNullThatShadowsPhpProperty(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { exists } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertJson([ 'data' => [ @@ -186,7 +186,7 @@ public function testExpensivePropertyIsOnlyCalledOnce(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ <<schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! expensive_property: Int! @@ -197,13 +197,13 @@ public function testExpensivePropertyIsOnlyCalledOnce(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { expensive_property } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertJson([ 'data' => [ diff --git a/tests/Integration/MultipleRequestsTest.php b/tests/Integration/MultipleRequestsTest.php index 1e4d2f1221..ada96a21bb 100644 --- a/tests/Integration/MultipleRequestsTest.php +++ b/tests/Integration/MultipleRequestsTest.php @@ -10,27 +10,27 @@ public function testFireMultipleRequestsInOneTest(): void { $this->mockResolver(static fn ($_, array $args): string => $args['this']); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { return(this: String!): String @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { return(this: "foo") } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'return' => 'foo', ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { return(this: "bar") } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'return' => 'bar', ], diff --git a/tests/Integration/OrderBy/OrderByDirectiveDBTest.php b/tests/Integration/OrderBy/OrderByDirectiveDBTest.php index 2d4b4c8166..ba085175e6 100644 --- a/tests/Integration/OrderBy/OrderByDirectiveDBTest.php +++ b/tests/Integration/OrderBy/OrderByDirectiveDBTest.php @@ -9,7 +9,7 @@ final class OrderByDirectiveDBTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users( orderBy: _ @orderBy @@ -26,14 +26,14 @@ final class OrderByDirectiveDBTest extends DBTestCase enum UserColumn { NAME @enum(value: "name") } - '; + GRAPHQL; public function testOrderByTheGivenColumnAndSortOrderASC(): void { $this->createUser('B'); $this->createUser('A'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( orderBy: [ @@ -46,7 +46,7 @@ public function testOrderByTheGivenColumnAndSortOrderASC(): void name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -65,7 +65,7 @@ public function testOrderByTheGivenFieldAndSortOrderDESC(): void $this->createUser('B'); $this->createUser('A'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( orderBy: [ @@ -78,7 +78,7 @@ public function testOrderByTheGivenFieldAndSortOrderDESC(): void name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -98,7 +98,7 @@ public function testOrderByMultipleColumns(): void $this->createUser('A', 5); $this->createUser('C', 2); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( orderBy: [ @@ -116,7 +116,7 @@ public function testOrderByMultipleColumns(): void name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -141,7 +141,7 @@ public function testOrderWithRestrictedColumns(): void $this->createUser('B'); $this->createUser('A'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( orderByRestricted: [ @@ -154,7 +154,7 @@ public function testOrderWithRestrictedColumns(): void name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -173,7 +173,7 @@ public function testUseColumnEnumsArg(): void $this->createUser('B'); $this->createUser('A'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( orderByRestrictedEnum: [ @@ -186,7 +186,7 @@ public function testUseColumnEnumsArg(): void name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -204,7 +204,7 @@ public function testRejectsDefinitionWithDuplicateColumnArgument(): void { $this->expectException(DefinitionException::class); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { users( orderBy: _ @orderBy(columns: ["name"], columnsEnum: "UserColumn") @@ -219,7 +219,7 @@ public function testRejectsDefinitionWithDuplicateColumnArgument(): void enum UserColumn { NAME @enum(value: "name") } - '); + GRAPHQL); } public function testOrderColumnOnField(): void @@ -234,7 +234,7 @@ public function testOrderColumnOnField(): void $userB->name = 'B'; $userB->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { latestUsers: [User!]! @all @@ -244,15 +244,15 @@ public function testOrderColumnOnField(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { latestUsers { name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'latestUsers' => [ [ @@ -268,7 +268,7 @@ public function testOrderColumnOnField(): void public function testOrderByRelationCount(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users( orderBy: _ @orderBy(relations: [ @@ -282,7 +282,7 @@ public function testOrderByRelationCount(): void type User { id: Int! } - '; + GRAPHQL; $userA = factory(User::class)->create(); $this->assertInstanceOf(User::class, $userA); @@ -297,7 +297,7 @@ public function testOrderByRelationCount(): void factory(Task::class, 2)->create(), ); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( orderBy: [ @@ -310,7 +310,7 @@ public function testOrderByRelationCount(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -323,7 +323,7 @@ public function testOrderByRelationCount(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( orderBy: [ @@ -336,7 +336,7 @@ public function testOrderByRelationCount(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -352,7 +352,7 @@ public function testOrderByRelationCount(): void public function testOrderByRelationAggregate(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users( orderBy: _ @orderBy(relations: [ @@ -371,7 +371,7 @@ public function testOrderByRelationAggregate(): void enum UserColumn { NAME @enum(value: "name") } - '; + GRAPHQL; $userA = factory(User::class)->create(); $this->assertInstanceOf(User::class, $userA); @@ -389,7 +389,7 @@ enum UserColumn { $taskB1->difficulty = 2; $userB->tasks()->save($taskB1); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( orderBy: [ @@ -402,7 +402,7 @@ enum UserColumn { id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -415,7 +415,7 @@ enum UserColumn { ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( orderBy: [ @@ -428,7 +428,7 @@ enum UserColumn { id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ diff --git a/tests/Integration/OrderBy/OrderByDirectiveTest.php b/tests/Integration/OrderBy/OrderByDirectiveTest.php index 1da4e882e8..68406cf9e0 100644 --- a/tests/Integration/OrderBy/OrderByDirectiveTest.php +++ b/tests/Integration/OrderBy/OrderByDirectiveTest.php @@ -10,13 +10,13 @@ final class OrderByDirectiveTest extends TestCase { public function testGeneratesInputWithFullyQualifiedName(): void { - $schemaString = /** @lang GraphQL */ ' + $schemaString = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( orderBy: _ @orderBy(columns: ["bar"]) ): ID @mock } - '; + GRAPHQL; $schema = $this->buildSchema($schemaString); $input = $schema->getType( @@ -30,7 +30,7 @@ public function testGeneratesInputWithFullyQualifiedName(): void public function testGeneratesInputWithFullyQualifiedNameUsingRelations(): void { - $schemaString = /** @lang GraphQL */ ' + $schemaString = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( orderBy: _ @orderBy( @@ -42,7 +42,7 @@ public function testGeneratesInputWithFullyQualifiedNameUsingRelations(): void ) ): ID @mock } - '; + GRAPHQL; $schema = $this->buildSchema($schemaString); @@ -82,7 +82,7 @@ public function testGeneratesInputWithFullyQualifiedNameUsingRelations(): void public function testValidatesOnlyColumnOrOneRelationIsUsed(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( orderBy: _ @orderBy( @@ -94,10 +94,10 @@ public function testValidatesOnlyColumnOrOneRelationIsUsed(): void ) ): ID @mock } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(orderBy: [{ column: BAR @@ -105,12 +105,12 @@ public function testValidatesOnlyColumnOrOneRelationIsUsed(): void order: ASC }]) } - ') + GRAPHQL) ->assertGraphQLValidationError('orderBy.0.column', 'The order by.0.column field prohibits order by.0.foo / order by.0.baz from being present.') ->assertGraphQLValidationError('orderBy.0.foo', 'The order by.0.foo field prohibits order by.0.column / order by.0.baz from being present.'); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(orderBy: [{ foo: { aggregate: COUNT } @@ -118,7 +118,7 @@ public function testValidatesOnlyColumnOrOneRelationIsUsed(): void order: ASC }]) } - ') + GRAPHQL) ->assertGraphQLValidationError('orderBy.0.foo', 'The order by.0.foo field prohibits order by.0.column / order by.0.baz from being present.') ->assertGraphQLValidationError('orderBy.0.baz', 'The order by.0.baz field prohibits order by.0.column / order by.0.foo from being present.'); } diff --git a/tests/Integration/Pagination/PaginateDirectiveDBTest.php b/tests/Integration/Pagination/PaginateDirectiveDBTest.php index 3a88b068a9..b49ac5e718 100644 --- a/tests/Integration/Pagination/PaginateDirectiveDBTest.php +++ b/tests/Integration/Pagination/PaginateDirectiveDBTest.php @@ -23,7 +23,7 @@ public function testPaginate(): void { factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -31,9 +31,9 @@ public function testPaginate(): void type Query { users: [User!]! @paginate } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 2) { paginatorInfo { @@ -46,7 +46,7 @@ public function testPaginate(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'paginatorInfo' => [ @@ -75,7 +75,7 @@ public function testSpecifyCustomBuilder(): void GRAPHQL; // The custom builder is supposed to change the sort order - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 1) { data { @@ -83,7 +83,7 @@ public function testSpecifyCustomBuilder(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'data' => [ @@ -120,7 +120,7 @@ public function testSpecifyCustomBuilderForRelation(): void GRAPHQL; // The custom builder is supposed to change the sort order - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<id}) { posts(first: 10) { @@ -130,7 +130,7 @@ public function testSpecifyCustomBuilderForRelation(): void } } } - ")->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'posts' => [ @@ -185,7 +185,7 @@ public function testSpecifyCustomBuilderForScoutBuilder(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($first: Int!, $page: Int!, $id: ID!) { posts(first: $first, page: $page, id: $id) { data { @@ -193,7 +193,7 @@ public function testSpecifyCustomBuilderForScoutBuilder(): void } } } - ', [ + GRAPHQL, [ 'first' => $first, 'page' => $page, 'id' => $post->id, @@ -222,7 +222,7 @@ public function testPaginateWithScopes(): void $unnamedUser->name = null; $unnamedUser->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: String! } @@ -230,9 +230,9 @@ public function testPaginateWithScopes(): void type Query { users: [User!]! @paginate(scopes: ["named"]) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 5) { paginatorInfo { @@ -245,7 +245,7 @@ public function testPaginateWithScopes(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ 'paginatorInfo' => [ @@ -306,7 +306,7 @@ public function testCreateQueryPaginatorsWithDifferentPages(): void $comment->save(); } - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { posts: [Post!]! @paginate } @@ -322,9 +322,9 @@ public function testCreateQueryPaginatorsWithDifferentPages(): void type Query { users: [User!]! @paginate } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 2, page: 1) { paginatorInfo { @@ -352,7 +352,7 @@ public function testCreateQueryPaginatorsWithDifferentPages(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'paginatorInfo' => [ @@ -385,7 +385,7 @@ public function testCreateQueryConnections(): void { factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -393,9 +393,9 @@ public function testCreateQueryConnections(): void type Query { users: [User!]! @paginate(type: CONNECTION) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 2) { pageInfo { @@ -408,7 +408,7 @@ public function testCreateQueryConnections(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'pageInfo' => [ @@ -421,7 +421,7 @@ public function testCreateQueryConnections(): void public function testQueriesConnectionWithNoData(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -429,9 +429,9 @@ public function testQueriesConnectionWithNoData(): void type Query { users: [User!]! @paginate(type: CONNECTION) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 5) { pageInfo { @@ -451,7 +451,7 @@ public function testQueriesConnectionWithNoData(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ 'pageInfo' => [ @@ -472,7 +472,7 @@ public function testQueriesConnectionWithNoData(): void public function testQueriesPaginationWithNoData(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -480,9 +480,9 @@ public function testQueriesPaginationWithNoData(): void type Query { users: [User!]! @paginate } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 5) { paginatorInfo { @@ -500,7 +500,7 @@ public function testQueriesPaginationWithNoData(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ 'paginatorInfo' => [ @@ -524,7 +524,7 @@ public function testQueriesFirst0(): void $amount = 3; factory(User::class, $amount)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -532,9 +532,9 @@ public function testQueriesFirst0(): void type Query { users: [User!]! @paginate } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 0) { paginatorInfo { @@ -552,7 +552,7 @@ public function testQueriesFirst0(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ 'paginatorInfo' => [ @@ -576,7 +576,7 @@ public function testQueriesPaginationWithoutPaginatorInfo(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -584,10 +584,10 @@ public function testQueriesPaginationWithoutPaginatorInfo(): void type Query { users: [User!]! @paginate } - '; + GRAPHQL; $this->assertQueryCountMatches(1, function () use ($user): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 1) { data { @@ -595,7 +595,7 @@ public function testQueriesPaginationWithoutPaginatorInfo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'data' => [ @@ -614,7 +614,7 @@ public function testQueriesConnectionWithoutPageInfo(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -622,10 +622,10 @@ public function testQueriesConnectionWithoutPageInfo(): void type Query { users: [User!]! @paginate(type: CONNECTION) } - '; + GRAPHQL; $this->assertQueryCountMatches(1, function () use ($user): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 1) { edges { @@ -635,7 +635,7 @@ public function testQueriesConnectionWithoutPageInfo(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'edges' => [ @@ -655,7 +655,7 @@ public function testQueriesConnectionPageOffset(): void { $users = factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -663,10 +663,10 @@ public function testQueriesConnectionPageOffset(): void type Query { users: [User!]! @paginate(type: CONNECTION) } - '; + GRAPHQL; $this->assertQueryCountMatches(2, function () use ($users): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($after: String!) { users(first: 2, after: $after) { pageInfo { @@ -686,7 +686,7 @@ public function testQueriesConnectionPageOffset(): void } } } - ', [ + GRAPHQL, [ 'after' => Cursor::encode(2), ])->assertJson([ 'data' => [ @@ -718,7 +718,7 @@ public function testQueriesConnectionPageOffsetWithoutPageInfo(): void { $users = factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -726,12 +726,12 @@ public function testQueriesConnectionPageOffsetWithoutPageInfo(): void type Query { users: [User!]! @paginate(type: CONNECTION) } - '; + GRAPHQL; $cursor = Cursor::encode(2); $this->assertQueryCountMatches(1, function () use ($users): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($after: String!) { users(first: 2, after: $after) { edges { @@ -741,7 +741,7 @@ public function testQueriesConnectionPageOffsetWithoutPageInfo(): void } } } - ', [ + GRAPHQL, [ 'after' => Cursor::encode(2), ])->assertJson([ 'data' => [ @@ -763,7 +763,7 @@ public function testPaginatesWhenDefinedInTypeExtension(): void { factory(User::class, 2)->create(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -771,9 +771,9 @@ public function testPaginatesWhenDefinedInTypeExtension(): void extend type Query { users: [User!]! @paginate(model: "User") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 1) { data { @@ -781,14 +781,14 @@ public function testPaginatesWhenDefinedInTypeExtension(): void } } } - ')->assertJsonCount(1, 'data.users.data'); + GRAPHQL)->assertJsonCount(1, 'data.users.data'); } public function testDefaultPaginationCount(): void { factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -796,9 +796,9 @@ public function testDefaultPaginationCount(): void type Query { users: [User!]! @paginate(defaultCount: 2) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { paginatorInfo { @@ -811,7 +811,7 @@ public function testDefaultPaginationCount(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'paginatorInfo' => [ @@ -829,7 +829,7 @@ public function testDoesNotRequireDefaultCountArgIfDefinedInConfig(): void $defaultCount = 2; config(['lighthouse.pagination.default_count' => $defaultCount]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -838,9 +838,9 @@ public function testDoesNotRequireDefaultCountArgIfDefinedInConfig(): void type Query { users: [User!] @paginate } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { data { @@ -848,14 +848,14 @@ public function testDoesNotRequireDefaultCountArgIfDefinedInConfig(): void } } } - ')->assertJsonCount($defaultCount, 'data.users.data'); + GRAPHQL)->assertJsonCount($defaultCount, 'data.users.data'); } public function testIsUnlimitedByMaxCountFromDirective(): void { config(['lighthouse.pagination.max_count' => 5]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -864,10 +864,10 @@ public function testIsUnlimitedByMaxCountFromDirective(): void type Query { users: [User!]! @paginate(maxCount: null) } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 10) { data { @@ -876,7 +876,7 @@ public function testIsUnlimitedByMaxCountFromDirective(): void } } } - ') + GRAPHQL) ->assertGraphQLErrorFree(); } @@ -885,7 +885,7 @@ public function testQueriesSimplePagination(): void config(['lighthouse.pagination.default_count' => 10]); factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -895,11 +895,11 @@ public function testQueriesSimplePagination(): void usersPaginated: [User!] @paginate(type: PAGINATOR) usersSimplePaginated: [User!] @paginate(type: SIMPLE) } - '; + GRAPHQL; // "paginate" fires 2 queries: One for data, one for counting. $this->assertQueryCountMatches(2, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { usersPaginated { paginatorInfo { @@ -910,12 +910,12 @@ public function testQueriesSimplePagination(): void } } } - ')->assertJsonCount(3, 'data.usersPaginated.data'); + GRAPHQL)->assertJsonCount(3, 'data.usersPaginated.data'); }); // "simplePaginate" only fires one query for the data. $this->assertQueryCountMatches(1, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { usersSimplePaginated { data { @@ -923,7 +923,7 @@ public function testQueriesSimplePagination(): void } } } - ')->assertJsonCount(3, 'data.usersSimplePaginated.data'); + GRAPHQL)->assertJsonCount(3, 'data.usersSimplePaginated.data'); }); } @@ -932,7 +932,7 @@ public function testGetSimplePaginationAttributes(): void config(['lighthouse.pagination.default_count' => 10]); factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -941,9 +941,9 @@ public function testGetSimplePaginationAttributes(): void type Query { users: [User!] @paginate(type: SIMPLE) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { paginatorInfo { @@ -955,7 +955,7 @@ public function testGetSimplePaginationAttributes(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'paginatorInfo' => [ @@ -975,7 +975,7 @@ public function testPaginateWithCacheDirective(): void $this->expectNotToPerformAssertions(); factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -983,9 +983,9 @@ public function testPaginateWithCacheDirective(): void type Query { users: [User!]! @paginate @cache } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 2) { data { @@ -993,9 +993,9 @@ public function testPaginateWithCacheDirective(): void } } } - '); + GRAPHQL); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 2) { paginatorInfo { @@ -1008,14 +1008,14 @@ public function testPaginateWithCacheDirective(): void } } } - '); + GRAPHQL); } public function testSimplePaginationWithNullPageUsesDefaultPage(): void { factory(User::class, 3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -1024,9 +1024,9 @@ public function testSimplePaginationWithNullPageUsesDefaultPage(): void type Query { users: [User!] @paginate(type: SIMPLE) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($page: Int) { users(first: 2, page: $page) { paginatorInfo { @@ -1038,7 +1038,7 @@ public function testSimplePaginationWithNullPageUsesDefaultPage(): void } } } - ', [ + GRAPHQL, [ 'page' => null, ])->assertJson([ 'data' => [ diff --git a/tests/Integration/Pennant/FeatureDirectiveTest.php b/tests/Integration/Pennant/FeatureDirectiveTest.php index 3cce571f79..b4b89850fb 100644 --- a/tests/Integration/Pennant/FeatureDirectiveTest.php +++ b/tests/Integration/Pennant/FeatureDirectiveTest.php @@ -42,7 +42,7 @@ protected function getPackageProviders($app): array public function testUnavailableWhenFeatureIsInactive(): void { - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenActive: String! @feature(name: "new-api", when: ACTIVE) @@ -50,7 +50,7 @@ public function testUnavailableWhenFeatureIsInactive(): void } GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { fieldWhenActive } @@ -61,7 +61,7 @@ public function testUnavailableWhenFeatureIsInactive(): void public function testUnavailableWhenFeatureIsInactiveWithDefaultFeatureState(): void { - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenActive: String! @feature(name: "new-api") @@ -69,7 +69,7 @@ public function testUnavailableWhenFeatureIsInactiveWithDefaultFeatureState(): v } GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { fieldWhenActive } @@ -81,7 +81,7 @@ public function testUnavailableWhenFeatureIsInactiveWithDefaultFeatureState(): v public function testUnavailableWhenFeatureIsActive(): void { Feature::define('new-api', static fn (): bool => true); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenInactive: String! @feature(name: "new-api", when: INACTIVE) @@ -89,7 +89,7 @@ public function testUnavailableWhenFeatureIsActive(): void } GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { fieldWhenInactive } @@ -103,7 +103,7 @@ public function testAvailableWhenFeatureIsActive(): void Feature::define('new-api', static fn (): bool => true); $fieldValue = 'active'; $this->mockResolver(static fn (): string => $fieldValue); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenActive: String! @feature(name: "new-api", when: ACTIVE) @@ -111,7 +111,7 @@ public function testAvailableWhenFeatureIsActive(): void } GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { fieldWhenActive } @@ -130,7 +130,7 @@ public function testAvailableWhenFeatureIsActiveWithDefaultFeatureState(): void Feature::define('new-api', static fn (): bool => true); $fieldValue = 'active'; $this->mockResolver(static fn (): string => $fieldValue); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenActive: String! @feature(name: "new-api") @@ -138,7 +138,7 @@ public function testAvailableWhenFeatureIsActiveWithDefaultFeatureState(): void } GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { fieldWhenActive } @@ -156,7 +156,7 @@ public function testAvailableWhenFeatureIsInactive(): void { $fieldValue = 'inactive'; $this->mockResolver(static fn (): string => $fieldValue); - $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenInactive: String! @feature(name: "new-api", when: INACTIVE) @@ -164,7 +164,7 @@ public function testAvailableWhenFeatureIsInactive(): void } GRAPHQL; - $response = $this->graphQL(/* @lang GraphQL */ <<<'GRAPHQL' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { fieldWhenInactive } diff --git a/tests/Integration/QueryCacheTest.php b/tests/Integration/QueryCacheTest.php index 23c659febd..8f17003c79 100644 --- a/tests/Integration/QueryCacheTest.php +++ b/tests/Integration/QueryCacheTest.php @@ -72,12 +72,12 @@ public function testDifferentQueriesHasDifferentKeys(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], diff --git a/tests/Integration/ReportingErrorHandlerTest.php b/tests/Integration/ReportingErrorHandlerTest.php index e7b77620f9..1b1cc0ec81 100644 --- a/tests/Integration/ReportingErrorHandlerTest.php +++ b/tests/Integration/ReportingErrorHandlerTest.php @@ -9,11 +9,11 @@ final class ReportingErrorHandlerTest extends TestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID @mock } - '; + GRAPHQL; public function testReportsNonClientSafeErrors(): void { @@ -27,11 +27,11 @@ public function testReportsNonClientSafeErrors(): void ->with($exception); $this->app->singleton(ExceptionHandler::class, static fn (): MockObject => $handler); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } public function testDoesNotReportClientSafeErrors(): void @@ -46,10 +46,10 @@ public function testDoesNotReportClientSafeErrors(): void ->with($error); $this->app->singleton(ExceptionHandler::class, static fn (): MockObject => $handler); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } } diff --git a/tests/Integration/Schema/Directives/AggregateDirectiveTest.php b/tests/Integration/Schema/Directives/AggregateDirectiveTest.php index 6abb29be43..e43a51c796 100644 --- a/tests/Integration/Schema/Directives/AggregateDirectiveTest.php +++ b/tests/Integration/Schema/Directives/AggregateDirectiveTest.php @@ -13,41 +13,41 @@ final class AggregateDirectiveTest extends DBTestCase { public function testRequiresARelationOrModelArgument(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { tasks: Int @aggregate } - '; + GRAPHQL; $this->expectException(DefinitionException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks } - '); + GRAPHQL); } public function testAggregateModel(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { sum: Int! @aggregate(model: "Task", function: SUM, column: "difficulty") avg: Float! @aggregate(model: "Task", function: AVG, column: "difficulty") min: Int! @aggregate(model: "Task", function: MIN, column: "difficulty") max: Int! @aggregate(model: "Task", function: MAX, column: "difficulty") } - '; + GRAPHQL; $tasks = factory(Task::class, 3)->create(); - $response = $this->graphQL(/** @lang GraphQL */ ' + $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { sum avg min max } - '); + GRAPHQL); $response->assertJson([ 'data' => [ @@ -66,11 +66,11 @@ public function testAggregateModel(): void public function testSumModelWithScopes(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { finished: Int! @aggregate(model: "Task", function: SUM, column: "difficulty", scopes: ["completed"]) } - '; + GRAPHQL; factory(Task::class, 3)->create(); $completed = factory(Task::class, 2)->create(); @@ -79,11 +79,11 @@ public function testSumModelWithScopes(): void $task->save(); }); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { finished } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'finished' => $completed->sum('difficulty'), ], @@ -92,7 +92,7 @@ public function testSumModelWithScopes(): void public function testSumRelationEagerLoad(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [User!] @all } @@ -100,7 +100,7 @@ public function testSumRelationEagerLoad(): void type User { workload: Int! @aggregate(relation: "tasks", function: SUM, column: "difficulty") } - '; + GRAPHQL; factory(User::class, 3) ->create() @@ -113,13 +113,13 @@ public function testSumRelationEagerLoad(): void }); $this->assertQueryCountMatches(2, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { workload } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -139,7 +139,7 @@ public function testSumRelationEagerLoad(): void public function testSumRelationWithScopes(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User @first } @@ -147,7 +147,7 @@ public function testSumRelationWithScopes(): void type User { finished: Int! @aggregate(relation: "tasks", function: SUM, column: "difficulty", scopes: ["completed"]) } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -159,13 +159,13 @@ public function testSumRelationWithScopes(): void $this->assertInstanceOf(Task::class, $completed); $user->tasks()->save($completed); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { finished } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'user' => [ 'finished' => $completed->difficulty, @@ -176,7 +176,7 @@ public function testSumRelationWithScopes(): void public function testMultipleAggregatesOnSameRelationWithAliases(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { difficulty( minimum: Int @where(key: "difficulty", operator: ">=") @@ -187,7 +187,7 @@ public function testMultipleAggregatesOnSameRelationWithAliases(): void type Query { users: [User!]! @all } - '; + GRAPHQL; $user1 = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user1); @@ -216,14 +216,14 @@ public function testMultipleAggregatesOnSameRelationWithAliases(): void $user2->tasks()->save($high2); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query { users { lowDifficulty: difficulty(maximum: 9000) highDifficulty: difficulty(minimum: 9000) } } - ') + GRAPHQL) ->assertExactJson([ 'data' => [ 'users' => [ @@ -242,14 +242,14 @@ public function testMultipleAggregatesOnSameRelationWithAliases(): void public function testAggregateWithBuilder(): void { - $this->schema = /** @lang GraphQL */ " + $this->schema = /** @lang GraphQL */ <<qualifyTestResolver('builder')}\", function: SUM, column: \"difficulty\") + ): Int! @aggregate(builder: "{$this->qualifyTestResolver('builder')}", function: SUM, column: "difficulty") } - "; + GRAPHQL; $difficulty = 5; @@ -273,11 +273,11 @@ public function testAggregateWithBuilder(): void $task4->difficulty = $difficulty; $task4->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($difficulty: Int!, $exclude: ID!) { sum(difficulty: $difficulty, exclude: $exclude) } - ', [ + GRAPHQL, [ 'difficulty' => $difficulty, 'exclude' => $task4->id, ])->assertJson([ diff --git a/tests/Integration/Schema/Directives/AllDirectiveTest.php b/tests/Integration/Schema/Directives/AllDirectiveTest.php index f206c82250..2be3c1d2cd 100644 --- a/tests/Integration/Schema/Directives/AllDirectiveTest.php +++ b/tests/Integration/Schema/Directives/AllDirectiveTest.php @@ -22,7 +22,7 @@ public function testGetAllModelsAsRootField(): void $count = 2; factory(User::class, $count)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -30,15 +30,15 @@ public function testGetAllModelsAsRootField(): void type Query { users: [User!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id } } - ')->assertJsonCount($count, 'data.users'); + GRAPHQL)->assertJsonCount($count, 'data.users'); } public function testExplicitModelName(): void @@ -46,7 +46,7 @@ public function testExplicitModelName(): void $count = 2; factory(User::class, $count)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo { id: ID! } @@ -54,15 +54,15 @@ public function testExplicitModelName(): void type Query { foos: [Foo!]! @all(model: "User") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foos { id } } - ')->assertJsonCount($count, 'data.foos'); + GRAPHQL)->assertJsonCount($count, 'data.foos'); } public function testRenamedModelWithModelDirective(): void @@ -70,7 +70,7 @@ public function testRenamedModelWithModelDirective(): void $count = 2; factory(User::class, $count)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo @model(class: "User") { id: ID! } @@ -78,15 +78,15 @@ public function testRenamedModelWithModelDirective(): void type Query { foos: [Foo!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foos { id } } - ')->assertJsonCount($count, 'data.foos'); + GRAPHQL)->assertJsonCount($count, 'data.foos'); } public function testGetAllAsNestedField(): void @@ -99,7 +99,7 @@ public function testGetAllAsNestedField(): void $post->save(); }); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { posts: [Post!]! @all } @@ -111,9 +111,9 @@ public function testGetAllAsNestedField(): void type Query { users: [User!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { posts { @@ -121,7 +121,7 @@ public function testGetAllAsNestedField(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ [ @@ -154,7 +154,7 @@ public function testGetAllModelsFiltered(): void $users = factory(User::class, 3)->create(); $userName = $users->first()->name; - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -163,16 +163,16 @@ public function testGetAllModelsFiltered(): void type Query { users(name: String @neq): [User!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<assertJsonCount(2, 'data.users'); + GRAPHQL)->assertJsonCount(2, 'data.users'); } public function testSpecifyCustomBuilder(): void @@ -191,13 +191,13 @@ public function testSpecifyCustomBuilder(): void GRAPHQL; // The custom builder is supposed to change the sort order - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ [ @@ -235,7 +235,7 @@ public function testSpecifyCustomBuilderForRelation(): void GRAPHQL; // The custom builder is supposed to change the sort order - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<id}) { posts { @@ -243,7 +243,7 @@ public function testSpecifyCustomBuilderForRelation(): void } } } - ")->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'posts' => [ @@ -284,13 +284,13 @@ public function testSpecifyCustomBuilderForScoutBuilder(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { posts(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $post->id, ])->assertJson([ 'data' => [ diff --git a/tests/Integration/Schema/Directives/BelongsToDirectiveTest.php b/tests/Integration/Schema/Directives/BelongsToDirectiveTest.php index 482a656868..929d16b6c7 100644 --- a/tests/Integration/Schema/Directives/BelongsToDirectiveTest.php +++ b/tests/Integration/Schema/Directives/BelongsToDirectiveTest.php @@ -22,7 +22,7 @@ public function testResolveBelongsToRelationship(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { name: String! } @@ -34,9 +34,9 @@ public function testResolveBelongsToRelationship(): void type Query { user: User @auth } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { company { @@ -44,7 +44,7 @@ public function testResolveBelongsToRelationship(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'company' => [ @@ -66,7 +66,7 @@ public function testResolveBelongsToWithCustomName(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { name: String! } @@ -78,9 +78,9 @@ public function testResolveBelongsToWithCustomName(): void type Query { user: User @auth } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { account { @@ -88,7 +88,7 @@ public function testResolveBelongsToWithCustomName(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'account' => [ @@ -112,7 +112,7 @@ public function testResolveBelongsToRelationshipWithTwoRelation(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { name: String! } @@ -129,9 +129,9 @@ public function testResolveBelongsToRelationshipWithTwoRelation(): void type Query { user: User @auth } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { company { @@ -142,7 +142,7 @@ public function testResolveBelongsToRelationshipWithTwoRelation(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'company' => [ @@ -160,7 +160,7 @@ public function testResolveBelongsToRelationshipWhenMainModelHasCompositePrimary { $products = factory(Product::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Color { id: ID! name: String @@ -177,9 +177,9 @@ public function testResolveBelongsToRelationshipWhenMainModelHasCompositePrimary type Query { products: [Product] @paginate } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { products(first: 2) { data{ @@ -193,7 +193,7 @@ public function testResolveBelongsToRelationshipWhenMainModelHasCompositePrimary } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'products' => [ 'data' => [ @@ -223,7 +223,7 @@ public function testBelongsToItself(): void $child->parent()->associate($parent); $child->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: Int! parent: Post @belongsTo @@ -232,10 +232,10 @@ public function testBelongsToItself(): void type Query { posts: [Post!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts { id @@ -244,7 +244,7 @@ public function testBelongsToItself(): void } } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'posts' => [ @@ -274,7 +274,7 @@ public function testDoesNotShortcutForeignKeySelectionByDefault(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! @rename(attribute: "uuid") } @@ -286,9 +286,9 @@ public function testDoesNotShortcutForeignKeySelectionByDefault(): void type Query { user: User @auth } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { company { @@ -296,7 +296,7 @@ public function testDoesNotShortcutForeignKeySelectionByDefault(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'company' => [ @@ -323,7 +323,7 @@ public function testShortcutsForeignKeySelectID(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! } @@ -335,10 +335,10 @@ public function testShortcutsForeignKeySelectID(): void type Query { user: User @auth } - '; + GRAPHQL; $this->assertNoQueriesExecuted(function () use ($company): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { company { @@ -346,7 +346,7 @@ public function testShortcutsForeignKeySelectID(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'company' => [ @@ -374,7 +374,7 @@ public function testShortcutsForeignKeySelectTypename(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! } @@ -386,10 +386,10 @@ public function testShortcutsForeignKeySelectTypename(): void type Query { user: User @auth } - '; + GRAPHQL; $this->assertNoQueriesExecuted(function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { company { @@ -397,7 +397,7 @@ public function testShortcutsForeignKeySelectTypename(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'company' => [ @@ -425,7 +425,7 @@ public function testShortcutsForeignKeySelectIDAndTypename(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! } @@ -437,10 +437,10 @@ public function testShortcutsForeignKeySelectIDAndTypename(): void type Query { user: User @auth } - '; + GRAPHQL; $this->assertNoQueriesExecuted(function () use ($company): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { company { @@ -449,7 +449,7 @@ public function testShortcutsForeignKeySelectIDAndTypename(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'company' => [ @@ -476,7 +476,7 @@ public function testDoesNotShortcutForeignKeyIfQueryHasFieldSelection(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -489,10 +489,10 @@ public function testDoesNotShortcutForeignKeyIfQueryHasFieldSelection(): void type Query { user: User @auth } - '; + GRAPHQL; $this->assertQueryCountMatches(1, function () use ($company): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { company { @@ -501,7 +501,7 @@ public function testDoesNotShortcutForeignKeyIfQueryHasFieldSelection(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'company' => [ @@ -528,7 +528,7 @@ public function testDoesNotShortcutForeignKeyIfQueryHasConditions(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! } @@ -540,10 +540,10 @@ public function testDoesNotShortcutForeignKeyIfQueryHasConditions(): void type Query { user: User @auth } - '; + GRAPHQL; $this->assertQueryCountMatches(1, function () use ($company): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($name: String) { user { company(name: $name) { @@ -551,7 +551,7 @@ public function testDoesNotShortcutForeignKeyIfQueryHasConditions(): void } } } - ', [ + GRAPHQL, [ 'name' => "{$company->name} no match", ])->assertJson([ 'data' => [ diff --git a/tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php b/tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php index 460b8b5be6..24f10c5ee9 100644 --- a/tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php +++ b/tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php @@ -12,7 +12,7 @@ final class BelongsToManyDirectiveTest extends DBTestCase { public function testQueryBelongsToManyRelationship(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { roles: [Role!]! @belongsToMany } @@ -24,7 +24,7 @@ public function testQueryBelongsToManyRelationship(): void type Query { user: User! @auth } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -34,7 +34,7 @@ public function testQueryBelongsToManyRelationship(): void $roles = factory(Role::class, $rolesCount)->create(); $user->roles()->attach($roles); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { roles { @@ -42,12 +42,12 @@ public function testQueryBelongsToManyRelationship(): void } } } - ')->assertJsonCount($rolesCount, 'data.user.roles'); + GRAPHQL)->assertJsonCount($rolesCount, 'data.user.roles'); } public function testNameRelationExplicitly(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { foo: [Role!] @belongsToMany(relation: "roles") } @@ -59,7 +59,7 @@ public function testNameRelationExplicitly(): void type Query { user: User! @auth } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -69,7 +69,7 @@ public function testNameRelationExplicitly(): void $roles = factory(Role::class, $rolesCount)->create(); $user->roles()->attach($roles); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { foo { @@ -77,12 +77,12 @@ public function testNameRelationExplicitly(): void } } } - ')->assertJsonCount($rolesCount, 'data.user.foo'); + GRAPHQL)->assertJsonCount($rolesCount, 'data.user.foo'); } public function testQueryBelongsToManyPaginator(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { rolesPaginated: [Role!]! @belongsToMany(type: PAGINATOR, relation: "roles") rolesSimplePaginated: [Role!]! @belongsToMany(type: SIMPLE, relation: "roles") @@ -95,7 +95,7 @@ public function testQueryBelongsToManyPaginator(): void type Query { user: User! @auth } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -106,7 +106,7 @@ public function testQueryBelongsToManyPaginator(): void $user->roles()->attach($roles); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { rolesPaginated(first: 2) { @@ -129,7 +129,7 @@ public function testQueryBelongsToManyPaginator(): void } } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'user' => [ @@ -154,7 +154,7 @@ public function testQueryBelongsToManyPaginator(): void public function testQueryBelongsToManyRelayConnection(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { roles: [Role!]! @belongsToMany(type: CONNECTION) } @@ -166,7 +166,7 @@ public function testQueryBelongsToManyRelayConnection(): void type Query { user: User! @auth } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -175,7 +175,7 @@ public function testQueryBelongsToManyRelayConnection(): void $roles = factory(Role::class, 3)->create(); $user->roles()->attach($roles); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { roles(first: 2) { @@ -190,7 +190,7 @@ public function testQueryBelongsToManyRelayConnection(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'roles' => [ @@ -205,7 +205,7 @@ public function testQueryBelongsToManyRelayConnection(): void public function testQueryBelongsToManyRelayConnectionWithCustomEdgeUsingDirective(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { roles: [Role!]! @belongsToMany(type: CONNECTION, edgeType: "CustomRoleEdge") } @@ -223,7 +223,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomEdgeUsingDirectiv type Query { user: User! @auth } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -233,7 +233,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomEdgeUsingDirectiv $meta = ['meta' => 'new']; $user->roles()->attach($roles, $meta); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { roles(first: 2) { @@ -246,7 +246,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomEdgeUsingDirectiv } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'roles' => [ @@ -261,7 +261,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomEdgeUsingDirectiv public function testQueryBelongsToManyRelayConnectionWithCustomEdgeHavingPivotFieldUsingDirective(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { roles: [Role!]! @belongsToMany(type: CONNECTION, edgeType: "UserRoleEdge") } @@ -283,7 +283,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomEdgeHavingPivotFi type Query { user: User! @auth } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -293,7 +293,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomEdgeHavingPivotFi $meta = ['meta' => 'new']; $user->roles()->attach($roles, $meta); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { roles(first: 2) { @@ -308,13 +308,13 @@ public function testQueryBelongsToManyRelayConnectionWithCustomEdgeHavingPivotFi } } } - ')->assertJsonPath('data.user.roles.edges.*.pivot', array_fill(0, 2, $meta)) + GRAPHQL)->assertJsonPath('data.user.roles.edges.*.pivot', array_fill(0, 2, $meta)) ->assertJsonCount(2, 'data.user.roles.edges'); } public function testQueryBelongsToManyPivot(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { roles: [Role!]! @belongsToMany } @@ -331,7 +331,7 @@ public function testQueryBelongsToManyPivot(): void type Query { user: User! @auth } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -342,7 +342,7 @@ public function testQueryBelongsToManyPivot(): void $meta = ['meta' => 'new']; $user->roles()->attach($roles, $meta); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { roles { @@ -353,7 +353,7 @@ public function testQueryBelongsToManyPivot(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'roles' => [ @@ -371,7 +371,7 @@ public function testThrowsExceptionForInvalidEdgeTypeFromDirective(): void $this->expectExceptionObject(new DefinitionException( 'The `edgeType` argument of @belongsToMany on roles must reference an existing object type definition.', )); - $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type User { roles: [Role!]! @belongsToMany(type: CONNECTION, edgeType: "CustomRoleEdge") } @@ -379,12 +379,12 @@ public function testThrowsExceptionForInvalidEdgeTypeFromDirective(): void type Role { id: ID! } - '); + GRAPHQL); } public function testQueryBelongsToManyRelayConnectionWithCustomMagicEdge(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { roles: [Role!]! @belongsToMany(type: CONNECTION) } @@ -402,7 +402,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomMagicEdge(): void type Query { user: User! @auth } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -412,7 +412,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomMagicEdge(): void $meta = ['meta' => 'new']; $user->roles()->attach($roles, $meta); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { roles(first: 2) { @@ -425,7 +425,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomMagicEdge(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'roles' => [ @@ -440,7 +440,7 @@ public function testQueryBelongsToManyRelayConnectionWithCustomMagicEdge(): void public function testQueryPaginatedBelongsToManyWithDuplicates(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [User]! @all } @@ -453,7 +453,7 @@ public function testQueryPaginatedBelongsToManyWithDuplicates(): void type Role { id: ID! } - '; + GRAPHQL; $roles = factory(Role::class, 2)->create(); @@ -467,7 +467,7 @@ public function testQueryPaginatedBelongsToManyWithDuplicates(): void ->map(static fn (Role $role): array => ['id' => (string) $role->id]) ->all(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id @@ -478,7 +478,7 @@ public function testQueryPaginatedBelongsToManyWithDuplicates(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => $users ->map(static fn (User $user): array => [ @@ -494,7 +494,7 @@ public function testQueryPaginatedBelongsToManyWithDuplicates(): void public function testQueryBelongsToManyNestedRelationships(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! roles: [Role!]! @belongsToMany(type: CONNECTION) @@ -513,7 +513,7 @@ public function testQueryBelongsToManyNestedRelationships(): void type Query { user: User! @auth } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -522,7 +522,7 @@ public function testQueryBelongsToManyNestedRelationships(): void $roles = factory(Role::class, 3)->create(); $user->roles()->attach($roles); - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { roles(first: 2) { @@ -553,7 +553,7 @@ public function testQueryBelongsToManyNestedRelationships(): void } } } - '); + GRAPHQL); $this->assertTrue($result->json('data.user.roles.pageInfo.hasNextPage')); @@ -568,7 +568,7 @@ public function testQueryBelongsToManyNestedRelationships(): void public function testThrowsErrorWithUnknownTypeArg(): void { $this->expectExceptionObject(new DefinitionException('Found invalid pagination type: foo')); - $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type User { roles(first: Int! after: Int): [Role!]! @belongsToMany(type: "foo") } @@ -576,6 +576,6 @@ public function testThrowsErrorWithUnknownTypeArg(): void type Role { id: ID! } - '); + GRAPHQL); } } diff --git a/tests/Integration/Schema/Directives/BuilderDirectiveTest.php b/tests/Integration/Schema/Directives/BuilderDirectiveTest.php index 70b0bd89ca..7369084ec4 100644 --- a/tests/Integration/Schema/Directives/BuilderDirectiveTest.php +++ b/tests/Integration/Schema/Directives/BuilderDirectiveTest.php @@ -28,13 +28,13 @@ public function testCallsCustomBuilderMethod(): void factory(User::class, 2)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(limit: 1) { id } } - ')->assertJsonCount(1, 'data.users'); + GRAPHQL)->assertJsonCount(1, 'data.users'); } public function testCallsCustomBuilderMethodOnFieldCheckWithArgs(): void @@ -65,13 +65,13 @@ public function testCallsCustomBuilderMethodOnFieldCheckWithArgs(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(arg1: "Hello", arg2: "World") { id } } - '); + GRAPHQL); } public function testCallsCustomBuilderMethodOnFieldCheckWithoutArgs(): void @@ -100,13 +100,13 @@ public function testCallsCustomBuilderMethodOnFieldCheckWithoutArgs(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id } } - '); + GRAPHQL); } public function testCallsCustomBuilderMethodOnFieldWithValue(): void @@ -124,13 +124,13 @@ public function testCallsCustomBuilderMethodOnFieldWithValue(): void factory(User::class, 2)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id } } - ')->assertJsonCount(1, 'data.users'); + GRAPHQL)->assertJsonCount(1, 'data.users'); } public function testCallsCustomBuilderMethodOnFieldWithoutValue(): void @@ -147,13 +147,13 @@ public function testCallsCustomBuilderMethodOnFieldWithoutValue(): void factory(User::class, 3)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id } } - ')->assertJsonCount(2, 'data.users'); + GRAPHQL)->assertJsonCount(2, 'data.users'); } public function testCallsCustomBuilderMethodOnFieldWithSpecificModel(): void @@ -194,7 +194,7 @@ public function testCallsCustomBuilderMethodOnFieldWithSpecificModel(): void $taskWithOtherName->save(); } - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id @@ -205,7 +205,7 @@ public function testCallsCustomBuilderMethodOnFieldWithSpecificModel(): void } } } - ') + GRAPHQL) ->assertJsonCount(1, 'data.users.0.tasks.data') ->assertJsonCount(1, 'data.users.1.tasks.data'); } diff --git a/tests/Integration/Schema/Directives/ConvertEmptyStringsToNullDirectiveTest.php b/tests/Integration/Schema/Directives/ConvertEmptyStringsToNullDirectiveTest.php index 62710a7396..420ba1619c 100644 --- a/tests/Integration/Schema/Directives/ConvertEmptyStringsToNullDirectiveTest.php +++ b/tests/Integration/Schema/Directives/ConvertEmptyStringsToNullDirectiveTest.php @@ -9,19 +9,19 @@ final class ConvertEmptyStringsToNullDirectiveTest extends TestCase { public function testOnArgument(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: String @convertEmptyStringsToNull): String @mock } - '; + GRAPHQL; $this->mockResolver(static fn ($_, array $args): ?string => $args['bar']); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: "") } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => null, ], @@ -30,19 +30,19 @@ public function testOnArgument(): void public function testOnArgumentWithMatrix(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: [[[String]]] @convertEmptyStringsToNull): [[[String]]] @mock } - '; + GRAPHQL; $this->mockResolver(static fn ($_, array $args): ?array => $args['bar']); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: [[["", null, "baz"]]]) } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => [[[null, null, 'baz']]], ], @@ -53,7 +53,7 @@ public function testOnField(): void { $this->mockResolver(static fn ($_, array $args): array => $args); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Foo { foo: String bar: [String]! @@ -69,9 +69,9 @@ public function testOnField(): void qux: Int! ): Foo! @convertEmptyStringsToNull @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( foo: "" @@ -85,7 +85,7 @@ public function testOnField(): void qux } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => [ 'foo' => null, @@ -101,7 +101,7 @@ public function testDoesNotConvertNonNullableArgumentsWhenUsedOnField(): void { $this->mockResolver(static fn ($_, array $args): array => $args); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Foo { foo: String! bar: [String!]! @@ -115,9 +115,9 @@ public function testDoesNotConvertNonNullableArgumentsWhenUsedOnField(): void baz: [[[String!]]] ): Foo! @convertEmptyStringsToNull @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( foo: "" @@ -129,7 +129,7 @@ public function testDoesNotConvertNonNullableArgumentsWhenUsedOnField(): void baz } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => [ 'foo' => '', @@ -142,19 +142,19 @@ public function testDoesNotConvertNonNullableArgumentsWhenUsedOnField(): void public function testConvertsNonNullableArgumentsWhenUsedOnArgument(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: String! @convertEmptyStringsToNull): String @mock } - '; + GRAPHQL; $this->mockResolver(static fn ($_, array $args): ?string => $args['bar']); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: "") } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => null, ], @@ -163,25 +163,25 @@ public function testConvertsNonNullableArgumentsWhenUsedOnArgument(): void public function testConvertsEmptyStringToNullWithFieldDirective(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: String): FooResponse @convertEmptyStringsToNull - @field(resolver: "Tests\\\Utils\\\Mutations\\\ReturnReceivedInput") + @field(resolver: "Tests\\Utils\\Mutations\\ReturnReceivedInput") } type FooResponse { bar: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: "") { bar } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => [ 'bar' => null, @@ -196,24 +196,24 @@ public function testConvertsEmptyStringToNullWithGlobalFieldMiddleware(): void ConvertEmptyStringsToNullDirective::class, ]]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: String): FooResponse - @field(resolver: "Tests\\\Utils\\\Mutations\\\ReturnReceivedInput") + @field(resolver: "Tests\\Utils\\Mutations\\ReturnReceivedInput") } type FooResponse { bar: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: "") { bar } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => [ 'bar' => null, @@ -224,11 +224,11 @@ public function testConvertsEmptyStringToNullWithGlobalFieldMiddleware(): void public function testConvertsEmptyStringToNullWithFieldDirectiveAndInputType(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: FooInput): FooInputResponse @convertEmptyStringsToNull - @field(resolver: "Tests\\\Utils\\\Mutations\\\ReturnReceivedInput") + @field(resolver: "Tests\\Utils\\Mutations\\ReturnReceivedInput") } input FooInput { @@ -242,9 +242,9 @@ public function testConvertsEmptyStringToNullWithFieldDirectiveAndInputType(): v type FooResponse { bar: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(input: { bar: "" @@ -254,7 +254,7 @@ public function testConvertsEmptyStringToNullWithFieldDirectiveAndInputType(): v } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => [ 'input' => [ @@ -271,10 +271,10 @@ public function testConvertsEmptyStringToNullWithGlobalFieldMiddlewareAndInputTy ConvertEmptyStringsToNullDirective::class, ]]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: FooInput): FooInputResponse - @field(resolver: "Tests\\\Utils\\\Mutations\\\ReturnReceivedInput") + @field(resolver: "Tests\\Utils\\Mutations\\ReturnReceivedInput") } input FooInput { @@ -288,9 +288,9 @@ public function testConvertsEmptyStringToNullWithGlobalFieldMiddlewareAndInputTy type FooResponse { bar: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(input: { bar: "" @@ -300,7 +300,7 @@ public function testConvertsEmptyStringToNullWithGlobalFieldMiddlewareAndInputTy } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => [ 'input' => [ diff --git a/tests/Integration/Schema/Directives/CountDirectiveDBTest.php b/tests/Integration/Schema/Directives/CountDirectiveDBTest.php index 2b0bccd580..9d559eb149 100644 --- a/tests/Integration/Schema/Directives/CountDirectiveDBTest.php +++ b/tests/Integration/Schema/Directives/CountDirectiveDBTest.php @@ -15,35 +15,35 @@ final class CountDirectiveDBTest extends DBTestCase { public function testRequiresARelationOrModelArgument(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { tasks: Int @count } - '; + GRAPHQL; $this->expectException(DefinitionException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks } - '); + GRAPHQL); } public function testCountModel(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { tasks_count: Int @count(model: "Task") } - '; + GRAPHQL; factory(Task::class, 3)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks_count } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'tasks_count' => 3, ], @@ -52,11 +52,11 @@ public function testCountModel(): void public function testCountModelWithScopes(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { completed_tasks: Int @count(model: "Task", scopes: ["completed"]) } - '; + GRAPHQL; factory(Task::class, 3)->create(); $completed = factory(Task::class, 2)->make(); @@ -65,11 +65,11 @@ public function testCountModelWithScopes(): void $task->save(); }); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { completed_tasks } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'completed_tasks' => 2, ], @@ -78,7 +78,7 @@ public function testCountModelWithScopes(): void public function testCountRelationAndEagerLoadsTheCount(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [User!] @all } @@ -86,7 +86,7 @@ public function testCountRelationAndEagerLoadsTheCount(): void type User { tasks_count: Int @count(relation: "tasks") } - '; + GRAPHQL; factory(User::class, 3)->create() ->each(static function (User $user, int $index): void { @@ -98,13 +98,13 @@ public function testCountRelationAndEagerLoadsTheCount(): void }); $this->assertQueryCountMatches(2, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { tasks_count } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -124,7 +124,7 @@ public function testCountRelationAndEagerLoadsTheCount(): void public function testCountRelationThatIsNotSuffixedWithCount(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @first } @@ -132,7 +132,7 @@ public function testCountRelationThatIsNotSuffixedWithCount(): void type User { tasks: Int @count(relation: "tasks") } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -142,13 +142,13 @@ public function testCountRelationThatIsNotSuffixedWithCount(): void $task->save(); }); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'user' => [ 'tasks' => 3, @@ -159,7 +159,7 @@ public function testCountRelationThatIsNotSuffixedWithCount(): void public function testCountRelationWithScopesApplied(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User @first } @@ -167,7 +167,7 @@ public function testCountRelationWithScopesApplied(): void type User { completed_tasks: Int! @count(relation: "tasks", scopes: ["completed"]) } - '; + GRAPHQL; /** @var User $user */ $user = factory(User::class)->create(); @@ -182,13 +182,13 @@ public function testCountRelationWithScopesApplied(): void $completedTask->user()->associate($user); $completedTask->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { completed_tasks } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'user' => [ 'completed_tasks' => 1, @@ -199,7 +199,7 @@ public function testCountRelationWithScopesApplied(): void public function testCountPolymorphicRelation(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { activity: [Activity!] @all } @@ -220,7 +220,7 @@ public function testCountPolymorphicRelation(): void id: ID content: ActivityContent! @morphTo } - '; + GRAPHQL; /** @var User $user */ $user = factory(User::class)->create(); @@ -265,7 +265,7 @@ public function testCountPolymorphicRelation(): void factory(Image::class, 4)->make(), ); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { activity { id @@ -284,7 +284,7 @@ public function testCountPolymorphicRelation(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'activity' => [ [ @@ -320,17 +320,17 @@ public function testResolveCountByModel(): void { factory(User::class)->times(3)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: Int! @count(model: "User") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => 3, ], @@ -348,7 +348,7 @@ public function testResolveCountByRelation(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { taskCount: Int! @count(relation: "tasks") } @@ -356,15 +356,15 @@ public function testResolveCountByRelation(): void type Query { user: User @auth } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { taskCount } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'taskCount' => 4, @@ -391,7 +391,7 @@ public function testResolveRelationItemsAndCount(): void $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany taskCount: Int! @count(relation: "tasks") @@ -404,9 +404,9 @@ public function testResolveRelationItemsAndCount(): void type Query { user: User @auth } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks { @@ -415,7 +415,7 @@ public function testResolveRelationItemsAndCount(): void taskCount } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'tasks' => [ @@ -434,11 +434,11 @@ public function testResolveRelationItemsAndCount(): void public function testCountModelWithColumns(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { tasks: Int @count(model: "Task", columns: ["difficulty"]) } - '; + GRAPHQL; $notNull = factory(Task::class)->make(); $this->assertInstanceOf(Task::class, $notNull); @@ -450,11 +450,11 @@ public function testCountModelWithColumns(): void $notNull->difficulty = 2; $notNull->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'tasks' => 1, ], @@ -463,11 +463,11 @@ public function testCountModelWithColumns(): void public function testCountModelWithColumnsAndDistinct(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { tasks: Int @count(model: "Task", distinct: true, columns: ["difficulty"]) } - '; + GRAPHQL; foreach (factory(Task::class, 2)->make() as $task) { $this->assertInstanceOf(Task::class, $task); $task->difficulty = 1; @@ -479,11 +479,11 @@ public function testCountModelWithColumnsAndDistinct(): void $other->difficulty = 2; $other->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'tasks' => 2, ], diff --git a/tests/Integration/Schema/Directives/CreateDirectiveTest.php b/tests/Integration/Schema/Directives/CreateDirectiveTest.php index a0ca489968..e50936dfc6 100644 --- a/tests/Integration/Schema/Directives/CreateDirectiveTest.php +++ b/tests/Integration/Schema/Directives/CreateDirectiveTest.php @@ -13,7 +13,7 @@ final class CreateDirectiveTest extends DBTestCase { public function testCreateFromFieldArguments(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -22,16 +22,16 @@ public function testCreateFromFieldArguments(): void type Mutation { createCompany(name: String): Company @create } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createCompany(name: "foo") { id name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createCompany' => [ 'id' => '1', @@ -43,7 +43,7 @@ public function testCreateFromFieldArguments(): void public function testCreateFromInputObject(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -56,9 +56,9 @@ public function testCreateFromInputObject(): void input CreateCompanyInput { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createCompany(input: { name: "foo" @@ -67,7 +67,7 @@ public function testCreateFromInputObject(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createCompany' => [ 'id' => '1', @@ -79,7 +79,7 @@ public function testCreateFromInputObject(): void public function testCreatesAnEntryWithDatabaseDefaultsAndReturnsItImmediately(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { createTag(name: String): Tag @create } @@ -88,16 +88,16 @@ public function testCreatesAnEntryWithDatabaseDefaultsAndReturnsItImmediately(): name: String! default_string: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTag(name: "foobar") { name default_string } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTag' => [ 'name' => 'foobar', @@ -117,7 +117,7 @@ public function testDoesNotCreateWithFailingRelationship(): void $config = $this->app->make(ConfigRepository::class); $config->set('app.debug', false); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -146,9 +146,9 @@ public function testDoesNotCreateWithFailingRelationship(): void name: String user: ID } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "foo" @@ -166,7 +166,7 @@ public function testDoesNotCreateWithFailingRelationship(): void } } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'createUser' => null, @@ -188,7 +188,7 @@ public function testCreatesOnPartialFailureWithTransactionsDisabled(): void $config->set('app.debug', false); $config->set('lighthouse.transactional_mutations', false); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -217,9 +217,9 @@ public function testCreatesOnPartialFailureWithTransactionsDisabled(): void name: String user: ID } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "foo" @@ -237,7 +237,7 @@ public function testCreatesOnPartialFailureWithTransactionsDisabled(): void } } } - ') + GRAPHQL) // TODO allow partial success // ->assertJson([ // 'data' => [ @@ -254,7 +254,7 @@ public function testCreatesOnPartialFailureWithTransactionsDisabled(): void public function testDoesNotFailWhenPropertyNameMatchesModelsNativeMethods(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -284,9 +284,9 @@ public function testDoesNotFailWhenPropertyNameMatchesModelsNativeMethods(): voi name: String guard: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "foo" @@ -302,7 +302,7 @@ public function testDoesNotFailWhenPropertyNameMatchesModelsNativeMethods(): voi } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createUser' => [ 'tasks' => [ @@ -317,7 +317,7 @@ public function testDoesNotFailWhenPropertyNameMatchesModelsNativeMethods(): voi public function testNestedArgResolverHasMany(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { createUser(input: CreateUserInput! @spread): User @create } @@ -339,9 +339,9 @@ public function testNestedArgResolverHasMany(): void input CreateTaskInput { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "foo" @@ -355,7 +355,7 @@ public function testNestedArgResolverHasMany(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'createUser' => [ 'name' => 'foo', @@ -371,7 +371,7 @@ public function testNestedArgResolverHasMany(): void public function testNestedArgResolverForOptionalBelongsTo(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { createTask(input: CreateTaskInput! @spread): Task @create } @@ -393,9 +393,9 @@ public function testNestedArgResolverForOptionalBelongsTo(): void input CreateUserInput { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "task" @@ -409,7 +409,7 @@ public function testNestedArgResolverForOptionalBelongsTo(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'createTask' => [ 'name' => 'task', @@ -423,7 +423,7 @@ public function testNestedArgResolverForOptionalBelongsTo(): void public function testCreateTwice(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -451,9 +451,9 @@ public function testCreateTwice(): void input CreateTaskInput { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "foo" @@ -466,7 +466,7 @@ public function testCreateTwice(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createUser' => [ 'name' => 'foo', @@ -474,7 +474,7 @@ public function testCreateTwice(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "bar" @@ -487,7 +487,7 @@ public function testCreateTwice(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createUser' => [ 'name' => 'bar', @@ -498,7 +498,7 @@ public function testCreateTwice(): void public function testCreateTwiceWithCreateDirective(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -522,9 +522,9 @@ public function testCreateTwiceWithCreateDirective(): void input CreateTaskInput { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser(input: { name: "foo" @@ -543,7 +543,7 @@ public function testCreateTwiceWithCreateDirective(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createUser' => [ 'name' => 'foo', @@ -564,7 +564,7 @@ public function testTurnOnMassAssignment(): void { config(['lighthouse.force_fill' => false]); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { name: String! } @@ -572,16 +572,16 @@ public function testTurnOnMassAssignment(): void type Mutation { createCompany(name: String): Company @create } - '; + GRAPHQL; $this->expectException(MassAssignmentException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createCompany(name: "foo") { name } } - '); + GRAPHQL); } } diff --git a/tests/Integration/Schema/Directives/CreateManyDirectiveTest.php b/tests/Integration/Schema/Directives/CreateManyDirectiveTest.php index b211f163b2..246ab13a3d 100644 --- a/tests/Integration/Schema/Directives/CreateManyDirectiveTest.php +++ b/tests/Integration/Schema/Directives/CreateManyDirectiveTest.php @@ -8,7 +8,7 @@ final class CreateManyDirectiveTest extends DBTestCase { public function testCreateFromFieldArguments(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -21,9 +21,9 @@ public function testCreateFromFieldArguments(): void type Mutation { createCompanies(inputs: [CreateCompanyInput!]!): [Company!]! @createMany } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createCompanies(inputs: [ { @@ -37,7 +37,7 @@ public function testCreateFromFieldArguments(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createCompanies' => [ [ diff --git a/tests/Integration/Schema/Directives/DeleteDirectiveTest.php b/tests/Integration/Schema/Directives/DeleteDirectiveTest.php index de9f398106..8b23164f54 100644 --- a/tests/Integration/Schema/Directives/DeleteDirectiveTest.php +++ b/tests/Integration/Schema/Directives/DeleteDirectiveTest.php @@ -17,7 +17,7 @@ public function testDeletesUserAndReturnsIt(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -25,15 +25,15 @@ public function testDeletesUserAndReturnsIt(): void type Mutation { deleteUser(id: ID! @whereKey): User @delete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { deleteUser(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertJson([ 'data' => [ @@ -48,7 +48,7 @@ public function testDeletesUserAndReturnsIt(): void public function testDeleteNotFound(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -56,15 +56,15 @@ public function testDeleteNotFound(): void type Mutation { deleteUser(id: ID! @whereKey): User @delete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { deleteUser(id: "non-existing") { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'deleteUser' => null, ], @@ -76,7 +76,7 @@ public function testDeletesMultipleUsersByIDAndReturnsThem(): void $users = factory(User::class, 2)->create(); $this->assertInstanceOf(EloquentCollection::class, $users); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -84,15 +84,15 @@ public function testDeletesMultipleUsersByIDAndReturnsThem(): void type Mutation { deleteUsers(ids: [ID!]! @whereKey): [User!]! @delete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($ids: [ID!]!) { deleteUsers(ids: $ids) { id } } - ', [ + GRAPHQL, [ 'ids' => $users->pluck('id'), ])->assertJsonCount(2, 'data.deleteUsers'); @@ -111,7 +111,7 @@ public function testDeleteByNonPrimaryKey(): void $bar->name = 'bar'; $bar->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -119,15 +119,15 @@ public function testDeleteByNonPrimaryKey(): void type Mutation { deleteUsers(name: String! @eq): [User!]! @delete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($name: String!) { deleteUsers(name: $name) { id } } - ', [ + GRAPHQL, [ 'name' => $foo->name, ])->assertJson([ 'data' => [ @@ -154,7 +154,7 @@ public function testDeleteWithScopes(): void $unnamed->name = null; $unnamed->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -162,15 +162,15 @@ public function testDeleteWithScopes(): void type Mutation { deleteUser(id: ID! @whereKey): User @delete(scopes: ["named"]) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { deleteUser(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $named->id, ])->assertJson([ 'data' => [ @@ -180,13 +180,13 @@ public function testDeleteWithScopes(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { deleteUser(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $unnamed->id, ])->assertJson([ 'data' => [ @@ -197,7 +197,7 @@ public function testDeleteWithScopes(): void public function testDeletesMultipleNonExisting(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -205,15 +205,15 @@ public function testDeletesMultipleNonExisting(): void type Mutation { deleteUsers(ids: [ID!]! @whereKey): [User!]! @delete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { deleteUsers(ids: ["non-existing"]) { id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'deleteUsers' => [], ], @@ -222,7 +222,7 @@ public function testDeletesMultipleNonExisting(): void public function testDeletesMultipleEmptyInput(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -230,15 +230,15 @@ public function testDeletesMultipleEmptyInput(): void type Mutation { deleteUsers(ids: [ID!]! @whereKey): [User!]! @delete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { deleteUsers(ids: []) { id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'deleteUsers' => [], ], @@ -247,7 +247,7 @@ public function testDeletesMultipleEmptyInput(): void public function testDeleteRequiresAtLeastOneArgument(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -255,20 +255,20 @@ public function testDeleteRequiresAtLeastOneArgument(): void type Mutation { deleteUser(id: ID @whereKey, email: String @eq): User @delete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { deleteUser { id } } - ')->assertGraphQLError(ModifyModelExistenceDirective::wouldModifyAll()); + GRAPHQL)->assertGraphQLError(ModifyModelExistenceDirective::wouldModifyAll()); } public function testDoesNotAcceptArgumentWithoutArgBuilderDirective(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -276,22 +276,22 @@ public function testDoesNotAcceptArgumentWithoutArgBuilderDirective(): void type Mutation { deleteUser(id: ID): User @delete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { deleteUser(id: 1) { id } } - ')->assertGraphQLError(ModifyModelExistenceDirective::wouldModifyAll()); + GRAPHQL)->assertGraphQLError(ModifyModelExistenceDirective::wouldModifyAll()); } public function testRequiresRelationWhenUsingAsArgResolver(): void { $this->expectException(DefinitionException::class); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateUser(deleteTasks: Tasks @delete): User @update } @@ -299,7 +299,7 @@ public function testRequiresRelationWhenUsingAsArgResolver(): void type User { id: ID! } - ' . self::PLACEHOLDER_QUERY); + GRAPHQL . self::PLACEHOLDER_QUERY); } public function testUseNestedArgResolverDelete(): void @@ -314,7 +314,7 @@ public function testUseNestedArgResolverDelete(): void $task->save(); } - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateUser( id: ID @@ -330,9 +330,9 @@ public function testUseNestedArgResolverDelete(): void type Task { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!, $deleteTasks: [ID!]!) { updateUser(id: $id, deleteTasks: $deleteTasks) { id @@ -341,7 +341,7 @@ public function testUseNestedArgResolverDelete(): void } } } - ', [ + GRAPHQL, [ 'id' => $user->id, 'deleteTasks' => [$tasks[1]->id], ])->assertExactJson([ @@ -368,7 +368,7 @@ public function testDeleteHasOneThroughNestedArgResolver(): void $post->task()->associate($task); $post->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateTask( id: ID @@ -384,9 +384,9 @@ public function testDeleteHasOneThroughNestedArgResolver(): void type Post { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { updateTask(id: $id, deletePost: false) { id @@ -395,7 +395,7 @@ public function testDeleteHasOneThroughNestedArgResolver(): void } } } - ', [ + GRAPHQL, [ 'id' => $task->id, ])->assertExactJson([ 'data' => [ @@ -408,7 +408,7 @@ public function testDeleteHasOneThroughNestedArgResolver(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { updateTask(id: $id, deletePost: true) { id @@ -417,7 +417,7 @@ public function testDeleteHasOneThroughNestedArgResolver(): void } } } - ', [ + GRAPHQL, [ 'id' => $task->id, ])->assertExactJson([ 'data' => [ @@ -441,7 +441,7 @@ public function testDeleteBelongsToThroughNestedArgResolver(): void $task->user()->associate($user); $task->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateTask( id: ID! @@ -457,9 +457,9 @@ public function testDeleteBelongsToThroughNestedArgResolver(): void type User { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { updateTask(id: $id, deleteUser: true) { id @@ -468,7 +468,7 @@ public function testDeleteBelongsToThroughNestedArgResolver(): void } } } - ', [ + GRAPHQL, [ 'id' => $task->id, ])->assertExactJson([ 'data' => [ @@ -490,7 +490,7 @@ public function testDeletingReturnsFalseTriggersException(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -498,15 +498,15 @@ public function testDeletingReturnsFalseTriggersException(): void type Mutation { deleteUser(id: ID! @whereKey): User @delete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { deleteUser(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertGraphQLError(ModifyModelExistenceDirective::couldNotModify($user)); } diff --git a/tests/Integration/Schema/Directives/EnumDirectiveTest.php b/tests/Integration/Schema/Directives/EnumDirectiveTest.php index f31963b8c1..1d21089b1c 100644 --- a/tests/Integration/Schema/Directives/EnumDirectiveTest.php +++ b/tests/Integration/Schema/Directives/EnumDirectiveTest.php @@ -14,7 +14,7 @@ public function testDefinesEnumWithInternalValues(): void return 'Not active'; }); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' enum Status { ACTIVE @enum(value: "Active internal") INACTIVE @enum(value: "Not active") @@ -23,14 +23,14 @@ enum Status { type Query { status(status: Status!): Status! @mock } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { status(status: ACTIVE) } - ') + GRAPHQL) ->assertExactJson([ 'data' => [ 'status' => 'INACTIVE', diff --git a/tests/Integration/Schema/Directives/EqDirectiveTest.php b/tests/Integration/Schema/Directives/EqDirectiveTest.php index 9280ca49d0..325aa9bb82 100644 --- a/tests/Integration/Schema/Directives/EqDirectiveTest.php +++ b/tests/Integration/Schema/Directives/EqDirectiveTest.php @@ -12,7 +12,7 @@ public function testAttachEqFilterFromFieldArgument(): void { $users = factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -20,16 +20,16 @@ public function testAttachEqFilterFromFieldArgument(): void type Query { users(id: ID @eq): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID) { users(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $users->first()->getKey(), ]) ->assertJsonCount(1, 'data.users'); @@ -39,7 +39,7 @@ public function testAttachEqFilterFromInputObject(): void { $users = factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -51,10 +51,10 @@ public function testAttachEqFilterFromInputObject(): void input UserInput { id: ID @eq } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID) { users( input: { @@ -64,7 +64,7 @@ public function testAttachEqFilterFromInputObject(): void id } } - ', [ + GRAPHQL, [ 'id' => $users->first()->getKey(), ]) ->assertJsonCount(1, 'data.users'); @@ -74,7 +74,7 @@ public function testAttachEqFilterFromInputObjectWithinList(): void { $users = factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -86,10 +86,10 @@ public function testAttachEqFilterFromInputObjectWithinList(): void input UserInput { id: ID @eq } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID) { users( input: [ @@ -101,7 +101,7 @@ public function testAttachEqFilterFromInputObjectWithinList(): void id } } - ', [ + GRAPHQL, [ 'id' => $users->first()->getKey(), ]) ->assertJsonCount(1, 'data.users'); @@ -111,24 +111,24 @@ public function testAttachEqFilterFromField(): void { $users = factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ " + $this->schema = /** @lang GraphQL */ <<first()->getKey()}) + users: [User!]! @all @eq(key: "id", value: {$users->first()->getKey()}) } - "; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id } } - ') + GRAPHQL) ->assertJsonCount(1, 'data.users'); } @@ -136,7 +136,7 @@ public function testEqOnFieldRequiresValue(): void { $this->expectException(DefinitionException::class); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -144,14 +144,14 @@ public function testEqOnFieldRequiresValue(): void type Query { users: [User!]! @all @eq } - '); + GRAPHQL); } public function testEqOnFieldRequiresKey(): void { $this->expectException(DefinitionException::class); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -159,6 +159,6 @@ public function testEqOnFieldRequiresKey(): void type Query { users: [User!]! @all @eq(value: 3) } - '); + GRAPHQL); } } diff --git a/tests/Integration/Schema/Directives/EventDirectiveTest.php b/tests/Integration/Schema/Directives/EventDirectiveTest.php index 2f3ad2b50e..dfec5d7f6a 100644 --- a/tests/Integration/Schema/Directives/EventDirectiveTest.php +++ b/tests/Integration/Schema/Directives/EventDirectiveTest.php @@ -14,7 +14,7 @@ public function testDispatchesAnEvent(): void CompanyWasCreatedEvent::class, ]); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -22,18 +22,18 @@ public function testDispatchesAnEvent(): void type Mutation { createCompany(name: String): Company @create - @event(dispatch: "Tests\\\\Integration\\\\Schema\\\\Directives\\\\Fixtures\\\\CompanyWasCreatedEvent") + @event(dispatch: "Tests\\Integration\\Schema\\Directives\\Fixtures\\CompanyWasCreatedEvent") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createCompany(name: "foo") { id name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createCompany' => [ 'id' => '1', diff --git a/tests/Integration/Schema/Directives/FindDirectiveTest.php b/tests/Integration/Schema/Directives/FindDirectiveTest.php index f96c7a6d5c..02d678066d 100644 --- a/tests/Integration/Schema/Directives/FindDirectiveTest.php +++ b/tests/Integration/Schema/Directives/FindDirectiveTest.php @@ -14,7 +14,7 @@ public function testReturnsSingleUser(): void $userB = $this->createUserWithName('B'); $this->createUserWithName('C'); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -23,15 +23,15 @@ public function testReturnsSingleUser(): void type Query { user(id: ID @eq): User @find(model: "User") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<id}) { name } } - ")->assertJsonFragment([ + GRAPHQL)->assertJsonFragment([ 'user' => [ 'name' => 'B', ], @@ -43,7 +43,7 @@ public function testDefaultsToFieldTypeIfNoModelIsSupplied(): void $userA = $this->createUserWithName('A'); $this->createUserWithName('B'); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -52,15 +52,15 @@ public function testDefaultsToFieldTypeIfNoModelIsSupplied(): void type Query { user(id: ID @eq): User @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<id}) { name } } - ")->assertJsonFragment([ + GRAPHQL)->assertJsonFragment([ 'name' => 'A', ]); } @@ -71,7 +71,7 @@ public function testCannotFetchIfMultipleModelsMatch(): void $this->createUserWithName('A'); $this->createUserWithName('B'); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -80,15 +80,15 @@ public function testCannotFetchIfMultipleModelsMatch(): void type Query { user(name: String @eq): User @find(model: "User") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(name: "A") { name } } - ')->assertJsonCount(1, 'errors'); + GRAPHQL)->assertJsonCount(1, 'errors'); } public function testUseScopes(): void @@ -99,7 +99,7 @@ public function testUseScopes(): void $this->createUserWithNameAndCompany('A', $companyB); $this->createUserWithNameAndCompany('B', $companyA); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Company { name: String! } @@ -112,16 +112,16 @@ public function testUseScopes(): void type Query { user(name: String @eq, company: String!): User @find(model: "User" scopes: [companyName]) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(name: "A" company: "CompanyA") { id name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'id' => $userA->id, @@ -133,7 +133,7 @@ public function testUseScopes(): void public function testReturnsAnEmptyObjectWhenTheModelIsNotFound(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -142,16 +142,16 @@ public function testReturnsAnEmptyObjectWhenTheModelIsNotFound(): void type Query { user(name: String @eq): User @find(model: "User") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(name: "A") { id name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'user' => null, ], @@ -164,7 +164,7 @@ public function testReturnsCustomAttributes(): void $this->assertInstanceOf(Company::class, $company); $user = $this->createUserWithNameAndCompany('A', $company); - $this->schema = ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -174,9 +174,9 @@ public function testReturnsCustomAttributes(): void type Query { user(id: ID @eq): User @find(model: "User") } - '; + GRAPHQL; - $this->graphQL(" + $this->graphQL(/** @lang GraphQL */ <<id}) { id @@ -184,7 +184,7 @@ public function testReturnsCustomAttributes(): void companyName } } - ")->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'id' => (string) $user->id, diff --git a/tests/Integration/Schema/Directives/FirstDirectiveTest.php b/tests/Integration/Schema/Directives/FirstDirectiveTest.php index 3156d8b623..5a8b4a7787 100644 --- a/tests/Integration/Schema/Directives/FirstDirectiveTest.php +++ b/tests/Integration/Schema/Directives/FirstDirectiveTest.php @@ -9,7 +9,7 @@ final class FirstDirectiveTest extends DBTestCase { public function testReturnsASingleUser(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -18,7 +18,7 @@ public function testReturnsASingleUser(): void type Query { user(id: ID @eq): User @first(model: "User") } - '; + GRAPHQL; $userA = factory(User::class)->create(); $this->assertInstanceOf(User::class, $userA); @@ -29,13 +29,13 @@ public function testReturnsASingleUser(): void $userC = factory(User::class)->create(); $this->assertInstanceOf(User::class, $userC); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $userB->id, ])->assertJson([ 'data' => [ @@ -48,7 +48,7 @@ public function testReturnsASingleUser(): void public function testReturnsASingleUserWhenMultiplesMatch(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -57,7 +57,7 @@ public function testReturnsASingleUserWhenMultiplesMatch(): void type Query { user(name: String @eq): User @first(model: "User") } - '; + GRAPHQL; $userA1 = factory(User::class)->create(); $this->assertInstanceOf(User::class, $userA1); @@ -74,13 +74,13 @@ public function testReturnsASingleUserWhenMultiplesMatch(): void $userB->name = 'B'; $userB->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(name: "A") { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'id' => $userA1->id, diff --git a/tests/Integration/Schema/Directives/HasManyDirectiveTest.php b/tests/Integration/Schema/Directives/HasManyDirectiveTest.php index cc8783fdf7..ae50a98e17 100644 --- a/tests/Integration/Schema/Directives/HasManyDirectiveTest.php +++ b/tests/Integration/Schema/Directives/HasManyDirectiveTest.php @@ -15,7 +15,7 @@ final class HasManyDirectiveTest extends DBTestCase { public function testQueryHasManyRelationship(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany } @@ -28,7 +28,7 @@ public function testQueryHasManyRelationship(): void type Query { user: User @first } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -48,7 +48,7 @@ public function testQueryHasManyRelationship(): void $this->assertSame(4, $tasksWithoutGlobalScope); // Ensure global scopes are respected here - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks { @@ -56,12 +56,12 @@ public function testQueryHasManyRelationship(): void } } } - ')->assertJsonCount(3, 'data.user.tasks'); + GRAPHQL)->assertJsonCount(3, 'data.user.tasks'); } public function testHasManyWithRenamedModel(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { foos: [Foo!]! @hasMany(relation: "tasks") } @@ -73,7 +73,7 @@ public function testHasManyWithRenamedModel(): void type Query { user: User @first } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -81,7 +81,7 @@ public function testHasManyWithRenamedModel(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { foos { @@ -89,12 +89,12 @@ public function testHasManyWithRenamedModel(): void } } } - ')->assertJsonCount(3, 'data.user.foos'); + GRAPHQL)->assertJsonCount(3, 'data.user.foos'); } public function testQueryHasManyWithCondition(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks( id: ID! @eq @@ -108,7 +108,7 @@ public function testQueryHasManyWithCondition(): void type Query { user: User! @first } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -120,7 +120,7 @@ public function testQueryHasManyWithCondition(): void $this->assertInstanceOf(Task::class, $firstTask); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user { tasks(id: $id) { @@ -128,7 +128,7 @@ public function testQueryHasManyWithCondition(): void } } } - ', [ + GRAPHQL, [ 'id' => $firstTask->id, ]) ->assertJsonCount(1, 'data.user.tasks'); @@ -136,7 +136,7 @@ public function testQueryHasManyWithCondition(): void public function testQueryHasManyWithConditionInDifferentAliases(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks( id: ID! @eq @@ -150,7 +150,7 @@ public function testQueryHasManyWithConditionInDifferentAliases(): void type Query { users: [User!]! @all } - '; + GRAPHQL; $user1 = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user1); @@ -171,7 +171,7 @@ public function testQueryHasManyWithConditionInDifferentAliases(): void $this->assertInstanceOf(Task::class, $lastTask); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($firstId: ID!, $lastId: ID!) { users { firstTasks: tasks(id: $firstId) { @@ -182,7 +182,7 @@ public function testQueryHasManyWithConditionInDifferentAliases(): void } } } - ', [ + GRAPHQL, [ 'firstId' => $firstTask->id, 'lastId' => $lastTask->id, ]) @@ -212,7 +212,7 @@ public function testQueryHasManyWithConditionInDifferentAliases(): void public function testQueryPaginatedHasManyWithConditionInDifferentAliases(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks( id: ID! @eq @@ -226,7 +226,7 @@ public function testQueryPaginatedHasManyWithConditionInDifferentAliases(): void type Query { users: [User!]! @all } - '; + GRAPHQL; $user1 = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user1); @@ -247,7 +247,7 @@ public function testQueryPaginatedHasManyWithConditionInDifferentAliases(): void $this->assertInstanceOf(Task::class, $lastTask); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($firstId: ID!, $lastId: ID!) { users { firstTasks: tasks(id: $firstId) { @@ -262,7 +262,7 @@ public function testQueryPaginatedHasManyWithConditionInDifferentAliases(): void } } } - ', [ + GRAPHQL, [ 'firstId' => $firstTask->id, 'lastId' => $lastTask->id, ]) @@ -300,7 +300,7 @@ public function testQueryPaginatedHasManyWithConditionInDifferentAliases(): void public function testQueryPaginatedHasManyFirst0(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! tasks: [Task!]! @hasMany(type: PAGINATOR) @@ -313,7 +313,7 @@ public function testQueryPaginatedHasManyFirst0(): void type Query { users: [User!]! @all } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -323,7 +323,7 @@ public function testQueryPaginatedHasManyFirst0(): void $user->tasks()->saveMany($tasks); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id @@ -337,7 +337,7 @@ public function testQueryPaginatedHasManyFirst0(): void } } } - ') + GRAPHQL) ->assertExactJson([ 'data' => [ 'users' => [ @@ -357,7 +357,7 @@ public function testQueryPaginatedHasManyFirst0(): void public function testQueryPaginatedHasManyWithNonUniqueForeignKey(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { roles: [RoleUser!]! @hasMany(relation: "roles", type: PAGINATOR, defaultCount: 10) } @@ -371,7 +371,7 @@ public function testQueryPaginatedHasManyWithNonUniqueForeignKey(): void type Query { posts: [Post!]! @all } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -394,7 +394,7 @@ public function testQueryPaginatedHasManyWithNonUniqueForeignKey(): void $this->assertCount(3, $user->roles); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query { posts { roles { @@ -406,7 +406,7 @@ public function testQueryPaginatedHasManyWithNonUniqueForeignKey(): void } } } - ') + GRAPHQL) ->assertExactJson([ 'data' => [ 'posts' => [ @@ -459,7 +459,7 @@ public function testQueryPaginatedHasManyWithNonUniqueForeignKey(): void public function testCallsScopeWithResolverArgs(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks(foo: Int): [Task!]! @hasMany(scopes: ["foo"]) } @@ -472,7 +472,7 @@ public function testCallsScopeWithResolverArgs(): void type Query { user: User @first } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -480,7 +480,7 @@ public function testCallsScopeWithResolverArgs(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(foo: 2) { @@ -488,7 +488,7 @@ public function testCallsScopeWithResolverArgs(): void } } } - ')->assertJsonCount(2, 'data.user.tasks'); + GRAPHQL)->assertJsonCount(2, 'data.user.tasks'); } /** @dataProvider batchloadRelations */ @@ -507,7 +507,7 @@ public function testQueryHasManyPaginator(bool $batchloadRelations): void factory(Post::class, 3)->make(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: PAGINATOR) posts: [Post!]! @hasMany(type: SIMPLE) @@ -524,10 +524,10 @@ public function testQueryHasManyPaginator(bool $batchloadRelations): void type Query { user: User @first } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 2) { @@ -550,7 +550,7 @@ public function testQueryHasManyPaginator(bool $batchloadRelations): void } } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'user' => [ @@ -581,7 +581,7 @@ public function testDoesNotRequireModelClassForPaginatedHasMany(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [NotTheModelNameTask!]! @hasMany(type: PAGINATOR) } @@ -593,9 +593,9 @@ public function testDoesNotRequireModelClassForPaginatedHasMany(): void type Query { user: User @first } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 2) { @@ -610,7 +610,7 @@ public function testDoesNotRequireModelClassForPaginatedHasMany(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'tasks' => [ @@ -635,7 +635,7 @@ public function testPaginatorTypeIsLimitedByMaxCountFromDirective(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: PAGINATOR, maxCount: 3) } @@ -647,10 +647,10 @@ public function testPaginatorTypeIsLimitedByMaxCountFromDirective(): void type Query { user: User @first } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 5) { @@ -660,7 +660,7 @@ public function testPaginatorTypeIsLimitedByMaxCountFromDirective(): void } } } - ') + GRAPHQL) ->assertGraphQLErrorMessage(PaginationArgs::requestedTooManyItems(3, 5)); } @@ -674,7 +674,7 @@ public function testPaginatorTypeIsUnlimitedByMaxCountFromDirective(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: PAGINATOR, maxCount: null) } @@ -686,10 +686,10 @@ public function testPaginatorTypeIsUnlimitedByMaxCountFromDirective(): void type Query { user: User @first } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 5) { @@ -699,7 +699,7 @@ public function testPaginatorTypeIsUnlimitedByMaxCountFromDirective(): void } } } - ') + GRAPHQL) ->assertGraphQLErrorFree(); } @@ -711,7 +711,7 @@ public function testRejectsPaginationWithNegativeCount(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID tasks: [Task!] @hasMany(type: PAGINATOR) @@ -724,10 +724,10 @@ public function testRejectsPaginationWithNegativeCount(): void type Query { user: User @first } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { id @@ -738,7 +738,7 @@ public function testRejectsPaginationWithNegativeCount(): void } } } - ') + GRAPHQL) ->assertGraphQLErrorMessage(PaginationArgs::requestedLessThanZeroItems(-1)); } @@ -752,7 +752,7 @@ public function testRelayTypeIsLimitedByMaxCountFromDirective(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: CONNECTION, maxCount: 3) } @@ -764,9 +764,9 @@ public function testRelayTypeIsLimitedByMaxCountFromDirective(): void type Query { user: User @first } - '; + GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 5) { @@ -778,7 +778,7 @@ public function testRelayTypeIsLimitedByMaxCountFromDirective(): void } } } - '); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(3, 5), @@ -796,7 +796,7 @@ public function testPaginatorTypeIsLimitedToMaxCountFromConfig(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: PAGINATOR) } @@ -808,9 +808,9 @@ public function testPaginatorTypeIsLimitedToMaxCountFromConfig(): void type Query { user: User @first } - '; + GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 3) { @@ -820,7 +820,7 @@ public function testPaginatorTypeIsLimitedToMaxCountFromConfig(): void } } } - '); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(2, 3), @@ -838,7 +838,7 @@ public function testRelayTypeIsLimitedToMaxCountFromConfig(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: CONNECTION) } @@ -850,9 +850,9 @@ public function testRelayTypeIsLimitedToMaxCountFromConfig(): void type Query { user: User @first } - '; + GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 3) { @@ -864,7 +864,7 @@ public function testRelayTypeIsLimitedToMaxCountFromConfig(): void } } } - '); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(2, 3), @@ -880,7 +880,7 @@ public function testQueryHasManyPaginatorWithADefaultCount(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: PAGINATOR, defaultCount: 2) } @@ -892,9 +892,9 @@ public function testQueryHasManyPaginatorWithADefaultCount(): void type Query { user: User @first } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks { @@ -909,7 +909,7 @@ public function testQueryHasManyPaginatorWithADefaultCount(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'tasks' => [ @@ -932,7 +932,7 @@ public function testQueryHasManyRelayConnection(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: CONNECTION) } @@ -944,9 +944,9 @@ public function testQueryHasManyRelayConnection(): void type Query { user: User @first } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 2) { @@ -961,7 +961,7 @@ public function testQueryHasManyRelayConnection(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'tasks' => [ @@ -982,7 +982,7 @@ public function testQueryHasManyRelayConnectionWithADefaultCount(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: CONNECTION, defaultCount: 2) } @@ -994,9 +994,9 @@ public function testQueryHasManyRelayConnectionWithADefaultCount(): void type Query { user: User @first } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks { @@ -1011,7 +1011,7 @@ public function testQueryHasManyRelayConnectionWithADefaultCount(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'tasks' => [ @@ -1032,7 +1032,7 @@ public function testQueryHasManyNestedRelationships(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: CONNECTION) } @@ -1045,9 +1045,9 @@ public function testQueryHasManyNestedRelationships(): void type Query { user: User @first } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 2) { @@ -1071,7 +1071,7 @@ public function testQueryHasManyNestedRelationships(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'tasks' => [ @@ -1100,7 +1100,7 @@ public function testQueryHasManySelfReferencingRelationships(): void $post3->parent()->associate($post2); $post3->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: Int! parent: Post @belongsTo @@ -1109,9 +1109,9 @@ public function testQueryHasManySelfReferencingRelationships(): void type Query { posts: [Post!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts { id @@ -1123,7 +1123,7 @@ public function testQueryHasManySelfReferencingRelationships(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'posts' => [ [ @@ -1154,7 +1154,7 @@ public function testQueryHasManySelfReferencingRelationships(): void public function testQueryHasManyPaginatorBeforeQuery(): void { // BeforeQuery - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: Int! tasks: [Task!]! @hasMany(type: PAGINATOR) @@ -1168,7 +1168,7 @@ public function testQueryHasManyPaginatorBeforeQuery(): void user(id: ID! @eq): User @find tasks: [Task!]! @paginate } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -1176,7 +1176,7 @@ public function testQueryHasManyPaginatorBeforeQuery(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(first: 2) { data { @@ -1184,13 +1184,13 @@ public function testQueryHasManyPaginatorBeforeQuery(): void } } } - ')->assertJsonCount(2, 'data.tasks.data'); + GRAPHQL)->assertJsonCount(2, 'data.tasks.data'); } public function testQueryHasManyPaginatorAfterQuery(): void { // AfterQuery - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @eq): User @find tasks: [Task!]! @paginate @@ -1204,7 +1204,7 @@ public function testQueryHasManyPaginatorAfterQuery(): void type Task { id: Int! } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -1212,7 +1212,7 @@ public function testQueryHasManyPaginatorAfterQuery(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(first: 2) { data{ @@ -1220,13 +1220,13 @@ public function testQueryHasManyPaginatorAfterQuery(): void } } } - ')->assertJsonCount(2, 'data.tasks.data'); + GRAPHQL)->assertJsonCount(2, 'data.tasks.data'); } public function testQueryHasManyNoTypePaginator(): void { // AfterQuery - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(id: ID! @eq): User @find tasks: [Task!]! @paginate @@ -1240,7 +1240,7 @@ public function testQueryHasManyNoTypePaginator(): void type Task { id: Int! } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -1248,7 +1248,7 @@ public function testQueryHasManyNoTypePaginator(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(first: 2) { data{ @@ -1256,12 +1256,12 @@ public function testQueryHasManyNoTypePaginator(): void } } } - ')->assertJsonCount(2, 'data.tasks.data'); + GRAPHQL)->assertJsonCount(2, 'data.tasks.data'); } public function testHasManyWithModelAndPaginatedRelation(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany(type: PAGINATOR) @can(ability: "adminOnly") } @@ -1273,7 +1273,7 @@ public function testHasManyWithModelAndPaginatedRelation(): void type Query { user: User @first } - '; + GRAPHQL; $user = factory(User::class)->make(); $this->assertInstanceOf(User::class, $user); @@ -1285,7 +1285,7 @@ public function testHasManyWithModelAndPaginatedRelation(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 3) { @@ -1295,12 +1295,12 @@ public function testHasManyWithModelAndPaginatedRelation(): void } } } - ')->assertJsonCount(3, 'data.user.tasks.data'); + GRAPHQL)->assertJsonCount(3, 'data.user.tasks.data'); } public function testHasManyWithRenamedModelAndPaginatedRelation(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { foos: [Foo!]! @hasMany(type: PAGINATOR, relation: "tasks") @can(ability: "adminOnly") } @@ -1312,7 +1312,7 @@ public function testHasManyWithRenamedModelAndPaginatedRelation(): void type Query { user: User @first } - '; + GRAPHQL; $user = factory(User::class)->make(); $this->assertInstanceOf(User::class, $user); @@ -1324,7 +1324,7 @@ public function testHasManyWithRenamedModelAndPaginatedRelation(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { foos(first: 3) { @@ -1334,12 +1334,12 @@ public function testHasManyWithRenamedModelAndPaginatedRelation(): void } } } - ')->assertJsonCount(3, 'data.user.foos.data'); + GRAPHQL)->assertJsonCount(3, 'data.user.foos.data'); } public function testHasManyWithRenamedModelAndConnection(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { foos: [Foo!]! @hasMany(type: CONNECTION, relation: "tasks") @can(ability: "adminOnly") } @@ -1351,7 +1351,7 @@ public function testHasManyWithRenamedModelAndConnection(): void type Query { user: User @first } - '; + GRAPHQL; $user = factory(User::class)->make(); $this->assertInstanceOf(User::class, $user); @@ -1363,7 +1363,7 @@ public function testHasManyWithRenamedModelAndConnection(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { foos(first: 3) { @@ -1375,7 +1375,7 @@ public function testHasManyWithRenamedModelAndConnection(): void } } } - ')->assertJsonCount(3, 'data.user.foos.edges'); + GRAPHQL)->assertJsonCount(3, 'data.user.foos.edges'); } /** @return iterable */ diff --git a/tests/Integration/Schema/Directives/HasManyThroughDirectiveTest.php b/tests/Integration/Schema/Directives/HasManyThroughDirectiveTest.php index 60c24257f0..0d18bbb75a 100644 --- a/tests/Integration/Schema/Directives/HasManyThroughDirectiveTest.php +++ b/tests/Integration/Schema/Directives/HasManyThroughDirectiveTest.php @@ -12,7 +12,7 @@ final class HasManyThroughDirectiveTest extends DBTestCase { public function testQueryHasManyThroughRelationship(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! } @@ -24,7 +24,7 @@ public function testQueryHasManyThroughRelationship(): void type Query { task: Task! @first } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -46,7 +46,7 @@ public function testQueryHasManyThroughRelationship(): void $comment->save(); } - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { task { postComments { @@ -54,6 +54,6 @@ public function testQueryHasManyThroughRelationship(): void } } } - ')->assertJsonCount(2, 'data.task.postComments'); + GRAPHQL)->assertJsonCount(2, 'data.task.postComments'); } } diff --git a/tests/Integration/Schema/Directives/HasOneDirectiveTest.php b/tests/Integration/Schema/Directives/HasOneDirectiveTest.php index aeb7ed9ed8..41465bdc48 100644 --- a/tests/Integration/Schema/Directives/HasOneDirectiveTest.php +++ b/tests/Integration/Schema/Directives/HasOneDirectiveTest.php @@ -17,7 +17,7 @@ public function testQueryHasOneRelationship(): void $post = factory(Post::class)->create(); $this->assertInstanceOf(Post::class, $post); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: Int } @@ -29,9 +29,9 @@ public function testQueryHasOneRelationship(): void type Query { tasks: [Task!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks { post { @@ -39,7 +39,7 @@ public function testQueryHasOneRelationship(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'tasks' => [ [ diff --git a/tests/Integration/Schema/Directives/HasOneThroughDirectiveTest.php b/tests/Integration/Schema/Directives/HasOneThroughDirectiveTest.php index fe6849816f..9388ed171e 100644 --- a/tests/Integration/Schema/Directives/HasOneThroughDirectiveTest.php +++ b/tests/Integration/Schema/Directives/HasOneThroughDirectiveTest.php @@ -10,7 +10,7 @@ final class HasOneThroughDirectiveTest extends DBTestCase { public function testQueryHasOneThroughRelationship(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { tasks: [Task!]! @all } @@ -24,7 +24,7 @@ public function testQueryHasOneThroughRelationship(): void id: ID! status: String } - '; + GRAPHQL; $post = factory(Post::class)->create(); $this->assertInstanceOf(Post::class, $post); @@ -34,7 +34,7 @@ public function testQueryHasOneThroughRelationship(): void $postStatus->post()->associate($post); $postStatus->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks { id @@ -44,7 +44,7 @@ public function testQueryHasOneThroughRelationship(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'tasks' => [ [ diff --git a/tests/Integration/Schema/Directives/InDirectiveTest.php b/tests/Integration/Schema/Directives/InDirectiveTest.php index c32a91b996..ead5dfe666 100644 --- a/tests/Integration/Schema/Directives/InDirectiveTest.php +++ b/tests/Integration/Schema/Directives/InDirectiveTest.php @@ -14,7 +14,7 @@ public function testInIDs(): void factory(User::class)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -22,18 +22,18 @@ public function testInIDs(): void type Query { users(ids: [ID!] @in(key: "id")): [User!]! @all } - '; + GRAPHQL; $user1ID = (string) $user1->id; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($ids: [ID!]) { users(ids: $ids) { id } } - ', [ + GRAPHQL, [ 'ids' => [$user1ID], ]) ->assertJson([ @@ -51,7 +51,7 @@ public function testExplicitNull(): void { $users = factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -59,16 +59,16 @@ public function testExplicitNull(): void type Query { users(ids: [ID!] @in(key: "id")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($ids: [ID!]) { users(ids: $ids) { id } } - ', [ + GRAPHQL, [ 'ids' => null, ]) ->assertJsonCount($users->count(), 'data.users'); @@ -78,7 +78,7 @@ public function testExplicitNullInArray(): void { factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -86,16 +86,16 @@ public function testExplicitNullInArray(): void type Query { users(ids: [ID] @in(key: "id")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($ids: [ID]) { users(ids: $ids) { id } } - ', [ + GRAPHQL, [ 'ids' => [null], ]) ->assertJsonCount(0, 'data.users'); @@ -105,7 +105,7 @@ public function testEmptyArray(): void { factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -113,16 +113,16 @@ public function testEmptyArray(): void type Query { users(ids: [ID!] @in(key: "id")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($ids: [ID!]) { users(ids: $ids) { id } } - ', [ + GRAPHQL, [ 'ids' => [], ]) ->assertJsonCount(0, 'data.users'); diff --git a/tests/Integration/Schema/Directives/InjectDirectiveDBTest.php b/tests/Integration/Schema/Directives/InjectDirectiveDBTest.php index 0c79df9e5a..f7ef8e4ec2 100644 --- a/tests/Integration/Schema/Directives/InjectDirectiveDBTest.php +++ b/tests/Integration/Schema/Directives/InjectDirectiveDBTest.php @@ -15,7 +15,7 @@ public function testInjectDataFromContextIntoArgs(): void $this->mockResolver() ->with(null, ['user_id' => 1]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: Int! } @@ -25,14 +25,14 @@ public function testInjectDataFromContextIntoArgs(): void @inject(context: "user.id", name: "user_id") @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { me { id } } - '); + GRAPHQL); } } diff --git a/tests/Integration/Schema/Directives/InjectDirectiveTest.php b/tests/Integration/Schema/Directives/InjectDirectiveTest.php index f4a778803b..70e2ca50f4 100644 --- a/tests/Integration/Schema/Directives/InjectDirectiveTest.php +++ b/tests/Integration/Schema/Directives/InjectDirectiveTest.php @@ -12,7 +12,7 @@ public function testCreateFromInputObjectWithDeepInjection(): void $user = factory(User::class)->create(); $this->be($user); - $this->schema .= ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -30,9 +30,9 @@ public function testCreateFromInputObjectWithDeepInjection(): void input CreateTaskInput { name: String } - '; + GRAPHQL; - $this->graphQL(' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createTask(input: { name: "foo" @@ -44,7 +44,7 @@ public function testCreateFromInputObjectWithDeepInjection(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'createTask' => [ 'id' => '1', diff --git a/tests/Integration/Schema/Directives/LazyLoadDirectiveTest.php b/tests/Integration/Schema/Directives/LazyLoadDirectiveTest.php index ab772034f7..895dbc1444 100644 --- a/tests/Integration/Schema/Directives/LazyLoadDirectiveTest.php +++ b/tests/Integration/Schema/Directives/LazyLoadDirectiveTest.php @@ -13,22 +13,22 @@ public function testLazyLoadRequiresRelationArgument(): void { $this->expectException(DefinitionException::class); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID @lazyLoad } - '); + GRAPHQL); } public function testLazyLoadRelationArgumentMustNotBeEmptyList(): void { $this->expectException(DefinitionException::class); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID @lazyLoad(relations: []) } - '); + GRAPHQL); } public function testLazyLoadRelationsOnConnections(): void @@ -39,7 +39,7 @@ public function testLazyLoadRelationsOnConnections(): void $tasks = factory(Task::class, 3)->make(); $user->tasks()->saveMany($tasks); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @lazyLoad(relations: ["user"]) @@ -54,9 +54,9 @@ public function testLazyLoadRelationsOnConnections(): void type Query { user: User @first } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasks(first: 1) { @@ -68,7 +68,7 @@ public function testLazyLoadRelationsOnConnections(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'tasks' => [ @@ -89,7 +89,7 @@ public function testLazyLoadRelationsOnPaginate(): void { factory(User::class)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany tasksLoaded: Boolean! @method @@ -102,9 +102,9 @@ public function testLazyLoadRelationsOnPaginate(): void type Query { users: [User!]! @paginate @lazyLoad(relations: ["tasks"]) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 1) { data { @@ -112,7 +112,7 @@ public function testLazyLoadRelationsOnPaginate(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'data' => [ diff --git a/tests/Integration/Schema/Directives/LikeDirectiveTest.php b/tests/Integration/Schema/Directives/LikeDirectiveTest.php index d12eed57bc..6a1ff7936b 100644 --- a/tests/Integration/Schema/Directives/LikeDirectiveTest.php +++ b/tests/Integration/Schema/Directives/LikeDirectiveTest.php @@ -13,7 +13,7 @@ public function testLikeClientsCanPassWildcards(): void $this->createUserWithName('Alex'); $this->createUserWithName('Aaron'); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! } @@ -23,15 +23,15 @@ public function testLikeClientsCanPassWildcards(): void name: String! @like ): [User!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(name: "Al%") { name } } - ')->assertJsonFragment([ + GRAPHQL)->assertJsonFragment([ 'users' => [ [ 'name' => 'Alan', @@ -49,7 +49,7 @@ public function testLikeWithWildcardsInTemplate(): void $this->createUserWithName('Alex'); $this->createUserWithName('Aaron'); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! } @@ -59,15 +59,15 @@ public function testLikeWithWildcardsInTemplate(): void name: String! @like(template: "%{}%") ): [User!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(name: "l") { name } } - ')->assertJsonFragment([ + GRAPHQL)->assertJsonFragment([ 'users' => [ [ 'name' => 'Alan', @@ -86,7 +86,7 @@ public function testLikeClientWildcardsAreEscapedFromTemplate(): void $this->createUserWithName('Aar%'); $this->createUserWithName('Aar%toomuch'); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -97,15 +97,15 @@ public function testLikeClientWildcardsAreEscapedFromTemplate(): void name: String! @like(template: "%{}__") ): [User!] @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(name: "ar%") { name } } - ')->assertJsonFragment([ + GRAPHQL)->assertJsonFragment([ 'users' => [ [ 'name' => 'Aar%on', @@ -119,7 +119,7 @@ public function testLikeOnField(): void $this->createUserWithName('Alex'); $this->createUserWithName('Aaron'); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -130,15 +130,15 @@ public function testLikeOnField(): void @all @like(key: "name", value: "%ex") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { name } } - ')->assertJsonFragment([ + GRAPHQL)->assertJsonFragment([ 'users' => [ [ 'name' => 'Alex', diff --git a/tests/Integration/Schema/Directives/LimitDirectiveTest.php b/tests/Integration/Schema/Directives/LimitDirectiveTest.php index 9cf29502ae..26d5236744 100644 --- a/tests/Integration/Schema/Directives/LimitDirectiveTest.php +++ b/tests/Integration/Schema/Directives/LimitDirectiveTest.php @@ -26,7 +26,7 @@ public function testLimitsResults(): void { factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -34,7 +34,7 @@ public function testLimitsResults(): void type Query { users(limit: Int @limit): [User!]! @all } - '; + GRAPHQL; $queries = []; DB::listen(static function (QueryExecuted $query) use (&$queries): void { @@ -42,13 +42,13 @@ public function testLimitsResults(): void }); $limit = 1; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($limit: Int) { users(limit: $limit) { id } } - ', [ + GRAPHQL, [ 'limit' => $limit, ])->assertJsonCount($limit, 'data.users'); $this->assertSame([ @@ -60,7 +60,7 @@ public function testLimitsQueryBuilder(): void { factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -68,7 +68,7 @@ public function testLimitsQueryBuilder(): void type Query { users(limit: Int @limit(builder: true)): [User!]! @all } - '; + GRAPHQL; $queries = []; DB::listen(static function (QueryExecuted $query) use (&$queries): void { @@ -76,13 +76,13 @@ public function testLimitsQueryBuilder(): void }); $limit = 1; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($limit: Int) { users(limit: $limit) { id } } - ', [ + GRAPHQL, [ 'limit' => $limit, ])->assertJsonCount($limit, 'data.users'); $this->assertSame([ @@ -102,7 +102,7 @@ public function testLimitOnInputField(): void // @phpstan-ignore-next-line https://github.com/phpstan/phpstan-phpunit/issues/52 factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -114,10 +114,10 @@ public function testLimitOnInputField(): void type Query { users(filter: UserFilter): [User!]! @all } - '; + GRAPHQL; $limit = 1; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($limit: Int) { users(filter: { limit: $limit @@ -125,7 +125,7 @@ public function testLimitOnInputField(): void id } } - ', [ + GRAPHQL, [ 'limit' => $limit, ])->assertJsonCount($limit, 'data.users'); } @@ -141,7 +141,7 @@ public function testLimitsRelations(): void ); } - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! tasks(limit: Int @limit): [Task!]! @hasMany @@ -154,11 +154,11 @@ public function testLimitsRelations(): void type Query { users: [User!]! @all } - '; + GRAPHQL; $limit = 1; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($limit: Int) { users { id @@ -167,7 +167,7 @@ public function testLimitsRelations(): void } } } - ', [ + GRAPHQL, [ 'limit' => $limit, ]) ->assertJsonCount($limit, 'data.users.0.tasks') @@ -186,7 +186,7 @@ public function testLimitsWithCache(): void ); } - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! @cacheKey tasks(limit: Int @limit): [Task!]! @hasMany @cache @@ -199,10 +199,10 @@ public function testLimitsWithCache(): void type Query { user: [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { id @@ -211,7 +211,7 @@ public function testLimitsWithCache(): void } } } - '); + GRAPHQL); $cache = $this->app->make(CacheRepository::class); @@ -233,7 +233,7 @@ public function testLimitsWithCache(): void $this->assertSame(3, $task->id); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { id @@ -242,7 +242,7 @@ public function testLimitsWithCache(): void } } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'user' => [ diff --git a/tests/Integration/Schema/Directives/MorphManyDirectiveTest.php b/tests/Integration/Schema/Directives/MorphManyDirectiveTest.php index 339d4e71ed..9dc03b7001 100644 --- a/tests/Integration/Schema/Directives/MorphManyDirectiveTest.php +++ b/tests/Integration/Schema/Directives/MorphManyDirectiveTest.php @@ -76,7 +76,7 @@ function (): Image { public function testQueryMorphManyRelationship(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! title: String! @@ -102,9 +102,9 @@ public function testQueryMorphManyRelationship(): void id: ID! @eq ): Task @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<post->id}) { id @@ -122,7 +122,7 @@ public function testQueryMorphManyRelationship(): void } } } - ")->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'post' => [ 'id' => $this->post->id, @@ -149,7 +149,7 @@ public function testQueryMorphManyRelationship(): void public function testQueryMorphManyPaginator(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! title: String! @@ -166,9 +166,9 @@ public function testQueryMorphManyPaginator(): void id: ID! @eq ): Post @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<post->id}) { id @@ -185,7 +185,7 @@ public function testQueryMorphManyPaginator(): void } } } - ")->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'post' => [ 'id' => $this->post->id, @@ -207,7 +207,7 @@ public function testPaginatorTypeIsLimitedByMaxCountFromDirective(): void { config(['lighthouse.pagination.max_count' => 1]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! title: String! @@ -223,9 +223,9 @@ public function testPaginatorTypeIsLimitedByMaxCountFromDirective(): void id: ID! @eq ): Post @find } - '; + GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ " + $result = $this->graphQL(/** @lang GraphQL */ <<post->id}) { id @@ -237,7 +237,7 @@ public function testPaginatorTypeIsLimitedByMaxCountFromDirective(): void } } } - "); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(3, 10), @@ -249,7 +249,7 @@ public function testPaginatorTypeIsLimitedToMaxCountFromConfig(): void { config(['lighthouse.pagination.max_count' => 2]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! title: String! @@ -265,9 +265,9 @@ public function testPaginatorTypeIsLimitedToMaxCountFromConfig(): void id: ID! @eq ): Post @find } - '; + GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ " + $result = $this->graphQL(/** @lang GraphQL */ <<post->id}) { id @@ -279,7 +279,7 @@ public function testPaginatorTypeIsLimitedToMaxCountFromConfig(): void } } } - "); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(2, 10), @@ -291,7 +291,7 @@ public function testPaginatorTypeIsUnlimitedByMaxCountFromDirective(): void { config(['lighthouse.pagination.max_count' => 1]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! title: String! @@ -307,10 +307,10 @@ public function testPaginatorTypeIsUnlimitedByMaxCountFromDirective(): void id: ID! @eq ): Post @find } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ " + ->graphQL(/** @lang GraphQL */ <<post->id}) { id @@ -322,13 +322,13 @@ public function testPaginatorTypeIsUnlimitedByMaxCountFromDirective(): void } } } - ") + GRAPHQL) ->assertGraphQLErrorFree(); } public function testHandlesPaginationWithCountZero(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! title: String! @@ -344,10 +344,10 @@ public function testHandlesPaginationWithCountZero(): void id: ID! @eq ): Post @find } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { post(id: $id) { images(first: 0) { @@ -366,7 +366,7 @@ public function testHandlesPaginationWithCountZero(): void } } } - ', [ + GRAPHQL, [ 'id' => $this->post->id, ]) ->assertExactJson([ @@ -391,7 +391,7 @@ public function testHandlesPaginationWithCountZero(): void public function testQueryMorphManyPaginatorWithADefaultCount(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -407,9 +407,9 @@ public function testQueryMorphManyPaginatorWithADefaultCount(): void id: ID! @eq ): Task @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<task->id}) { id @@ -426,7 +426,7 @@ public function testQueryMorphManyPaginatorWithADefaultCount(): void } } } - ")->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'task' => [ 'id' => $this->task->id, @@ -445,7 +445,7 @@ public function testQueryMorphManyPaginatorWithADefaultCount(): void public function testQueryMorphManyRelayConnection(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -461,9 +461,9 @@ public function testQueryMorphManyRelayConnection(): void id: ID! @eq ): Task @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<task->id}) { id @@ -480,7 +480,7 @@ public function testQueryMorphManyRelayConnection(): void } } } - ")->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'task' => [ 'id' => $this->task->id, @@ -499,7 +499,7 @@ public function testRelayTypeIsLimitedByMaxCountFromDirective(): void { config(['lighthouse.pagination.max_count' => 1]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -515,9 +515,9 @@ public function testRelayTypeIsLimitedByMaxCountFromDirective(): void id: ID! @eq ): Task @find } - '; + GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ " + $result = $this->graphQL(/** @lang GraphQL */ <<task->id}) { id @@ -531,7 +531,7 @@ public function testRelayTypeIsLimitedByMaxCountFromDirective(): void } } } - "); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(3, 10), @@ -543,7 +543,7 @@ public function testRelayTypeIsLimitedToMaxCountFromConfig(): void { config(['lighthouse.pagination.max_count' => 2]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -559,9 +559,9 @@ public function testRelayTypeIsLimitedToMaxCountFromConfig(): void id: ID! @eq ): Task @find } - '; + GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ " + $result = $this->graphQL(/** @lang GraphQL */ <<task->id}) { id @@ -575,7 +575,7 @@ public function testRelayTypeIsLimitedToMaxCountFromConfig(): void } } } - "); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(2, 10), @@ -585,7 +585,7 @@ public function testRelayTypeIsLimitedToMaxCountFromConfig(): void public function testQueryMorphManyRelayConnectionWithADefaultCount(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -601,9 +601,9 @@ public function testQueryMorphManyRelayConnectionWithADefaultCount(): void id: ID! @eq ): Task @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<task->id}) { id @@ -620,7 +620,7 @@ public function testQueryMorphManyRelayConnectionWithADefaultCount(): void } } } - ")->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'task' => [ 'id' => $this->task->id, diff --git a/tests/Integration/Schema/Directives/MorphOneDirectiveTest.php b/tests/Integration/Schema/Directives/MorphOneDirectiveTest.php index cf8a5b326b..9a7532afdc 100644 --- a/tests/Integration/Schema/Directives/MorphOneDirectiveTest.php +++ b/tests/Integration/Schema/Directives/MorphOneDirectiveTest.php @@ -50,7 +50,7 @@ protected function setUp(): void public function testResolveMorphOneRelationship(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Image { id: ID! } @@ -66,9 +66,9 @@ public function testResolveMorphOneRelationship(): void id: ID! @eq ): Task @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { task(id: $id) { id @@ -78,7 +78,7 @@ public function testResolveMorphOneRelationship(): void } } } - ', [ + GRAPHQL, [ 'id' => $this->task->id, ])->assertJson([ 'data' => [ @@ -95,7 +95,7 @@ public function testResolveMorphOneRelationship(): void public function testResolveMorphOneWithCustomName(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Image { id: ID! } @@ -111,9 +111,9 @@ public function testResolveMorphOneWithCustomName(): void id: ID! @eq ): Task @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { task(id: $id) { id @@ -123,7 +123,7 @@ public function testResolveMorphOneWithCustomName(): void } } } - ', [ + GRAPHQL, [ 'id' => $this->task->id, ])->assertJson([ 'data' => [ diff --git a/tests/Integration/Schema/Directives/MorphOneFromUnionTest.php b/tests/Integration/Schema/Directives/MorphOneFromUnionTest.php index 09ac0c383c..5c13cd9980 100644 --- a/tests/Integration/Schema/Directives/MorphOneFromUnionTest.php +++ b/tests/Integration/Schema/Directives/MorphOneFromUnionTest.php @@ -46,7 +46,7 @@ public function testResolveMorphOneRelationshipOnInterface(): void $employee->colors()->save($employeeColor); $contractor->colors()->save($contractorColor); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' interface Person { id: ID! user: User! @morphOne @@ -81,9 +81,9 @@ interface Person { type Query { colors: [Color!]! @all } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { colors { id @@ -101,7 +101,7 @@ interface Person { } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'colors' => [ [ diff --git a/tests/Integration/Schema/Directives/MorphToDirectiveTest.php b/tests/Integration/Schema/Directives/MorphToDirectiveTest.php index d71feb7ca4..6f53d74b2f 100644 --- a/tests/Integration/Schema/Directives/MorphToDirectiveTest.php +++ b/tests/Integration/Schema/Directives/MorphToDirectiveTest.php @@ -25,7 +25,7 @@ public function testResolveMorphToRelationship(): void $image->imageable()->associate($task); $image->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Image { id: ID! imageable: Task! @morphTo @@ -41,9 +41,9 @@ public function testResolveMorphToRelationship(): void id: ID! @eq ): Image @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { image(id: $id) { id @@ -53,7 +53,7 @@ public function testResolveMorphToRelationship(): void } } } - ', [ + GRAPHQL, [ 'id' => $image->id, ])->assertJson([ 'data' => [ @@ -83,7 +83,7 @@ public function testResolveMorphToWithCustomName(): void $image->imageable()->associate($task); $image->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Image { id: ID! customImageable: Task! @morphTo(relation: "imageable") @@ -99,9 +99,9 @@ public function testResolveMorphToWithCustomName(): void id: ID! @eq ): Image @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { image(id: $id) { id @@ -111,7 +111,7 @@ public function testResolveMorphToWithCustomName(): void } } } - ', [ + GRAPHQL, [ 'id' => $image->id, ])->assertJson([ 'data' => [ @@ -151,7 +151,7 @@ public function testResolveMorphToUsingInterfaces(): void $postImage->imageable()->associate($post); $postImage->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' interface Imageable { id: ID! } @@ -176,9 +176,9 @@ interface Imageable { id: ID! @eq ): Image @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($taskImage: ID!, $postImage: ID!) { taskImage: image(id: $taskImage) { id @@ -207,7 +207,7 @@ interface Imageable { } } } - ', [ + GRAPHQL, [ 'taskImage' => $image->id, 'postImage' => $postImage->id, ])->assertJson([ @@ -257,7 +257,7 @@ public function testResolveMorphToUsingInterfacesWithShortcutForeignKeySelection $postImage->imageable()->associate($post); $postImage->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' interface Imageable { id: ID! } @@ -282,10 +282,10 @@ interface Imageable { id: ID! @eq ): Image @find } - '; + GRAPHQL; $this->assertQueryCountMatches(2, function () use ($image, $postImage, $task, $post): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($taskImage: ID!, $postImage: ID!) { taskImage: image(id: $taskImage) { id @@ -310,7 +310,7 @@ interface Imageable { } } } - ', [ + GRAPHQL, [ 'taskImage' => $image->id, 'postImage' => $postImage->id, ])->assertJson([ @@ -359,7 +359,7 @@ public function testResolveMorphToUsingInterfacesWithShortcutForeignKeySelection $postImage->imageable()->associate($post); $postImage->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' interface Imageable { id: ID! } @@ -384,10 +384,10 @@ interface Imageable { id: ID! @eq ): Image @find } - '; + GRAPHQL; $this->assertQueryCountMatches(2, function () use ($image, $postImage, $task, $post): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($taskImage: ID!, $postImage: ID!) { taskImage: image(id: $taskImage) { id @@ -414,7 +414,7 @@ interface Imageable { } } } - ', [ + GRAPHQL, [ 'taskImage' => $image->id, 'postImage' => $postImage->id, ])->assertJson([ @@ -463,7 +463,7 @@ public function testResolveMorphToUsingUnions(): void $postImage->imageable()->associate($post); $postImage->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' union Imageable = Task | Post type Task { @@ -486,9 +486,9 @@ public function testResolveMorphToUsingUnions(): void id: ID! @eq ): Image @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($taskImage: ID!, $postImage: ID!) { taskImage: image(id: $taskImage) { id @@ -519,7 +519,7 @@ public function testResolveMorphToUsingUnions(): void } } } - ', [ + GRAPHQL, [ 'taskImage' => $image->id, 'postImage' => $postImage->id, ])->assertJson([ @@ -571,7 +571,7 @@ public function testShortcutsForeignKeySelectionUsingUnionSelectID(): void $postImage->imageable()->associate($post); $postImage->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' union Imageable = Task | Post type Task { @@ -594,10 +594,10 @@ public function testShortcutsForeignKeySelectionUsingUnionSelectID(): void id: ID! @eq ): Image @find } - '; + GRAPHQL; $this->assertQueryCountMatches(2, function () use ($image, $postImage, $task, $post): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($taskImage: ID!, $postImage: ID!) { taskImage: image(id: $taskImage) { id @@ -622,7 +622,7 @@ public function testShortcutsForeignKeySelectionUsingUnionSelectID(): void } } } - ', [ + GRAPHQL, [ 'taskImage' => $image->id, 'postImage' => $postImage->id, ])->assertJson([ @@ -671,7 +671,7 @@ public function testShortcutsForeignKeySelectionUsingUnionSelectIDAndTypename(): $postImage->imageable()->associate($post); $postImage->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' union Imageable = Task | Post type Task { @@ -694,10 +694,10 @@ public function testShortcutsForeignKeySelectionUsingUnionSelectIDAndTypename(): id: ID! @eq ): Image @find } - '; + GRAPHQL; $this->assertQueryCountMatches(2, function () use ($image, $postImage, $task, $post): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($taskImage: ID!, $postImage: ID!) { taskImage: image(id: $taskImage) { id @@ -724,7 +724,7 @@ public function testShortcutsForeignKeySelectionUsingUnionSelectIDAndTypename(): } } } - ', [ + GRAPHQL, [ 'taskImage' => $image->id, 'postImage' => $postImage->id, ])->assertJson([ @@ -775,7 +775,7 @@ public function testDoesNotShortcutForeignKeySelectionUsingUnionSelectIDAndTypen $postImage->imageable()->associate($post); $postImage->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' union Imageable = Task | Post type Task { @@ -798,10 +798,10 @@ public function testDoesNotShortcutForeignKeySelectionUsingUnionSelectIDAndTypen id: ID! @eq ): Image @find } - '; + GRAPHQL; $this->assertQueryCountMatches(4, function () use ($image, $postImage, $task, $post): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($taskImage: ID!, $postImage: ID!) { taskImage: image(id: $taskImage) { id @@ -830,7 +830,7 @@ public function testDoesNotShortcutForeignKeySelectionUsingUnionSelectIDAndTypen } } } - ', [ + GRAPHQL, [ 'taskImage' => $image->id, 'postImage' => $postImage->id, ])->assertJson([ @@ -871,7 +871,7 @@ public function testShortcutsForeignKeySelectID(): void $image->imageable()->associate($task); $image->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Image { id: ID! imageable: Task! @morphTo @@ -887,10 +887,10 @@ public function testShortcutsForeignKeySelectID(): void id: ID! @eq ): Image @find } - '; + GRAPHQL; $this->assertQueryCountMatches(1, function () use ($image, $task): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { image(id: $id) { id @@ -899,7 +899,7 @@ public function testShortcutsForeignKeySelectID(): void } } } - ', + GRAPHQL, [ 'id' => $image->id, ], @@ -933,7 +933,7 @@ public function testShortcutsForeignKeySelectTypename(): void $image->imageable()->associate($task); $image->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Image { id: ID! imageable: Task! @morphTo @@ -949,10 +949,10 @@ public function testShortcutsForeignKeySelectTypename(): void id: ID! @eq ): Image @find } - '; + GRAPHQL; $this->assertQueryCountMatches(1, function () use ($image): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { image(id: $id) { id @@ -961,7 +961,7 @@ public function testShortcutsForeignKeySelectTypename(): void } } } - ', + GRAPHQL, [ 'id' => $image->id, ], @@ -995,7 +995,7 @@ public function testShortcutsForeignKeySelectIDAndTypename(): void $image->imageable()->associate($task); $image->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Image { id: ID! imageable: Task! @morphTo @@ -1011,10 +1011,10 @@ public function testShortcutsForeignKeySelectIDAndTypename(): void id: ID! @eq ): Image @find } - '; + GRAPHQL; $this->assertQueryCountMatches(1, function () use ($image, $task): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { image(id: $id) { id @@ -1024,7 +1024,7 @@ public function testShortcutsForeignKeySelectIDAndTypename(): void } } } - ', + GRAPHQL, [ 'id' => $image->id, ], @@ -1059,7 +1059,7 @@ public function testDoesNotShortcutForeignKeyIfQueryHasFieldSelection(): void $image->imageable()->associate($task); $image->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Image { id: ID! imageable: Task! @morphTo @@ -1075,10 +1075,10 @@ public function testDoesNotShortcutForeignKeyIfQueryHasFieldSelection(): void id: ID! @eq ): Image @find } - '; + GRAPHQL; $this->assertQueryCountMatches(2, function () use ($image, $task): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { image(id: $id) { id @@ -1088,7 +1088,7 @@ public function testDoesNotShortcutForeignKeyIfQueryHasFieldSelection(): void } } } - ', + GRAPHQL, [ 'id' => $image->id, ], diff --git a/tests/Integration/Schema/Directives/MorphToManyDirectiveTest.php b/tests/Integration/Schema/Directives/MorphToManyDirectiveTest.php index c8315e1452..9ed384dd1e 100644 --- a/tests/Integration/Schema/Directives/MorphToManyDirectiveTest.php +++ b/tests/Integration/Schema/Directives/MorphToManyDirectiveTest.php @@ -34,7 +34,7 @@ protected function setUp(): void public function testResolveMorphToManyRelationship(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { post(id: $id) { id @@ -67,7 +67,7 @@ public function testResolveMorphToManyRelationship(): void } } } - ', [ + GRAPHQL, [ 'id' => $this->post->id, ])->assertJson([ 'data' => [ @@ -86,7 +86,7 @@ public function testResolveMorphToManyRelationship(): void public function testResolveMorphToManyRelationshipWithRelayConnection(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { post(id: $id) { id @@ -120,7 +120,7 @@ public function testResolveMorphToManyRelationshipWithRelayConnection(): void } } } - ', [ + GRAPHQL, [ 'id' => $this->post->id, ])->assertJson([ 'data' => [ @@ -143,7 +143,7 @@ public function testResolveMorphToManyRelationshipWithRelayConnection(): void public function testResolveMorphToManyWithCustomName(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { post(id: $id) { id @@ -176,7 +176,7 @@ public function testResolveMorphToManyWithCustomName(): void } } } - ', [ + GRAPHQL, [ 'id' => $this->post->id, ])->assertJson([ 'data' => [ @@ -264,7 +264,7 @@ interface Tag @interface(resolveType: "{$this->qualifyTestResolver('resolveType' } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($userId: ID!) { user (id: $userId) { id @@ -298,7 +298,7 @@ interface Tag @interface(resolveType: "{$this->qualifyTestResolver('resolveType' } } } - ', [ + GRAPHQL, [ 'userId' => $user->id, ])->assertJson([ 'data' => [ diff --git a/tests/Integration/Schema/Directives/NamespacedDirectiveTest.php b/tests/Integration/Schema/Directives/NamespacedDirectiveTest.php index 904beddb34..b865b3ed15 100644 --- a/tests/Integration/Schema/Directives/NamespacedDirectiveTest.php +++ b/tests/Integration/Schema/Directives/NamespacedDirectiveTest.php @@ -8,7 +8,7 @@ final class NamespacedDirectiveTest extends DBTestCase { public function testCRUDModelDirectives(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: UserQueries! @namespaced } @@ -32,10 +32,10 @@ public function testCRUDModelDirectives(): void id: ID! name: String! } - '; + GRAPHQL; $name = 'foo'; - $createUserResponse = $this->graphQL(/** @lang GraphQL */ ' + $createUserResponse = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($name: String!) { user { create(name: $name) { @@ -44,7 +44,7 @@ public function testCRUDModelDirectives(): void } } } - ', [ + GRAPHQL, [ 'name' => $name, ]); $createUserResponse->assertJson([ @@ -58,7 +58,7 @@ public function testCRUDModelDirectives(): void ]); $userID = $createUserResponse->json('data.user.create.id'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { user { find(id: $id) { @@ -69,7 +69,7 @@ public function testCRUDModelDirectives(): void } } } - ', [ + GRAPHQL, [ 'id' => $userID, ])->assertExactJson([ 'data' => [ @@ -87,7 +87,7 @@ public function testCRUDModelDirectives(): void ]); $newName = 'bar'; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!, $name: String) { user { update(id: $id, name: $name) { @@ -96,7 +96,7 @@ public function testCRUDModelDirectives(): void } } } - ', [ + GRAPHQL, [ 'id' => $userID, 'name' => $newName, ])->assertExactJson([ @@ -110,7 +110,7 @@ public function testCRUDModelDirectives(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation ($id: ID!) { user { delete(id: $id) { @@ -119,7 +119,7 @@ public function testCRUDModelDirectives(): void } } } - ', [ + GRAPHQL, [ 'id' => $userID, ])->assertExactJson([ 'data' => [ diff --git a/tests/Integration/Schema/Directives/NestDirectiveTest.php b/tests/Integration/Schema/Directives/NestDirectiveTest.php index 7d60d42993..34e6313258 100644 --- a/tests/Integration/Schema/Directives/NestDirectiveTest.php +++ b/tests/Integration/Schema/Directives/NestDirectiveTest.php @@ -8,7 +8,7 @@ final class NestDirectiveTest extends DBTestCase { public function testNestDelegates(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { createUser( name: String @@ -32,9 +32,9 @@ public function testNestDelegates(): void name: String tasks: [Task!]! @hasMany } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createUser( name: "foo" @@ -50,7 +50,7 @@ public function testNestDelegates(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'createUser' => [ 'name' => 'foo', diff --git a/tests/Integration/Schema/Directives/NotInDirectiveTest.php b/tests/Integration/Schema/Directives/NotInDirectiveTest.php index 6aee874301..f394ec8910 100644 --- a/tests/Integration/Schema/Directives/NotInDirectiveTest.php +++ b/tests/Integration/Schema/Directives/NotInDirectiveTest.php @@ -15,7 +15,7 @@ public function testNotInIDs(): void $user2 = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user2); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -23,19 +23,19 @@ public function testNotInIDs(): void type Query { users(notIDs: [ID!] @notIn(key: "id")): [User!]! @all } - '; + GRAPHQL; $user1ID = (string) $user1->id; $user2ID = (string) $user2->id; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($notIDs: [ID!]) { users(notIDs: $notIDs) { id } } - ', [ + GRAPHQL, [ 'notIDs' => [$user1ID], ]) ->assertJson([ @@ -53,7 +53,7 @@ public function testExplicitNull(): void { $users = factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -61,16 +61,16 @@ public function testExplicitNull(): void type Query { users(notIDs: [ID!] @notIn(key: "id")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($notIDs: [ID!]) { users(notIDs: $notIDs) { id } } - ', [ + GRAPHQL, [ 'notIDs' => null, ]) ->assertJsonCount($users->count(), 'data.users'); @@ -80,7 +80,7 @@ public function testExplicitNullInArray(): void { factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -88,16 +88,16 @@ public function testExplicitNullInArray(): void type Query { users(notIDs: [ID] @notIn(key: "id")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($notIDs: [ID]) { users(notIDs: $notIDs) { id } } - ', [ + GRAPHQL, [ 'notIDs' => [null], ]) ->assertJsonCount(0, 'data.users'); @@ -107,7 +107,7 @@ public function testEmptyArray(): void { $users = factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -115,16 +115,16 @@ public function testEmptyArray(): void type Query { users(notIDs: [ID!] @notIn(key: "id")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($notIDs: [ID!]) { users(notIDs: $notIDs) { id } } - ', [ + GRAPHQL, [ 'notIDs' => [], ]) ->assertJsonCount($users->count(), 'data.users'); diff --git a/tests/Integration/Schema/Directives/ScopeDirectiveTest.php b/tests/Integration/Schema/Directives/ScopeDirectiveTest.php index 95744bad50..17adde0592 100644 --- a/tests/Integration/Schema/Directives/ScopeDirectiveTest.php +++ b/tests/Integration/Schema/Directives/ScopeDirectiveTest.php @@ -22,7 +22,7 @@ public function testExplicitName(): void $taskWithTag->tags()->attach($tag); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { tasks(tags: [String!] @scope(name: "whereTags")): [Task!]! @all } @@ -30,23 +30,23 @@ public function testExplicitName(): void type Task { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks { id } } - ')->assertJsonCount(3, 'data.tasks'); + GRAPHQL)->assertJsonCount(3, 'data.tasks'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($tags: [String!]!) { tasks(tags: $tags) { id } } - ', [ + GRAPHQL, [ 'tags' => [$tag->name], ])->assertExactJson([ 'data' => [ @@ -71,7 +71,7 @@ public function testDefaultsScopeToEqualArgumentName(): void $taskWithTag->tags()->save($tag); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { tasks(whereTags: [String!] @scope): [Task!]! @all } @@ -79,15 +79,15 @@ public function testDefaultsScopeToEqualArgumentName(): void type Task { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($whereTags: [String!]!) { tasks(whereTags: $whereTags) { id } } - ', [ + GRAPHQL, [ 'whereTags' => [$tag->name], ])->assertExactJson([ 'data' => [ @@ -112,7 +112,7 @@ public function testWorksWithCustomQueryBuilders(): void $unnamed->name = null; $unnamed->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users(named: Boolean @scope): [User!]! @all } @@ -120,15 +120,15 @@ public function testWorksWithCustomQueryBuilders(): void type User { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($named: Boolean) { users(named: $named) { id } } - ', [ + GRAPHQL, [ 'named' => true, ])->assertExactJson([ 'data' => [ @@ -140,13 +140,13 @@ public function testWorksWithCustomQueryBuilders(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query { users { id } } - ', [ + GRAPHQL, [ 'named' => false, ])->assertSimilarJson([ 'data' => [ @@ -164,7 +164,7 @@ public function testWorksWithCustomQueryBuilders(): void public function testThrowExceptionOnInvalidScope(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { tasks( name: String @scope(name: "nonExistantScope") @@ -174,15 +174,15 @@ public function testThrowExceptionOnInvalidScope(): void type Task { id: ID } - '; + GRAPHQL; $this->expectException(DefinitionException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(name: "Lighthouse rocks") { id } } - '); + GRAPHQL); } } diff --git a/tests/Integration/Schema/Directives/ThrottleDirectiveTest.php b/tests/Integration/Schema/Directives/ThrottleDirectiveTest.php index 6c24209714..4b93a266a0 100644 --- a/tests/Integration/Schema/Directives/ThrottleDirectiveTest.php +++ b/tests/Integration/Schema/Directives/ThrottleDirectiveTest.php @@ -16,27 +16,27 @@ final class ThrottleDirectiveTest extends TestCase { public function testWrongLimiterName(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @throttle(name: "test") } - '; + GRAPHQL; $this->expectException(DefinitionException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } public function testNamedLimiterReturnsRequest(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @throttle(name: "test") } - '; + GRAPHQL; $rateLimiter = $this->app->make(RateLimiter::class); $rateLimiter->for( @@ -45,26 +45,26 @@ public function testNamedLimiterReturnsRequest(): void ); $this->expectException(DefinitionException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } public function testNamedLimiter(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @throttle(name: "test") } - '; + GRAPHQL; - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' { foo } - '; + GRAPHQL; $rateLimiter = $this->app->make(RateLimiter::class); $rateLimiter->for( @@ -85,17 +85,17 @@ public function testNamedLimiter(): void public function testLimitClears(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @throttle(name: "test") } - '; + GRAPHQL; - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' { foo } - '; + GRAPHQL; $rateLimiter = $this->app->make(RateLimiter::class); $rateLimiter->for( @@ -128,17 +128,17 @@ public function testLimitClears(): void public function testInlineLimiter(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @throttle(maxAttempts: 1) } - '; + GRAPHQL; - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' { foo } - '; + GRAPHQL; $faker = Factory::create()->unique(); $ip = $faker->ipv4; diff --git a/tests/Integration/Schema/Directives/TrimDirectiveTest.php b/tests/Integration/Schema/Directives/TrimDirectiveTest.php index 61493aef7b..76a92ae2a8 100644 --- a/tests/Integration/Schema/Directives/TrimDirectiveTest.php +++ b/tests/Integration/Schema/Directives/TrimDirectiveTest.php @@ -8,19 +8,19 @@ final class TrimDirectiveTest extends TestCase { public function testTrimsStringArgument(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: String! @trim): String! @mock } - '; + GRAPHQL; $this->mockResolver(static fn ($_, array $args): string => $args['bar']); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: " foo ") } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => 'foo', ], @@ -29,7 +29,7 @@ public function testTrimsStringArgument(): void public function testTrimsInputArgument(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' input FooInput { bar: String! } @@ -37,17 +37,17 @@ public function testTrimsInputArgument(): void type Query { foo(input: FooInput! @trim @spread): String! @mock } - '; + GRAPHQL; $this->mockResolver(static fn ($_, array $args): string => $args['bar']); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(input: { bar: " foo " }) } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => 'foo', ], @@ -58,7 +58,7 @@ public function testTrimsAllFieldInputs(): void { $this->mockResolver(static fn ($_, array $args): array => $args); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Foo { foo: String! bar: [String!]! @@ -74,9 +74,9 @@ public function testTrimsAllFieldInputs(): void type Query { foo(input: FooInput! @spread): Foo! @trim @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(input: { foo: " foo " @@ -88,7 +88,7 @@ public function testTrimsAllFieldInputs(): void baz } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => [ 'foo' => 'foo', diff --git a/tests/Integration/Schema/Directives/UpdateDirectiveTest.php b/tests/Integration/Schema/Directives/UpdateDirectiveTest.php index c1334e52af..6ef61bf91e 100644 --- a/tests/Integration/Schema/Directives/UpdateDirectiveTest.php +++ b/tests/Integration/Schema/Directives/UpdateDirectiveTest.php @@ -19,7 +19,7 @@ public function testUpdateFromFieldArguments(): void $company->name = 'foo'; $company->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -31,9 +31,9 @@ public function testUpdateFromFieldArguments(): void name: String ): Company @update } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompany( id: 1 @@ -43,7 +43,7 @@ public function testUpdateFromFieldArguments(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateCompany' => [ 'id' => '1', @@ -62,7 +62,7 @@ public function testUpdateFromInputObject(): void $company->name = 'foo'; $company->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -78,9 +78,9 @@ public function testUpdateFromInputObject(): void id: ID! name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompany(input: { id: 1 @@ -90,7 +90,7 @@ public function testUpdateFromInputObject(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateCompany' => [ 'id' => '1', @@ -104,7 +104,7 @@ public function testUpdateFromInputObject(): void public function testThrowsWhenMissingPrimaryKey(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! } @@ -112,15 +112,15 @@ public function testThrowsWhenMissingPrimaryKey(): void type Mutation { updateCompany: Company @update } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompany { id } } - ')->assertGraphQLErrorMessage(UpdateModel::MISSING_PRIMARY_KEY_FOR_UPDATE); + GRAPHQL)->assertGraphQLErrorMessage(UpdateModel::MISSING_PRIMARY_KEY_FOR_UPDATE); } public function testUpdateWithCustomPrimaryKey(): void @@ -130,7 +130,7 @@ public function testUpdateWithCustomPrimaryKey(): void $category->name = 'foo'; $category->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Category { category_id: ID! name: String! @@ -142,9 +142,9 @@ public function testUpdateWithCustomPrimaryKey(): void name: String ): Category @update } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCategory( category_id: 1 @@ -154,7 +154,7 @@ public function testUpdateWithCustomPrimaryKey(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateCategory' => [ 'category_id' => '1', @@ -173,7 +173,7 @@ public function testUpdateWithCustomPrimaryKeyAsId(): void $category->name = 'foo'; $category->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Category { id: ID! @rename(attribute: "category_id") name: String! @@ -185,9 +185,9 @@ public function testUpdateWithCustomPrimaryKeyAsId(): void name: String ): Category @update } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCategory( id: 1 @@ -197,7 +197,7 @@ public function testUpdateWithCustomPrimaryKeyAsId(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateCategory' => [ 'id' => '1', @@ -216,7 +216,7 @@ public function testDoesNotUpdateWithFailingRelationship(): void $user->name = 'Original'; $user->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String! @@ -245,10 +245,10 @@ public function testDoesNotUpdateWithFailingRelationship(): void input CreateTaskInput { thisFieldDoesNotExist: String } - '; + GRAPHQL; $this->expectException(QueryException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: 1 @@ -267,7 +267,7 @@ public function testDoesNotUpdateWithFailingRelationship(): void } } } - '); + GRAPHQL); $this->assertSame('Original', User::firstOrFail()->name); } @@ -282,7 +282,7 @@ public function testNestedArgResolver(): void $task->id = 3; $task->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateUser(input: UpdateUserInput! @spread): User @update } @@ -307,9 +307,9 @@ public function testNestedArgResolver(): void id: Int name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: 1 @@ -326,7 +326,7 @@ public function testNestedArgResolver(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'updateUser' => [ 'name' => 'foo', @@ -356,7 +356,7 @@ public function testNestedUpdateOnInputList(): void $taskB->id = 4; $taskB->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateUser(input: UpdateUserInput! @spread): User @update } @@ -381,9 +381,9 @@ public function testNestedUpdateOnInputList(): void id: Int name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: 1 @@ -406,7 +406,7 @@ public function testNestedUpdateOnInputList(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateUser' => [ 'name' => 'foo', diff --git a/tests/Integration/Schema/Directives/UpdateManyDirectiveTest.php b/tests/Integration/Schema/Directives/UpdateManyDirectiveTest.php index 8d6811c719..2b284cede9 100644 --- a/tests/Integration/Schema/Directives/UpdateManyDirectiveTest.php +++ b/tests/Integration/Schema/Directives/UpdateManyDirectiveTest.php @@ -22,7 +22,7 @@ public function testUpdateFromFieldArguments(): void $company2->name = 'unchanged'; $company2->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -36,9 +36,9 @@ public function testUpdateFromFieldArguments(): void type Mutation { updateCompanies(inputs: [UpdateCompanyInput!]!): [Company!]! @updateMany } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompanies(inputs: [ { @@ -54,7 +54,7 @@ public function testUpdateFromFieldArguments(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateCompanies' => [ [ @@ -72,7 +72,7 @@ public function testUpdateFromFieldArguments(): void public function testEmptyInputs(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -86,16 +86,16 @@ public function testEmptyInputs(): void type Mutation { updateCompanies(inputs: [UpdateCompanyInput!]!): [Company!]! @updateMany } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompanies(inputs: []) { id name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateCompanies' => [], ], @@ -111,7 +111,7 @@ public function testRollsBackAllChangesOnPartialFailure(): void $company1->name = $name; $company1->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -125,11 +125,11 @@ public function testRollsBackAllChangesOnPartialFailure(): void type Mutation { updateCompanies(inputs: [UpdateCompanyInput]!): [Company!]! @updateMany } - '; + GRAPHQL; $exception = null; try { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompanies(inputs: [ { @@ -145,7 +145,7 @@ public function testRollsBackAllChangesOnPartialFailure(): void name } } - '); + GRAPHQL); } catch (ModelNotFoundException $modelNotFoundException) { $exception = $modelNotFoundException; } @@ -163,7 +163,7 @@ public function testSameIDMultipleTimes(): void $company1->name = 'foo1'; $company1->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -177,9 +177,9 @@ public function testSameIDMultipleTimes(): void type Mutation { updateCompanies(inputs: [UpdateCompanyInput]!): [Company!]! @updateMany } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompanies(inputs: [ { @@ -195,7 +195,7 @@ public function testSameIDMultipleTimes(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateCompanies' => [ [ @@ -213,7 +213,7 @@ public function testSameIDMultipleTimes(): void public function testMissingArgument(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -227,24 +227,24 @@ public function testMissingArgument(): void type Mutation { updateCompanies(inputs: [UpdateCompanyInput!]): [Company!]! @updateMany } - '; + GRAPHQL; $this->expectExceptionObject(new DefinitionException( ManyModelMutationDirective::NOT_EXACTLY_ONE_ARGUMENT, )); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompanies { id name } } - '); + GRAPHQL); } public function testMultipleArguments(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -253,24 +253,24 @@ public function testMultipleArguments(): void type Mutation { updateCompanies(foo: String, bar: String): [Company!]! @updateMany } - '; + GRAPHQL; $this->expectExceptionObject(new DefinitionException( ManyModelMutationDirective::NOT_EXACTLY_ONE_ARGUMENT, )); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompanies(foo: "asf", bar: null) { id name } } - '); + GRAPHQL); } public function testNotList(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -284,12 +284,12 @@ public function testNotList(): void type Mutation { updateCompanies(inputs: UpdateCompanyInput!): [Company!]! @updateMany } - '; + GRAPHQL; $this->expectExceptionObject(new DefinitionException( ManyModelMutationDirective::ARGUMENT_NOT_LIST, )); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompanies(inputs: { id: 1 @@ -299,12 +299,12 @@ public function testNotList(): void name } } - '); + GRAPHQL); } public function testNotInputObjects(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Company { id: ID! name: String! @@ -313,18 +313,18 @@ public function testNotInputObjects(): void type Mutation { updateCompanies(inputs: [String!]!): [Company!]! @updateMany } - '; + GRAPHQL; $this->expectExceptionObject(new DefinitionException( ManyModelMutationDirective::LIST_ITEM_NOT_INPUT_OBJECT, )); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateCompanies(inputs: ["foo"]) { id name } } - '); + GRAPHQL); } } diff --git a/tests/Integration/Schema/Directives/UpsertDirectiveTest.php b/tests/Integration/Schema/Directives/UpsertDirectiveTest.php index fa8460a6e8..a46693ed90 100644 --- a/tests/Integration/Schema/Directives/UpsertDirectiveTest.php +++ b/tests/Integration/Schema/Directives/UpsertDirectiveTest.php @@ -21,7 +21,7 @@ public function testNestedArgResolver(): void $task->name = 'old'; $task->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateUser(input: UpdateUserInput! @spread): User @update } @@ -46,9 +46,9 @@ public function testNestedArgResolver(): void id: Int name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: 1 @@ -71,7 +71,7 @@ public function testNestedArgResolver(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateUser' => [ 'name' => 'foo', @@ -94,7 +94,7 @@ public function testNestedInsertOnInputList(): void { factory(User::class)->create(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateUser(input: UpdateUserInput! @spread): User @update } @@ -119,9 +119,9 @@ public function testNestedInsertOnInputList(): void id: Int name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: 1 @@ -140,7 +140,8 @@ public function testNestedInsertOnInputList(): void name } } - }')->assertJson([ + } + GRAPHQL)->assertJson([ 'data' => [ 'updateUser' => [ 'name' => 'foo', @@ -180,7 +181,7 @@ interface IUser } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertUser(input: { name: "foo" @@ -191,7 +192,7 @@ interface IUser } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertUser' => [ 'id' => 1, diff --git a/tests/Integration/Schema/Directives/UpsertManyDirectiveTest.php b/tests/Integration/Schema/Directives/UpsertManyDirectiveTest.php index 39b9009675..0aa8380d3b 100644 --- a/tests/Integration/Schema/Directives/UpsertManyDirectiveTest.php +++ b/tests/Integration/Schema/Directives/UpsertManyDirectiveTest.php @@ -21,7 +21,7 @@ public function testNestedArgResolver(): void $task->name = 'old'; $task->save(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateUser(input: UpdateUserInput! @spread): User @update } @@ -46,9 +46,9 @@ public function testNestedArgResolver(): void id: Int name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: 1 @@ -71,7 +71,7 @@ public function testNestedArgResolver(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'updateUser' => [ 'name' => 'foo', @@ -94,7 +94,7 @@ public function testNestedInsertOnInputList(): void { factory(User::class)->create(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Mutation { updateUser(input: UpdateUserInput! @spread): User @update } @@ -119,9 +119,9 @@ public function testNestedInsertOnInputList(): void id: Int name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateUser(input: { id: 1 @@ -140,7 +140,8 @@ public function testNestedInsertOnInputList(): void name } } - }')->assertJson([ + } + GRAPHQL)->assertJson([ 'data' => [ 'updateUser' => [ 'name' => 'foo', @@ -180,7 +181,7 @@ interface IUser } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { upsertUsers(inputs: [ { @@ -196,7 +197,7 @@ interface IUser } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'upsertUsers' => [ [ diff --git a/tests/Integration/Schema/Directives/WhereBetweenDirectiveTest.php b/tests/Integration/Schema/Directives/WhereBetweenDirectiveTest.php index a98abad19a..23f2aa08ed 100644 --- a/tests/Integration/Schema/Directives/WhereBetweenDirectiveTest.php +++ b/tests/Integration/Schema/Directives/WhereBetweenDirectiveTest.php @@ -25,8 +25,8 @@ public function testBetween(): void $user3->created_at = Carbon::createStrict(2024); $user3->save(); - $this->schema = /** @lang GraphQL */ ' - scalar DateTime @scalar(class: "Nuwave\\\Lighthouse\\\Schema\\\Types\\\Scalars\\\DateTime") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime") type User { id: ID! @@ -40,16 +40,16 @@ public function testBetween(): void from: DateTime! to: DateTime! } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(createdBetween: { from: "2022-06-06 00:00:00", to: "2023-06-06 00:00:00" }) { id } } - ') + GRAPHQL) ->assertExactJson([ 'data' => [ 'users' => [ @@ -65,8 +65,8 @@ public function testExplicitNull(): void { $users = factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' - scalar DateTime @scalar(class: "Nuwave\\\Lighthouse\\\Schema\\\Types\\\Scalars\\\DateTime") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime") type User { id: ID! @@ -80,16 +80,16 @@ public function testExplicitNull(): void from: DateTime! to: DateTime! } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(createdBetween: null) { id } } - ') + GRAPHQL) ->assertGraphQLErrorFree() ->assertJsonCount($users->count(), 'data.users'); } diff --git a/tests/Integration/Schema/Directives/WhereDirectiveTest.php b/tests/Integration/Schema/Directives/WhereDirectiveTest.php index b6d966feb7..7987e37847 100644 --- a/tests/Integration/Schema/Directives/WhereDirectiveTest.php +++ b/tests/Integration/Schema/Directives/WhereDirectiveTest.php @@ -19,7 +19,7 @@ public function testAttachWhereFilterFromField(): void $bar->name = 'bar'; $bar->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -27,16 +27,16 @@ public function testAttachWhereFilterFromField(): void type Query { usersBeginningWithF: [User!]! @all @where(key: "name", operator: "like", value: "f%") } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { usersBeginningWithF { id } } - ') + GRAPHQL) ->assertJsonCount(1, 'data.usersBeginningWithF'); } @@ -50,8 +50,8 @@ public function testIgnoreNull(): void $userWithEmail = factory(User::class)->create(); $this->assertInstanceOf(User::class, $userWithEmail); - $this->schema = /** @lang GraphQL */ ' - scalar DateTime @scalar(class: "Nuwave\\\Lighthouse\\\Schema\\\Types\\\Scalars\\\DateTime") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime") type User { id: ID! @@ -62,10 +62,10 @@ public function testIgnoreNull(): void usersIgnoreNull(email: String @where(ignoreNull: true)): [User!]! @all usersExplicitNull(email: String @where): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { usersIgnoreNull(email: null) { id @@ -75,7 +75,7 @@ public function testIgnoreNull(): void id } } - ') + GRAPHQL) ->assertGraphQLErrorFree() ->assertJsonCount(2, 'data.usersIgnoreNull') ->assertJsonPath('data.usersIgnoreNull', [ diff --git a/tests/Integration/Schema/Directives/WhereJsonContainsDirectiveDBTest.php b/tests/Integration/Schema/Directives/WhereJsonContainsDirectiveDBTest.php index aa7bec308a..bd19f00a9d 100644 --- a/tests/Integration/Schema/Directives/WhereJsonContainsDirectiveDBTest.php +++ b/tests/Integration/Schema/Directives/WhereJsonContainsDirectiveDBTest.php @@ -7,7 +7,7 @@ final class WhereJsonContainsDirectiveDBTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users(foo: String! @whereJsonContains(key: "name->nested")): [User!]! @all } @@ -15,7 +15,7 @@ final class WhereJsonContainsDirectiveDBTest extends DBTestCase type User { name: String } - '; + GRAPHQL; public function testApplyWhereJsonContainsFilter(): void { @@ -34,13 +34,13 @@ public function testApplyWhereJsonContainsFilter(): void ]); $userWithBaz->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(foo: "bar") { name } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ diff --git a/tests/Integration/Schema/Directives/WhereNotBetweenDirectiveTest.php b/tests/Integration/Schema/Directives/WhereNotBetweenDirectiveTest.php index b2cc62cf19..fa70cef5c9 100644 --- a/tests/Integration/Schema/Directives/WhereNotBetweenDirectiveTest.php +++ b/tests/Integration/Schema/Directives/WhereNotBetweenDirectiveTest.php @@ -11,8 +11,8 @@ public function testExplicitNull(): void { $users = factory(User::class, 2)->create(); - $this->schema = /** @lang GraphQL */ ' - scalar DateTime @scalar(class: "Nuwave\\\Lighthouse\\\Schema\\\Types\\\Scalars\\\DateTime") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime") type User { id: ID! @@ -27,16 +27,16 @@ public function testExplicitNull(): void from: DateTime! to: DateTime! } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(notCreatedBetween: null) { id } } - ') + GRAPHQL) ->assertGraphQLErrorFree() ->assertJsonCount($users->count(), 'data.users'); } diff --git a/tests/Integration/Schema/Directives/WhereNotNullDirectiveTest.php b/tests/Integration/Schema/Directives/WhereNotNullDirectiveTest.php index 3db2a3c54c..28dddff1f8 100644 --- a/tests/Integration/Schema/Directives/WhereNotNullDirectiveTest.php +++ b/tests/Integration/Schema/Directives/WhereNotNullDirectiveTest.php @@ -19,7 +19,7 @@ public function testWhereNull(): void $null->name = null; $null->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -27,16 +27,16 @@ public function testWhereNull(): void type Query { users(nameIsNotNull: Boolean @whereNotNull(key: "name")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'users' => [ @@ -51,13 +51,13 @@ public function testWhereNull(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(nameIsNotNull: null) { id } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'users' => [ @@ -72,13 +72,13 @@ public function testWhereNull(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(nameIsNotNull: true) { id } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'users' => [ @@ -90,13 +90,13 @@ public function testWhereNull(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(nameIsNotNull: false) { id } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'users' => [ diff --git a/tests/Integration/Schema/Directives/WhereNullDirectiveTest.php b/tests/Integration/Schema/Directives/WhereNullDirectiveTest.php index 825ebb3166..20e14a6a81 100644 --- a/tests/Integration/Schema/Directives/WhereNullDirectiveTest.php +++ b/tests/Integration/Schema/Directives/WhereNullDirectiveTest.php @@ -19,7 +19,7 @@ public function testWhereNull(): void $null->name = null; $null->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -27,16 +27,16 @@ public function testWhereNull(): void type Query { users(nameIsNull: Boolean @whereNull(key: "name")): [User!]! @all } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { id } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'users' => [ @@ -51,13 +51,13 @@ public function testWhereNull(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(nameIsNull: null) { id } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'users' => [ @@ -72,13 +72,13 @@ public function testWhereNull(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(nameIsNull: true) { id } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'users' => [ @@ -90,13 +90,13 @@ public function testWhereNull(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(nameIsNull: false) { id } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'users' => [ diff --git a/tests/Integration/Schema/Directives/WithCountDirectiveTest.php b/tests/Integration/Schema/Directives/WithCountDirectiveTest.php index 04fde40f26..2a861ad740 100644 --- a/tests/Integration/Schema/Directives/WithCountDirectiveTest.php +++ b/tests/Integration/Schema/Directives/WithCountDirectiveTest.php @@ -11,7 +11,7 @@ final class WithCountDirectiveTest extends DBTestCase { public function testEagerLoadsRelationCount(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [User!] @all } @@ -21,7 +21,7 @@ public function testEagerLoadsRelationCount(): void @withCount(relation: "tasks") @method } - '; + GRAPHQL; factory(User::class, 3)->create() ->each(static function (User $user): void { @@ -33,13 +33,13 @@ public function testEagerLoadsRelationCount(): void }); $this->assertQueryCountMatches(2, function (): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { tasksCountLoaded } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -59,7 +59,7 @@ public function testEagerLoadsRelationCount(): void public function testFailsToEagerLoadRelationCountWithoutRelation(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [User!] @all } @@ -67,17 +67,17 @@ public function testFailsToEagerLoadRelationCountWithoutRelation(): void type User { name: String! @withCount } - '; + GRAPHQL; factory(User::class)->create(); $this->expectException(DefinitionException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { name } } - '); + GRAPHQL); } } diff --git a/tests/Integration/Schema/Directives/WithDirectiveTest.php b/tests/Integration/Schema/Directives/WithDirectiveTest.php index 3e20f752d1..1646f36805 100644 --- a/tests/Integration/Schema/Directives/WithDirectiveTest.php +++ b/tests/Integration/Schema/Directives/WithDirectiveTest.php @@ -15,7 +15,7 @@ final class WithDirectiveTest extends DBTestCase { public function testEagerLoadsRelation(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User @first } @@ -25,7 +25,7 @@ public function testEagerLoadsRelation(): void @with(relation: "tasks") @method } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -41,13 +41,13 @@ public function testEagerLoadsRelation(): void $user->tasksLoaded(), ); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { tasksLoaded } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'user' => [ 'tasksLoaded' => true, @@ -58,7 +58,7 @@ public function testEagerLoadsRelation(): void public function testEagerLoadsNestedRelation(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: User @first } @@ -68,7 +68,7 @@ public function testEagerLoadsNestedRelation(): void @with(relation: "posts.comments") @method } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -90,13 +90,13 @@ public function testEagerLoadsNestedRelation(): void $user->postsCommentsLoaded(), ); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { postsCommentsLoaded } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'postsCommentsLoaded' => true, @@ -107,7 +107,7 @@ public function testEagerLoadsNestedRelation(): void public function testEagerLoadsPolymorphicRelations(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { activity: [Activity!] @all } @@ -132,7 +132,7 @@ public function testEagerLoadsPolymorphicRelations(): void type Image { id: ID } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -182,7 +182,7 @@ public function testEagerLoadsPolymorphicRelations(): void factory(Image::class, 4)->make(), ); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { activity { id @@ -205,7 +205,7 @@ public function testEagerLoadsPolymorphicRelations(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'activity' => [ [ @@ -245,7 +245,7 @@ public function testEagerLoadsPolymorphicRelations(): void public function testEagerLoadsMultipleRelationsAtOnce(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: User @first @@ -257,7 +257,7 @@ public function testEagerLoadsMultipleRelationsAtOnce(): void @with(relation: "posts.comments") @method } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -285,13 +285,13 @@ public function testEagerLoadsMultipleRelationsAtOnce(): void $user->tasksAndPostsCommentsLoaded(), ); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { tasksAndPostsCommentsLoaded } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'tasksAndPostsCommentsLoaded' => true, @@ -307,7 +307,7 @@ public function testEagerLoadsMultipleNestedRelationsAtOnce(): void $this->markTestSkipped("Not working due to the current naive usage of {$eloquentCollection}::load() in {$simpleModelsLoader}::load()."); // @phpstan-ignore-next-line unreachable due to markTestSkipped - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { users: User @first @@ -319,7 +319,7 @@ public function testEagerLoadsMultipleNestedRelationsAtOnce(): void @with(relation: "posts.comments") @method } - '; + GRAPHQL; $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); @@ -359,13 +359,13 @@ public function testEagerLoadsMultipleNestedRelationsAtOnce(): void $user->postTasksAndPostsCommentsLoaded(), ); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { postTasksAndPostsCommentsLoaded } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'postTasksAndPostsCommentsLoaded' => true, @@ -378,10 +378,10 @@ public function testWithDirectiveOnRootFieldThrows(): void { $this->expectException(DefinitionException::class); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @with(relation: "tasks") } - '); + GRAPHQL); } } diff --git a/tests/Integration/Schema/Directives/WithoutGlobalScopesDirectiveTest.php b/tests/Integration/Schema/Directives/WithoutGlobalScopesDirectiveTest.php index 985de601fb..ec8a5a736d 100644 --- a/tests/Integration/Schema/Directives/WithoutGlobalScopesDirectiveTest.php +++ b/tests/Integration/Schema/Directives/WithoutGlobalScopesDirectiveTest.php @@ -20,7 +20,7 @@ public function testOmitsScopesWhenArgumentValueIsTrue(): void $unscheduledPodcast->schedule_at = null; $unscheduledPodcast->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { podcasts( includeUnscheduled: Boolean @withoutGlobalScopes(names: ["scheduled"]) @@ -30,22 +30,22 @@ public function testOmitsScopesWhenArgumentValueIsTrue(): void type Podcast { id: ID! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { podcasts { id } } - ')->assertJsonCount(1, 'data.podcasts'); + GRAPHQL)->assertJsonCount(1, 'data.podcasts'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { podcasts(includeUnscheduled: true) { id } } - ')->assertJsonCount(2, 'data.podcasts'); + GRAPHQL)->assertJsonCount(2, 'data.podcasts'); } } diff --git a/tests/Integration/Schema/ResolverProviderTest.php b/tests/Integration/Schema/ResolverProviderTest.php index 854cb70a97..3595375fbf 100644 --- a/tests/Integration/Schema/ResolverProviderTest.php +++ b/tests/Integration/Schema/ResolverProviderTest.php @@ -10,17 +10,17 @@ final class ResolverProviderTest extends TestCase { public function testRootQuery(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -32,7 +32,7 @@ public function testNonRootFields(): void $id = '123'; $this->mockResolver(['id' => $id]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User @mock } @@ -41,16 +41,16 @@ public function testNonRootFields(): void id: ID! nonRootClassResolver: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { id nonRootClassResolver } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'id' => $id, @@ -68,7 +68,7 @@ public function testRootQueryMutationPayload(): void $barResult = 2; $this->mockResolver($barResult, 'bar'); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { bar: Int! @mock(key: "bar") } @@ -81,9 +81,9 @@ public function testRootQueryMutationPayload(): void result: Int! query: Query! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { foo { result @@ -92,7 +92,7 @@ public function testRootQueryMutationPayload(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => [ 'result' => $fooResult, diff --git a/tests/Integration/Schema/Types/InterfaceTest.php b/tests/Integration/Schema/Types/InterfaceTest.php index a1ce622131..04d7f50af8 100644 --- a/tests/Integration/Schema/Types/InterfaceTest.php +++ b/tests/Integration/Schema/Types/InterfaceTest.php @@ -36,7 +36,7 @@ interface Nameable { } GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { namedThings { name @@ -45,7 +45,7 @@ interface Nameable { } } } - ')->assertJsonStructure([ + GRAPHQL)->assertJsonStructure([ 'data' => [ 'namedThings' => [ [ @@ -86,7 +86,7 @@ interface Nameable { } GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { namedThings { name @@ -95,7 +95,7 @@ interface Nameable { } } } - ')->assertJsonStructure([ + GRAPHQL)->assertJsonStructure([ 'data' => [ 'namedThings' => [ [ @@ -136,13 +136,13 @@ interface Nameable { GRAPHQL; $this->expectNotToPerformAssertions(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { namedThings { name } } - '); + GRAPHQL); } public function testThrowsOnAmbiguousSchemaMapping(): void @@ -171,13 +171,13 @@ interface Nameable { $this->expectExceptionObject( TypeRegistry::unresolvableAbstractTypeMapping(User::class, ['Foo', 'Team']), ); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { namedThings { name } } - '); + GRAPHQL); } public function testThrowsOnNonOverlappingSchemaMapping(): void @@ -206,13 +206,13 @@ interface Nameable { $this->expectExceptionObject( TypeRegistry::unresolvableAbstractTypeMapping(User::class, []), ); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { namedThings { name } } - '); + GRAPHQL); } public function testUseCustomTypeResolver(): void @@ -232,7 +232,7 @@ interface Nameable @interface(resolveType: "{$this->qualifyTestResolver('resolve } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { namedThings { name @@ -241,7 +241,7 @@ interface Nameable @interface(resolveType: "{$this->qualifyTestResolver('resolve } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'namedThings' => $this->fetchGuy(), ], @@ -272,7 +272,7 @@ interface Nameable { } GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { __schema { types { @@ -284,7 +284,7 @@ interface Nameable { } } } - '); + GRAPHQL); $interface = (new Collection($result->json('data.__schema.types'))) ->firstWhere('name', 'Nameable'); @@ -317,7 +317,7 @@ interface HasPosts { } GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { __type(name: "HasPosts") { name @@ -333,7 +333,7 @@ interface HasPosts { } } } - '); + GRAPHQL); $this->assertSame('HasPosts', $result->json('data.__type.name')); $this->assertSame('INTERFACE', $result->json('data.__type.kind')); diff --git a/tests/Integration/Schema/Types/LaravelEnumTypeDBTest.php b/tests/Integration/Schema/Types/LaravelEnumTypeDBTest.php index 8f93f24944..004d5a1d26 100644 --- a/tests/Integration/Schema/Types/LaravelEnumTypeDBTest.php +++ b/tests/Integration/Schema/Types/LaravelEnumTypeDBTest.php @@ -21,7 +21,7 @@ protected function setUp(): void public function testUseLaravelEnumType(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { withEnum(type: AOrB @eq): WithEnum @find } @@ -33,7 +33,7 @@ public function testUseLaravelEnumType(): void type WithEnum { type: AOrB } - '; + GRAPHQL; $this->typeRegistry->register( new LaravelEnumType(AOrB::class), @@ -43,27 +43,27 @@ public function testUseLaravelEnumType(): void 'type' => 'A', ]; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { createWithEnum(type: A) { type } } - ')->assertJsonFragment($typeA); + GRAPHQL)->assertJsonFragment($typeA); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { withEnum(type: A) { type } } - ')->assertJsonFragment($typeA); + GRAPHQL)->assertJsonFragment($typeA); } public function testWhereJsonContainsUsingEnumType(): void { // We use the "name" field to store the "type" JSON - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { withEnum( type: AOrB @whereJsonContains(key: "name") @@ -73,7 +73,7 @@ public function testWhereJsonContainsUsingEnumType(): void type WithEnum { name: String } - '; + GRAPHQL; $this->typeRegistry->register( new LaravelEnumType(AOrB::class), @@ -85,13 +85,13 @@ public function testWhereJsonContainsUsingEnumType(): void $withEnum->name = $encodedType; $withEnum->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { withEnum(type: A) { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'withEnum' => [ 'name' => $encodedType, @@ -102,7 +102,7 @@ public function testWhereJsonContainsUsingEnumType(): void public function testScopeUsingEnumType(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { withEnum( byType: AOrB @scope @@ -112,7 +112,7 @@ public function testScopeUsingEnumType(): void type WithEnum { type: AOrB } - '; + GRAPHQL; $this->typeRegistry->register( new LaravelEnumType(AOrB::class), @@ -124,13 +124,13 @@ public function testScopeUsingEnumType(): void $withEnum->type = $a; $withEnum->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($type: AOrB) { withEnum(byType: $type) { type } } - ', [ + GRAPHQL, [ 'type' => $a->key, ])->assertJson([ 'data' => [ diff --git a/tests/Integration/Schema/Types/UnionTest.php b/tests/Integration/Schema/Types/UnionTest.php index 82cbee0314..cabdcb1082 100644 --- a/tests/Integration/Schema/Types/UnionTest.php +++ b/tests/Integration/Schema/Types/UnionTest.php @@ -62,18 +62,18 @@ public function testConsidersRenamedModels(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' - { - stuff { - ... on Foo { - name - } - ... on Post { - title + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + stuff { + ... on Foo { + name + } + ... on Post { + title + } + } } - } - } - ')->assertJsonStructure([ + GRAPHQL)->assertJsonStructure([ 'data' => [ 'stuff' => [ [ @@ -91,8 +91,7 @@ public function testRejectsUnionWithString(): void { $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<expectExceptionObject(new InvariantViolation( @@ -128,18 +127,18 @@ public function testThrowsOnAmbiguousSchemaMapping(): void $this->expectExceptionObject( TypeRegistry::unresolvableAbstractTypeMapping(User::class, ['Foo', 'Post']), ); - $this->graphQL(/** @lang GraphQL */ ' - { - stuff { - ... on Foo { - name - } - ... on Post { - title + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + stuff { + ... on Foo { + name + } + ... on Post { + title + } + } } - } - } - '); + GRAPHQL); } public function testThrowsOnNonOverlappingSchemaMapping(): void @@ -169,15 +168,15 @@ public function testThrowsOnNonOverlappingSchemaMapping(): void $this->expectExceptionObject( TypeRegistry::unresolvableAbstractTypeMapping(User::class, []), ); - $this->graphQL(/** @lang GraphQL */ ' - { - stuff { - ... on Post { - title + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + stuff { + ... on Post { + title + } + } } - } - } - '); + GRAPHQL); } /** @return \Illuminate\Support\Collection */ @@ -206,13 +205,15 @@ public static function schemaAndQuery(bool $withCustomTypeResolver): array : ''; $customResolver = $withCustomTypeResolver - ? /** @lang GraphQL */ '@union(resolveType: "Tests\\\\Utils\\\\Unions\\\\CustomStuff@resolveType")' + ? /** @lang GraphQL */ <<<'GRAPHQL' + @union(resolveType: "Tests\\Utils\\Unions\\CustomStuff@resolveType") + GRAPHQL : ''; $fetchResultsResolver = self::qualifyTestResolver('fetchResults'); return [ -/** @lang GraphQL */ " +/** @lang GraphQL */ <<schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(foo: Foo): Int } @@ -18,7 +18,7 @@ public function testOutputTypeUsedAsInput(): void type Foo { foo: Int } - '; + GRAPHQL; $schemaValidator = $this->app->make(SchemaValidator::class); diff --git a/tests/Integration/SchemaCacheTest.php b/tests/Integration/SchemaCacheTest.php index f4bb85023c..7aa8d01176 100644 --- a/tests/Integration/SchemaCacheTest.php +++ b/tests/Integration/SchemaCacheTest.php @@ -32,7 +32,7 @@ protected function tearDown(): void public function testSchemaCachingWithUnionType(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Foo @mock } @@ -46,14 +46,14 @@ public function testSchemaCachingWithUnionType(): void type Color { id: ID } - '; + GRAPHQL; $this->cacheSchema(); $comment = new Comment(); $comment->comment = 'foo'; $this->mockResolver($comment); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { ... on Comment { @@ -61,7 +61,7 @@ public function testSchemaCachingWithUnionType(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => [ 'comment' => $comment->comment, @@ -80,11 +80,11 @@ public function testInvalidSchemaCacheContents(): void $this->expectException(\AssertionError::class); $this->expectExceptionMessage("The schema cache file at {$path} is expected to return an array."); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } private function cacheSchema(): void diff --git a/tests/Integration/Scout/SearchDirectiveTest.php b/tests/Integration/Scout/SearchDirectiveTest.php index 0a17979dde..0e8de177ba 100644 --- a/tests/Integration/Scout/SearchDirectiveTest.php +++ b/tests/Integration/Scout/SearchDirectiveTest.php @@ -34,7 +34,7 @@ public function testSearch(): void new EloquentCollection([$postA, $postB]), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts(search: "great") { id title } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'posts' => [ [ @@ -78,7 +78,7 @@ public function testSearchWithEq(): void ->andReturn(new EloquentCollection()) ->once(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: Int) { posts(id: $id, search: "great") { id } } - ', [ + GRAPHQL, [ 'id' => $id, ])->assertJson([ 'data' => [ @@ -133,13 +133,13 @@ public function testSearchWithBuilder(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: Int!) { posts(input: { id: $id }, search: "greatness") { id } } - ', [ + GRAPHQL, [ 'id' => $id, ])->assertJson([ 'data' => [ @@ -162,7 +162,7 @@ public function testSearchWithTrashed(): void ->andReturn(new EloquentCollection()) ->once(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: Int! } @@ -173,15 +173,15 @@ public function testSearchWithTrashed(): void search: String @search ): [Post!]! @all @softDeletes } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts(search: "foo", trashed: ONLY) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'posts' => [], ], @@ -206,25 +206,25 @@ public function testSearchWithinCustomIndex(): void ) ->once(); - $this->schema = /** @lang GraphQL */ " + $this->schema = /** @lang GraphQL */ <<graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts(search: "great") { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'posts' => [ [ @@ -240,7 +240,7 @@ public function testSearchWithinCustomIndex(): void public function testWithinMustBeString(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! } @@ -250,22 +250,22 @@ public function testWithinMustBeString(): void search: String @search(within: 123) ): [Post!]! @all } - '; + GRAPHQL; $this->expectException(DefinitionException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts(search: "great") { id } } - '); + GRAPHQL); } public function testMultipleSearchesAreNotAllowed(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! } @@ -276,22 +276,22 @@ public function testMultipleSearchesAreNotAllowed(): void second: String @search ): [Post!]! @all } - '; + GRAPHQL; $this->expectException(ScoutException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts(first: "great", second: "nope") { id } } - '); + GRAPHQL); } public function testIncompatibleArgBuildersAreNotAllowed(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! } @@ -302,22 +302,22 @@ public function testIncompatibleArgBuildersAreNotAllowed(): void nope: String @neq ): [Post!]! @all } - '; + GRAPHQL; $this->expectException(ScoutException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts(search: "great", nope: "nope") { id } } - '); + GRAPHQL); } public function testModelMustBeSearchable(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! } @@ -327,17 +327,17 @@ public function testModelMustBeSearchable(): void search: String @search ): [Task!]! @all } - '; + GRAPHQL; $this->expectException(ScoutException::class); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(search: "great") { id } } - '); + GRAPHQL); } public function testHandlesScoutBuilderPaginationArguments(): void @@ -363,7 +363,7 @@ public function testHandlesScoutBuilderPaginationArguments(): void ->andReturn(new EloquentCollection([$postA, $postB])) ->once(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Post { id: ID! } @@ -373,9 +373,9 @@ public function testHandlesScoutBuilderPaginationArguments(): void search: String @search ): [Post!]! @paginate } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts(first: 10, search: "great") { data { @@ -383,7 +383,7 @@ public function testHandlesScoutBuilderPaginationArguments(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'posts' => [ 'data' => [ diff --git a/tests/Integration/SoftDeletes/ForceDeleteDirectiveTest.php b/tests/Integration/SoftDeletes/ForceDeleteDirectiveTest.php index c9aadb21b1..b96d3dd728 100644 --- a/tests/Integration/SoftDeletes/ForceDeleteDirectiveTest.php +++ b/tests/Integration/SoftDeletes/ForceDeleteDirectiveTest.php @@ -14,7 +14,7 @@ public function testForceDeletesTaskAndReturnsIt(): void { factory(Task::class)->create(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! } @@ -22,15 +22,15 @@ public function testForceDeletesTaskAndReturnsIt(): void type Mutation { forceDeleteTask(id: ID! @whereKey): Task @forceDelete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { forceDeleteTask(id: 1) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'forceDeleteTask' => [ 'id' => 1, @@ -46,7 +46,7 @@ public function testForceDeletesDeletedTaskAndReturnsIt(): void $task = factory(Task::class)->create(); $task->delete(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! } @@ -54,15 +54,15 @@ public function testForceDeletesDeletedTaskAndReturnsIt(): void type Mutation { forceDeleteTask(id: ID! @whereKey): Task @forceDelete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { forceDeleteTask(id: 1) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'forceDeleteTask' => [ 'id' => 1, @@ -77,7 +77,7 @@ public function testForceDeletesMultipleTasksAndReturnsThem(): void { factory(Task::class, 2)->create(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String @@ -86,15 +86,15 @@ public function testForceDeletesMultipleTasksAndReturnsThem(): void type Mutation { forceDeleteTasks(id: [ID!]! @whereKey): [Task!]! @forceDelete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { forceDeleteTasks(id: [1, 2]) { name } } - ')->assertJsonCount(2, 'data.forceDeleteTasks'); + GRAPHQL)->assertJsonCount(2, 'data.forceDeleteTasks'); $this->assertCount(0, Task::withTrashed()->get()); } @@ -110,7 +110,7 @@ public function testDirectiveIncludesTrashedModelsWhenUsingForceDelete(): void $user->tasks()->save($task); $task->delete(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String @@ -121,15 +121,15 @@ public function testDirectiveIncludesTrashedModelsWhenUsingForceDelete(): void @can(ability: "delete", query: true) @forceDelete } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { forceDeleteTasks(id: 1) { name } } - ')->assertJsonCount(1, 'data.forceDeleteTasks'); + GRAPHQL)->assertJsonCount(1, 'data.forceDeleteTasks'); $this->assertCount(0, Task::withTrashed()->get()); } @@ -145,7 +145,7 @@ public function testDirectiveUsesExplicitTrashedArgument(): void $user->tasks()->save($task); $task->delete(); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String @@ -158,15 +158,15 @@ public function testDirectiveUsesExplicitTrashedArgument(): void # The order has to be like this, otherwise @forceDelete will throw @softDeletes } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { forceDeleteTasks(id: 1, trashed: WITH) { name } } - ')->assertJsonCount(1, 'data.forceDeleteTasks'); + GRAPHQL)->assertJsonCount(1, 'data.forceDeleteTasks'); $this->assertCount(0, Task::withTrashed()->get()); } @@ -174,7 +174,7 @@ public function testDirectiveUsesExplicitTrashedArgument(): void public function testRejectsUsingDirectiveWithNonSoftDeleteModels(): void { $this->expectExceptionMessage(ForceDeleteDirective::MODEL_NOT_USING_SOFT_DELETES); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -182,6 +182,6 @@ public function testRejectsUsingDirectiveWithNonSoftDeleteModels(): void type Query { deleteUser(id: ID! @whereKey): User @forceDelete } - '); + GRAPHQL); } } diff --git a/tests/Integration/SoftDeletes/RestoreDirectiveTest.php b/tests/Integration/SoftDeletes/RestoreDirectiveTest.php index 54f9f6dcbd..30f8336c07 100644 --- a/tests/Integration/SoftDeletes/RestoreDirectiveTest.php +++ b/tests/Integration/SoftDeletes/RestoreDirectiveTest.php @@ -18,7 +18,7 @@ public function testRestoresTaskAndReturnsIt(): void $this->assertCount(1, Task::withTrashed()->get()); $this->assertCount(0, Task::withoutTrashed()->get()); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! } @@ -26,15 +26,15 @@ public function testRestoresTaskAndReturnsIt(): void type Mutation { restoreTask(id: ID! @whereKey): Task @restore } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { restoreTask(id: 1) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'restoreTask' => [ 'id' => 1, @@ -55,7 +55,7 @@ public function testRestoresMultipleTasksAndReturnsThem(): void $this->assertCount(2, Task::withTrashed()->get()); $this->assertCount(0, Task::withoutTrashed()->get()); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String @@ -64,15 +64,15 @@ public function testRestoresMultipleTasksAndReturnsThem(): void type Mutation { restoreTasks(id: [ID!]! @whereKey): [Task!]! @restore } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { restoreTasks(id: [1, 2]) { name } } - ')->assertJsonCount(2, 'data.restoreTasks'); + GRAPHQL)->assertJsonCount(2, 'data.restoreTasks'); $this->assertCount(2, Task::withoutTrashed()->get()); } @@ -90,7 +90,7 @@ public function testDirectiveExcludesTrashedModelsWhenUsingRestore(): void $this->assertCount(0, Task::withoutTrashed()->get()); - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! name: String @@ -101,15 +101,15 @@ public function testDirectiveExcludesTrashedModelsWhenUsingRestore(): void @can(ability: "delete", query: true) @restore } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { restoreTasks(id: 1) { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'restoreTasks' => [ 'name' => $task->name, @@ -124,7 +124,7 @@ public function testRejectsUsingDirectiveWithNonSoftDeleteModels(): void { $this->expectExceptionMessage(RestoreDirective::MODEL_NOT_USING_SOFT_DELETES); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -132,6 +132,6 @@ public function testRejectsUsingDirectiveWithNonSoftDeleteModels(): void type Query { restoreUser(id: ID! @whereKey): User @restore } - '); + GRAPHQL); } } diff --git a/tests/Integration/SoftDeletes/SoftDeletesAndTrashedDirectiveTest.php b/tests/Integration/SoftDeletes/SoftDeletesAndTrashedDirectiveTest.php index 1a39ad933a..0c36487da7 100644 --- a/tests/Integration/SoftDeletes/SoftDeletesAndTrashedDirectiveTest.php +++ b/tests/Integration/SoftDeletes/SoftDeletesAndTrashedDirectiveTest.php @@ -15,7 +15,7 @@ public function testWithAllDirective(): void $taskToRemove = $tasks[2]; $taskToRemove->delete(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! } @@ -23,15 +23,15 @@ public function testWithAllDirective(): void type Query { tasks: [Task!]! @all @softDeletes } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(trashed: ONLY) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'tasks' => [ [ @@ -41,29 +41,29 @@ public function testWithAllDirective(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(trashed: WITH) { id } } - ')->assertJsonCount(3, 'data.tasks'); + GRAPHQL)->assertJsonCount(3, 'data.tasks'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(trashed: WITHOUT) { id } } - ')->assertJsonCount(2, 'data.tasks'); + GRAPHQL)->assertJsonCount(2, 'data.tasks'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks { id } } - ')->assertJsonCount(2, 'data.tasks'); + GRAPHQL)->assertJsonCount(2, 'data.tasks'); } public function testNullDoesNothing(): void @@ -75,7 +75,7 @@ public function testNullDoesNothing(): void $leftoverTask = $tasks[1]; - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! } @@ -83,15 +83,15 @@ public function testNullDoesNothing(): void type Query { tasks: [Task!]! @all @softDeletes } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(trashed: null) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'tasks' => [ [ @@ -108,7 +108,7 @@ public function testWithFindDirective(): void $taskToRemove = factory(Task::class)->create(); $taskToRemove->delete(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! } @@ -116,15 +116,15 @@ public function testWithFindDirective(): void type Query { task(id: ID! @eq): Task @find @softDeletes } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { task(id: 1, trashed: ONLY) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'task' => [ 'id' => $taskToRemove->id, @@ -132,13 +132,13 @@ public function testWithFindDirective(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { task(id: 1, trashed: WITH) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'task' => [ 'id' => $taskToRemove->id, @@ -146,25 +146,25 @@ public function testWithFindDirective(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { task(id: 1, trashed: WITHOUT) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'task' => null, ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { task(id: 1) { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'task' => null, ], @@ -178,7 +178,7 @@ public function testWithPaginateDirective(): void $taskToRemove = $tasks[2]; $taskToRemove->delete(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! } @@ -186,9 +186,9 @@ public function testWithPaginateDirective(): void type Query { tasks: [Task!]! @paginate @softDeletes } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(first: 10, trashed: ONLY) { data { @@ -196,7 +196,7 @@ public function testWithPaginateDirective(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'tasks' => [ 'data' => [ @@ -208,7 +208,7 @@ public function testWithPaginateDirective(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(first: 10, trashed: WITH) { data { @@ -216,9 +216,9 @@ public function testWithPaginateDirective(): void } } } - ')->assertJsonCount(3, 'data.tasks.data'); + GRAPHQL)->assertJsonCount(3, 'data.tasks.data'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(first: 10, trashed: WITHOUT) { data { @@ -226,9 +226,9 @@ public function testWithPaginateDirective(): void } } } - ')->assertJsonCount(2, 'data.tasks.data'); + GRAPHQL)->assertJsonCount(2, 'data.tasks.data'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { tasks(first: 10) { data { @@ -236,7 +236,7 @@ public function testWithPaginateDirective(): void } } } - ')->assertJsonCount(2, 'data.tasks.data'); + GRAPHQL)->assertJsonCount(2, 'data.tasks.data'); } public function testNested(): void @@ -254,7 +254,7 @@ public function testNested(): void factory(Task::class, 2)->make(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Task { id: ID! } @@ -269,9 +269,9 @@ public function testNested(): void usersPaginated: [User!]! @paginate user(id: ID! @eq): User @find } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { tasks(trashed: ONLY) { @@ -279,7 +279,7 @@ public function testNested(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ [ @@ -293,7 +293,7 @@ public function testNested(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { usersPaginated(first: 10) { data { @@ -303,7 +303,7 @@ public function testNested(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'usersPaginated' => [ 'data' => [ @@ -319,7 +319,7 @@ public function testNested(): void ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: 1) { tasks(trashed: ONLY) { @@ -327,7 +327,7 @@ public function testNested(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'tasks' => [ @@ -340,7 +340,7 @@ public function testNested(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { tasksWith: tasks(trashed: WITH) { @@ -354,13 +354,13 @@ public function testNested(): void } } } - ') + GRAPHQL) ->assertJsonCount(3, 'data.users.0.tasksWith') ->assertJsonCount(2, 'data.users.0.tasksWithout') ->assertJsonCount(2, 'data.users.0.tasksSimple'); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { usersPaginated(first: 10) { data { @@ -376,13 +376,13 @@ public function testNested(): void } } } - ') + GRAPHQL) ->assertJsonCount(3, 'data.usersPaginated.data.0.tasksWith') ->assertJsonCount(2, 'data.usersPaginated.data.0.tasksWithout') ->assertJsonCount(2, 'data.usersPaginated.data.0.tasksSimple'); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(id: 1) { tasksWith: tasks(trashed: WITH) { @@ -396,7 +396,7 @@ public function testNested(): void } } } - ') + GRAPHQL) ->assertJsonCount(3, 'data.user.tasksWith') ->assertJsonCount(2, 'data.user.tasksWithout') ->assertJsonCount(2, 'data.user.tasksSimple'); @@ -404,7 +404,7 @@ public function testNested(): void public function testThrowsIfModelDoesNotSupportSoftDeletesTrashed(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { trashed(trashed: Trashed @trashed): [User!]! @all } @@ -412,21 +412,21 @@ public function testThrowsIfModelDoesNotSupportSoftDeletesTrashed(): void type User { id: ID } - '; + GRAPHQL; $this->expectExceptionMessage(TrashedDirective::MODEL_MUST_USE_SOFT_DELETES); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { trashed(trashed: WITH) { id } } - '); + GRAPHQL); } public function testThrowsIfModelDoesNotSupportSoftDeletes(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { softDeletes: [User!]! @all @softDeletes } @@ -434,15 +434,15 @@ public function testThrowsIfModelDoesNotSupportSoftDeletes(): void type User { id: ID } - '; + GRAPHQL; $this->expectExceptionMessage(TrashedDirective::MODEL_MUST_USE_SOFT_DELETES); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { softDeletes(trashed: WITH) { id } } - '); + GRAPHQL); } } diff --git a/tests/Integration/Subscriptions/Broadcast/BroadcastDBTest.php b/tests/Integration/Subscriptions/Broadcast/BroadcastDBTest.php index d800bf4253..c17b7d91a0 100644 --- a/tests/Integration/Subscriptions/Broadcast/BroadcastDBTest.php +++ b/tests/Integration/Subscriptions/Broadcast/BroadcastDBTest.php @@ -53,13 +53,13 @@ public function testBroadcastsFromPhp(): void ->shouldReceive('broadcast') ->once(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' subscription UserUpdated { taskUpdated { name } } - '); + GRAPHQL); Subscription::broadcast('taskUpdated', []); } @@ -70,20 +70,20 @@ public function testBroadcastsFromSchema(): void ->shouldReceive('broadcast') ->once(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' subscription TaskUpdated { taskUpdated { name } } - '); + GRAPHQL); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' mutation { updateTask(id: 1, name: "New name") { name } } - '); + GRAPHQL); } } diff --git a/tests/Integration/Subscriptions/EchoBroadcaster/AuthorizeRequestsTest.php b/tests/Integration/Subscriptions/EchoBroadcaster/AuthorizeRequestsTest.php index 4a5c0a6b2a..ec89d717d0 100644 --- a/tests/Integration/Subscriptions/EchoBroadcaster/AuthorizeRequestsTest.php +++ b/tests/Integration/Subscriptions/EchoBroadcaster/AuthorizeRequestsTest.php @@ -108,13 +108,13 @@ public function testEchoClientAuthorizeFailsAfterDelete(): void private function querySubscription(): TestResponse { - return $this->graphQL(/** @lang GraphQL */ ' + return $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' subscription { taskUpdated(id: 123) { id name } } - '); + GRAPHQL); } } diff --git a/tests/Integration/Subscriptions/Storage/RedisStorageManagerTest.php b/tests/Integration/Subscriptions/Storage/RedisStorageManagerTest.php index 968fbd41df..26ed1e413d 100644 --- a/tests/Integration/Subscriptions/Storage/RedisStorageManagerTest.php +++ b/tests/Integration/Subscriptions/Storage/RedisStorageManagerTest.php @@ -16,15 +16,15 @@ final class RedisStorageManagerTest extends TestCase use EnablesSubscriptionServiceProvider; protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' - type Task { - id: ID! - name: String! - } - - type Subscription { - taskUpdated(id: ID!): Task - taskCreated: Task - } + type Task { + id: ID! + name: String! + } + + type Subscription { + taskUpdated(id: ID!): Task + taskCreated: Task + } GRAPHQL . self::PLACEHOLDER_QUERY; public function testSubscriptionStoredWithPrefix(): void @@ -111,7 +111,9 @@ public function testSocketIDStoredOnSubscribe(): void } /** @param array $headers */ - private function querySubscription(string $topic = /** @lang GraphQL */ 'taskUpdated(id: 123)', array $headers = []): TestResponse + private function querySubscription(string $topic = /** @lang GraphQL */ <<<'GRAPHQL' + taskUpdated(id: 123) + GRAPHQL, array $headers = []): TestResponse { return $this->graphQL(/** @lang GraphQL */ query: " subscription { diff --git a/tests/Integration/Tracing/ApolloTracingExtensionTest.php b/tests/Integration/Tracing/ApolloTracingExtensionTest.php index cc3f174998..224ae57065 100644 --- a/tests/Integration/Tracing/ApolloTracingExtensionTest.php +++ b/tests/Integration/Tracing/ApolloTracingExtensionTest.php @@ -7,11 +7,11 @@ final class ApolloTracingExtensionTest extends TestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { - foo: String! @field(resolver: "Tests\\\Integration\\\Tracing\\\ApolloTracingExtensionTest@resolve") + foo: String! @field(resolver: "Tests\\Integration\\Tracing\\ApolloTracingExtensionTest@resolve") } - '; + GRAPHQL; protected function getPackageProviders($app): array { @@ -24,11 +24,11 @@ protected function getPackageProviders($app): array public function testAddTracingExtensionMetaToResult(): void { $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ') + GRAPHQL) ->assertJsonStructure([ 'extensions' => [ 'tracing' => [ @@ -43,11 +43,11 @@ public function testAddTracingExtensionMetaToResult(): void public function testAddTracingExtensionMetaToBatchedResults(): void { $postData = [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' { foo } - ', + GRAPHQL, ]; $expectedResponse = [ 'extensions' => [ diff --git a/tests/Integration/Tracing/FederatedTracingExtensionTest.php b/tests/Integration/Tracing/FederatedTracingExtensionTest.php index 51c399f488..71e1057fad 100644 --- a/tests/Integration/Tracing/FederatedTracingExtensionTest.php +++ b/tests/Integration/Tracing/FederatedTracingExtensionTest.php @@ -13,16 +13,16 @@ final class FederatedTracingExtensionTest extends TestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Foo! } type Foo @key(fields: "id") { - id: String! @field(resolver: "Tests\\\Integration\\\Tracing\\\FederatedTracingExtensionTest@resolve") - bar: String! @field(resolver: "Tests\\\Integration\\\Tracing\\\FederatedTracingExtensionTest@throw") + id: String! @field(resolver: "Tests\\Integration\\Tracing\\FederatedTracingExtensionTest@resolve") + bar: String! @field(resolver: "Tests\\Integration\\Tracing\\FederatedTracingExtensionTest@throw") } - '; + GRAPHQL; protected function getPackageProviders($app): array { @@ -45,11 +45,11 @@ protected function setUp(): void public function testHeaderIsRequiredToEnableTracing(): void { $response = $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { id } } - '); + GRAPHQL); $response->assertJsonMissingPath('extensions.ftv1'); } @@ -57,11 +57,11 @@ public function testHeaderIsRequiredToEnableTracing(): void public function testAddFtv1ExtensionMetaToResult(): void { $response = $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { id } } - ', + GRAPHQL, headers: ['apollo-federation-include-trace' => FederatedTracing::V1], ); @@ -152,11 +152,11 @@ public function testAddFtv1ExtensionMetaToBatchedResults(): void public function testReportErrorsToResult(): void { $response = $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { bar } } - ', + GRAPHQL, headers: ['apollo-federation-include-trace' => FederatedTracing::V1], ); diff --git a/tests/Integration/Validation/ExistsRuleTest.php b/tests/Integration/Validation/ExistsRuleTest.php index eab6e14001..31e388bd5f 100644 --- a/tests/Integration/Validation/ExistsRuleTest.php +++ b/tests/Integration/Validation/ExistsRuleTest.php @@ -20,7 +20,7 @@ public function testExistsRule(): void $userInvalid->name = 'Tester'; $userInvalid->save(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { callbackUser(id: ID! @eq): User @validator @find macroUser(id: ID! @eq): User @validator @find @@ -29,7 +29,7 @@ public function testExistsRule(): void type User { id: ID! } - '; + GRAPHQL; $this->macroUser($userValid) ->assertGraphQLValidationPasses(); @@ -46,26 +46,26 @@ public function testExistsRule(): void private function macroUser(User $user): TestResponse { - return $this->graphQL(/** @lang GraphQL */ ' + return $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { macroUser(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $user->id, ]); } private function callbackUser(User $user): TestResponse { - return $this->graphQL(/** @lang GraphQL */ ' + return $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { callbackUser(id: $id) { id } } - ', [ + GRAPHQL, [ 'id' => $user->id, ]); } diff --git a/tests/Integration/Validation/RulesDirectiveTest.php b/tests/Integration/Validation/RulesDirectiveTest.php index 9576d2f452..7f37c24214 100644 --- a/tests/Integration/Validation/RulesDirectiveTest.php +++ b/tests/Integration/Validation/RulesDirectiveTest.php @@ -23,20 +23,20 @@ protected function getEnvironmentSetUp($app): void public function testRequired(): void { - $this->schema = /** @lang GraphQL */ ' - type Query { - foo( - required: String @rules(apply: ["required"]) - ): Int - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo( + required: String @rules(apply: ["required"]) + ): Int + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo(required: "foo") - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo(required: "foo") + } + GRAPHQL) ->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, @@ -44,11 +44,11 @@ public function testRequired(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' - { - foo - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL) ->assertGraphQLValidationKeys(['required']); } @@ -58,24 +58,24 @@ public function testDifferentDates(): void $this->markTestSkipped('Not working right now, not sure how it can be fixed.'); // @phpstan-ignore-next-line https://github.com/phpstan/phpstan-phpunit/issues/52 - $this->schema = /** @lang GraphQL */ ' - "A date string with format `Y-m-d`, e.g. `2011-05-23`." - scalar Date @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Date") - - type Query { - foo( - bar: Date @rules(apply: ["different:baz"]) - baz: Date - ): Int - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + "A date string with format `Y-m-d`, e.g. `2011-05-23`." + scalar Date @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date") + + type Query { + foo( + bar: Date @rules(apply: ["different:baz"]) + baz: Date + ): Int + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo(bar: "2020-05-15", baz: "1999-12-01") - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo(bar: "2020-05-15", baz: "1999-12-01") + } + GRAPHQL) ->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, @@ -83,34 +83,34 @@ public function testDifferentDates(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' - { - foo(bar: "2020-05-15", baz: "2020-05-15") - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo(bar: "2020-05-15", baz: "2020-05-15") + } + GRAPHQL) ->assertGraphQLValidationKeys(['bar']); } public function testDateBefore(): void { - $this->schema = /** @lang GraphQL */ ' - "A date string with format `Y-m-d`, e.g. `2011-05-23`." - scalar Date @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Date") - - type Query { - foo( - early: Date @rules(apply: ["before:late"]) - late: Date - ): Int - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + "A date string with format `Y-m-d`, e.g. `2011-05-23`." + scalar Date @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date") + + type Query { + foo( + early: Date @rules(apply: ["before:late"]) + late: Date + ): Int + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo(early: "1999-12-01", late: "2020-05-15") - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo(early: "1999-12-01", late: "2020-05-15") + } + GRAPHQL) ->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, @@ -118,105 +118,105 @@ public function testDateBefore(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' - { - foo(early: "2020-05-15", late: "1999-05-15") - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo(early: "2020-05-15", late: "1999-05-15") + } + GRAPHQL) ->assertGraphQLValidationKeys(['early']); } public function testCustomMessages(): void { - $this->schema = /** @lang GraphQL */ ' - type Query { - foo( - bar: ID @rules( - apply: ["required"] - messages: [ - { - rule: "required", - message: "custom message" - } - ] - ) - ): String - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo( + bar: ID @rules( + apply: ["required"] + messages: [ + { + rule: "required", + message: "custom message" + } + ] + ) + ): String + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL) ->assertGraphQLValidationError('bar', 'custom message'); } public function testCustomMessagesWithMap(): void { - $this->schema = /** @lang GraphQL */ ' - type Query { - foo( - bar: ID @rules( - apply: ["required"] - messages: { - required: "custom message" - } - ) - ): String - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo( + bar: ID @rules( + apply: ["required"] + messages: { + required: "custom message" + } + ) + ): String + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL) ->assertGraphQLValidationError('bar', 'custom message'); } public function testCustomAttributes(): void { - $this->schema = /** @lang GraphQL */ ' - input FooInput { - name: String @rules( - apply: ["required"] - attribute: "name" - ) - type: FooTypeInput - } - - input FooTypeInput { - name: String @rules( - apply: ["required"] - attribute: "name" - ) - type: String @rules(apply: ["required"]) - } - - type Query { - foo( - bar: ID @rules( - apply: ["required"] - attribute: "baz" - ) - emails: [String] @rulesForArray( - apply: ["min:3"] - attribute: "email list" - ) - input: FooInput - ): String - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + input FooInput { + name: String @rules( + apply: ["required"] + attribute: "name" + ) + type: FooTypeInput + } + + input FooTypeInput { + name: String @rules( + apply: ["required"] + attribute: "name" + ) + type: String @rules(apply: ["required"]) + } + + type Query { + foo( + bar: ID @rules( + apply: ["required"] + attribute: "baz" + ) + emails: [String] @rulesForArray( + apply: ["min:3"] + attribute: "email list" + ) + input: FooInput + ): String + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo(emails: [], input: { type: {} }) - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo(emails: [], input: { type: {} }) + } + GRAPHQL) ->assertGraphQLValidationError('bar', 'The baz field is required.') ->assertGraphQLValidationError('emails', AppVersion::atLeast(10.0) ? 'The email list field must have at least 3 items.' @@ -228,28 +228,28 @@ public function testCustomAttributes(): void public function testUsesCustomRuleClass(): void { - $this->schema = /** @lang GraphQL */ ' - type Query { - withCustomRuleClass( - rules: String @rules(apply: ["Tests\\\\Utils\\\\Rules\\\\FooBarRule"]) - rulesForArray: [String!]! @rulesForArray(apply: ["Tests\\\\Utils\\\\Rules\\\\FooBarRule"]) - ): ID @mock - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + withCustomRuleClass( + rules: String @rules(apply: ["Tests\\Utils\\Rules\\FooBarRule"]) + rulesForArray: [String!]! @rulesForArray(apply: ["Tests\\Utils\\Rules\\FooBarRule"]) + ): ID @mock + } + GRAPHQL; $this->mockResolverExpects( $this->never(), ); $this - ->graphQL(/** @lang GraphQL */ ' - { - withCustomRuleClass( - rules: "baz" - rulesForArray: [] - ) - } - ', + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + withCustomRuleClass( + rules: "baz" + rulesForArray: [] + ) + } + GRAPHQL, ) ->assertJsonFragment([ 'rules' => [ @@ -266,20 +266,28 @@ public function testUsesCustomRuleClass(): void public function testValidateApplyArgument(string $applyArgument): void { $this->expectException(DefinitionException::class); - $this->buildSchema(/** @lang GraphQL */ " - type Query { - foo(bar: ID @rules(apply: {$applyArgument})): ID - } - "); + $this->buildSchema(/** @lang GraphQL */ << */ public static function invalidApplyArguments(): iterable { - yield [/** @lang GraphQL */ '123']; - yield [/** @lang GraphQL */ '"123"']; - yield [/** @lang GraphQL */ '[]']; - yield [/** @lang GraphQL */ '[123]']; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + 123 + GRAPHQL]; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + "123" + GRAPHQL]; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + [] + GRAPHQL]; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + [123] + GRAPHQL]; } /** @dataProvider invalidMessageArguments */ @@ -287,56 +295,70 @@ public static function invalidApplyArguments(): iterable public function testValidateMessageArgument(string $messageArgument): void { $this->expectException(DefinitionException::class); - $this->buildSchema(/** @lang GraphQL */ " - type Query { - foo(bar: ID @rules(apply: [\"email\"], messages: {$messageArgument})): ID - } - "); + $this->buildSchema(/** @lang GraphQL */ << */ public static function invalidMessageArguments(): iterable { - yield [/** @lang GraphQL */ '"foo"']; - yield [/** @lang GraphQL */ '{foo: 3}']; - yield [/** @lang GraphQL */ '[1, 2]']; - yield [/** @lang GraphQL */ '[{foo: 3}]']; - yield [/** @lang GraphQL */ '[{rule: "email"}]']; - yield [/** @lang GraphQL */ '[{rule: "email", message: null}]']; - yield [/** @lang GraphQL */ '[{rule: 3, message: "asfd"}]']; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + "foo" + GRAPHQL]; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + {foo: 3} + GRAPHQL]; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + [1, 2] + GRAPHQL]; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + [{foo: 3}] + GRAPHQL]; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + [{rule: "email"}] + GRAPHQL]; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + [{rule: "email", message: null}] + GRAPHQL]; + yield [/** @lang GraphQL */ <<<'GRAPHQL' + [{rule: 3, message: "asfd"}] + GRAPHQL]; } public function testValidateElementsOfListType(): void { - $this->schema = /** @lang GraphQL */ ' - type Query { - foo( - bar: [String] - @rules( - apply: ["required"] - ) - ): String - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo( + bar: [String] + @rules( + apply: ["required"] + ) + ): String + } + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' - { - foo( - bar: ["", null, "bar"] - ) - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo( + bar: ["", null, "bar"] + ) + } + GRAPHQL) ->assertGraphQLValidationKeys(['bar.0', 'bar.1']); $this - ->graphQL(/** @lang GraphQL */ ' - { - foo( - bar: [] - ) - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo( + bar: [] + ) + } + GRAPHQL) ->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, @@ -344,11 +366,11 @@ public function testValidateElementsOfListType(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' - { - foo - } - ') + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' + { + foo + } + GRAPHQL) ->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, diff --git a/tests/Integration/Validation/RulesForArrayDirectiveTest.php b/tests/Integration/Validation/RulesForArrayDirectiveTest.php index 0e990278df..1e835d3dde 100644 --- a/tests/Integration/Validation/RulesForArrayDirectiveTest.php +++ b/tests/Integration/Validation/RulesForArrayDirectiveTest.php @@ -8,29 +8,29 @@ final class RulesForArrayDirectiveTest extends TestCase { public function testValidatesListSize(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( list: [String] @rulesForArray(apply: ["min:1"]) ): ID } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( list: [] ) } - ') + GRAPHQL) ->assertGraphQLValidationKeys(['list']); } public function testValidatesListSizeOfInputObjects(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( list: [Foo] @@ -41,16 +41,16 @@ public function testValidatesListSizeOfInputObjects(): void input Foo { bar: ID } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( list: [] ) } - ') + GRAPHQL) ->assertGraphQLValidationKeys(['list']); } } diff --git a/tests/Integration/Validation/ValidationTest.php b/tests/Integration/Validation/ValidationTest.php index e31e039fc1..839b848065 100644 --- a/tests/Integration/Validation/ValidationTest.php +++ b/tests/Integration/Validation/ValidationTest.php @@ -31,32 +31,32 @@ public function testRunsValidationBeforeCallingTheResolver(): void $this->never(), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { doNotCall( bar: String @rules(apply: ["required"]) ): String @mock } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { doNotCall } - ') + GRAPHQL) ->assertGraphQLValidationKeys(['bar']); } public function testFullValidationError(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( bar: String @rules(apply: ["required"]) ): Int } - '; + GRAPHQL; $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { @@ -93,20 +93,20 @@ public function testFullValidationErrorWithoutLocationParse(): void $config = $this->app->make(ConfigRepository::class); $config->set('lighthouse.parse_source_location', false); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( bar: String @rules(apply: ["required"]) ): Int } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ') + GRAPHQL) ->assertExactJson([ 'errors' => [ [ @@ -129,7 +129,7 @@ public function testFullValidationErrorWithoutLocationParse(): void public function testRunsOnNonRootFields(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Foo @mock } @@ -140,7 +140,7 @@ public function testRunsOnNonRootFields(): void required: Int @rules(apply: ["required"]) ): Int } - '; + GRAPHQL; $this->mockResolver([ 'bar' => 123, @@ -148,14 +148,14 @@ public function testRunsOnNonRootFields(): void ]); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { bar baz } } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'foo' => [ @@ -181,24 +181,24 @@ public function testRunsOnNonRootFields(): void public function testCombinedRulesChangeTheirSemantics(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( bar: Int @rules(apply: ["min:42"]) baz: Int @rules(apply: ["int", "min:42"]) ): ID } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( bar: 21 baz: 21 ) } - ') + GRAPHQL) ->assertGraphQLValidationError('bar', AppVersion::atLeast(10.0) ? 'The bar field must be at least 42 characters.' : 'The bar must be at least 42 characters.') @@ -209,7 +209,7 @@ public function testCombinedRulesChangeTheirSemantics(): void public function testValidatesDifferentPathsIndividually(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( bar: String @rules(apply: ["email"]) @@ -221,10 +221,10 @@ public function testValidatesDifferentPathsIndividually(): void baz: String @rules(apply: ["email"]) input: BazInput } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( bar: "invalid email" @@ -240,7 +240,7 @@ public function testValidatesDifferentPathsIndividually(): void ] ) } - ') + GRAPHQL) ->assertGraphQLValidationKeys([ 'bar', 'input.0.baz', @@ -250,17 +250,17 @@ public function testValidatesDifferentPathsIndividually(): void public function testValidatesListContents(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( list: [String] @rules(apply: ["required", "email"]) ): ID } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( list: [ @@ -270,7 +270,7 @@ public function testValidatesListContents(): void ] ) } - ') + GRAPHQL) ->assertGraphQLValidationKeys([ 'list.0', 'list.2', @@ -281,7 +281,7 @@ public function testSanitizeValidateTransform(): void { $this->mockResolver(static fn ($_, array $args): string => $args['password']); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { password( password: String @@ -290,24 +290,24 @@ public function testSanitizeValidateTransform(): void @hash ): String @mock } - '; + GRAPHQL; - $validPasswordResult = $this->graphQL(/** @lang GraphQL */ ' + $validPasswordResult = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { password(password: " 1234567 ") } - '); + GRAPHQL); $password = $validPasswordResult->json('data.password'); $this->assertNotSame(' 1234567 ', $password); $this->assertTrue(password_verify('1234567', $password)); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { password(password: " 1234 ") } - ') + GRAPHQL) ->assertJson([ 'data' => [ 'password' => null, @@ -318,7 +318,7 @@ public function testSanitizeValidateTransform(): void public function testValidatesRulesOnInputObjectFields(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( input: FooInput @@ -328,10 +328,10 @@ public function testValidatesRulesOnInputObjectFields(): void input FooInput { email: String @rules(apply: ["email"]) } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -339,11 +339,11 @@ public function testValidatesRulesOnInputObjectFields(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationKeys(['input.email']); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -351,13 +351,13 @@ public function testValidatesRulesOnInputObjectFields(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationPasses(); } public function testCombinesArgumentValidationWhenGrouped(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( bar: String @@ -365,24 +365,24 @@ public function testCombinesArgumentValidationWhenGrouped(): void @rules(apply: ["max:3"]) ): Int } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: "f") } - ') + GRAPHQL) ->assertGraphQLValidationError('bar', AppVersion::atLeast(10.0) ? 'The bar field must be at least 2 characters.' : 'The bar must be at least 2 characters.'); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: "fasdf") } - ') + GRAPHQL) ->assertGraphQLValidationError('bar', AppVersion::atLeast(10.0) ? 'The bar field must not be greater than 3 characters.' : 'The bar must not be greater than 3 characters.'); @@ -390,7 +390,7 @@ public function testCombinesArgumentValidationWhenGrouped(): void public function testSingleFieldReferencesAreQualified(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Custom): String } @@ -399,10 +399,10 @@ public function testSingleFieldReferencesAreQualified(): void foo: String bar: String @rules(apply: ["required_if:foo,baz"]) } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -410,11 +410,11 @@ public function testSingleFieldReferencesAreQualified(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationPasses(); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -422,13 +422,13 @@ public function testSingleFieldReferencesAreQualified(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.bar', 'The input.bar field is required when input.foo is baz.'); } public function testOptionalFieldReferencesAreQualified(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Custom): String } @@ -437,10 +437,10 @@ public function testOptionalFieldReferencesAreQualified(): void foo: String @rules(apply: ["after:2018-01-01"]) bar: String @rules(apply: ["after:foo"]) } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -449,11 +449,11 @@ public function testOptionalFieldReferencesAreQualified(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationPasses(); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -462,7 +462,7 @@ public function testOptionalFieldReferencesAreQualified(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.foo', AppVersion::atLeast(10.0) ? 'The input.foo field must be a date after 2018-01-01.' : 'The input.foo must be a date after 2018-01-01.') @@ -481,7 +481,7 @@ public function testCustomValidationWithReferencesAreQualified(): void ValidatorFactory::replacer('equal_field', static fn (string $message, string $attribute, string $rule, array $parameters): string => str_replace(':other', implode(', ', $parameters), $message)); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Custom): String } @@ -491,10 +491,10 @@ public function testCustomValidationWithReferencesAreQualified(): void bar: Int @rules(apply: ["with_reference:equal_field,0,foo"]) baz: Int @rules(apply: ["with_reference:equal_field,0_1,foo,bar"]) } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -504,11 +504,11 @@ public function testCustomValidationWithReferencesAreQualified(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationPasses(); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -518,7 +518,7 @@ public function testCustomValidationWithReferencesAreQualified(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.bar', 'The input.bar must be equal to input.foo.') ->assertGraphQLValidationError('input.baz', 'The input.baz must be equal to input.foo, input.bar.'); } @@ -527,19 +527,19 @@ public function testCustomValidationClassWithReferencesAreQualified(): void { config(['app.debug' => true]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Custom): String } - input Custom @validator(class: "Tests\\\\Utils\\\\Validators\\\\EqualFieldCustomRuleValidator") { + input Custom @validator(class: "Tests\\Utils\\Validators\\EqualFieldCustomRuleValidator") { foo: Int bar: Int } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -548,13 +548,13 @@ public function testCustomValidationClassWithReferencesAreQualified(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.bar', 'input'); } public function testMultipleFieldReferencesAreQualified(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Custom): String } @@ -564,10 +564,10 @@ public function testMultipleFieldReferencesAreQualified(): void bar: String @rules(apply: ["required_without_all:foo,baz"]) baz: String } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -575,34 +575,34 @@ public function testMultipleFieldReferencesAreQualified(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationPasses(); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: {} ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.bar', 'The input.bar field is required when none of input.foo / input.baz are present.'); } public function testClosureRulesAreUsed(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Custom): String } - input Custom @validator(class: "Tests\\\\Utils\\\\Validators\\\\FooClosureValidator") { + input Custom @validator(class: "Tests\\Utils\\Validators\\FooClosureValidator") { foo: String! } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -610,11 +610,11 @@ public function testClosureRulesAreUsed(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationPasses(); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -622,13 +622,13 @@ public function testClosureRulesAreUsed(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.foo', FooClosureValidator::notFoo('input.foo')); } public function testReturnsMultipleValidationErrorsPerField(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( input: FooInput @@ -638,10 +638,10 @@ public function testReturnsMultipleValidationErrorsPerField(): void input FooInput { email: String @rules(apply: ["email", "min:16"]) } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -649,7 +649,7 @@ public function testReturnsMultipleValidationErrorsPerField(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.email', AppVersion::atLeast(10.0) ? 'The input.email field must be a valid email address.' : 'The input.email must be a valid email address.') diff --git a/tests/Integration/Validation/ValidatorDirectiveTest.php b/tests/Integration/Validation/ValidatorDirectiveTest.php index fb15ea7e8a..997fb92d78 100644 --- a/tests/Integration/Validation/ValidatorDirectiveTest.php +++ b/tests/Integration/Validation/ValidatorDirectiveTest.php @@ -11,7 +11,7 @@ final class ValidatorDirectiveTest extends TestCase { public function testUsesValidatorByNamingConvention(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: SelfValidating): ID } @@ -19,10 +19,10 @@ public function testUsesValidatorByNamingConvention(): void input SelfValidating @validator { rules: [String!]! } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -30,7 +30,7 @@ public function testUsesValidatorByNamingConvention(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.rules', AppVersion::atLeast(10.0) ? 'The input.rules field must be a valid email address.' : 'The input.rules must be a valid email address.'); @@ -38,7 +38,7 @@ public function testUsesValidatorByNamingConvention(): void public function testUsesValidatorTwiceNested(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: FooInput): ID } @@ -47,10 +47,10 @@ public function testUsesValidatorTwiceNested(): void email: String self: FooInput } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -61,7 +61,7 @@ public function testUsesValidatorTwiceNested(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.email', AppVersion::atLeast(10.0) ? 'The input.email field must be a valid email address.' : 'The input.email must be a valid email address.') @@ -72,7 +72,7 @@ public function testUsesValidatorTwiceNested(): void public function testUsesSpecifiedValidatorClassWithoutNamespace(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Bar): ID } @@ -80,10 +80,10 @@ public function testUsesSpecifiedValidatorClassWithoutNamespace(): void input Bar @validator(class: "SelfValidatingValidator") { rules: [String!]! } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -91,7 +91,7 @@ public function testUsesSpecifiedValidatorClassWithoutNamespace(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.rules', AppVersion::atLeast(10.0) ? 'The input.rules field must be a valid email address.' : 'The input.rules must be a valid email address.'); @@ -99,18 +99,18 @@ public function testUsesSpecifiedValidatorClassWithoutNamespace(): void public function testUsesSpecifiedValidatorClassWithFullNamespace(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Bar): ID } - input Bar @validator(class: "Tests\\\\Utils\\\\Validators\\\\SelfValidatingValidator") { + input Bar @validator(class: "Tests\\Utils\\Validators\\SelfValidatingValidator") { rules: [String!]! } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -118,7 +118,7 @@ public function testUsesSpecifiedValidatorClassWithFullNamespace(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.rules', AppVersion::atLeast(10.0) ? 'The input.rules field must be a valid email address.' : 'The input.rules must be a valid email address.'); @@ -126,7 +126,7 @@ public function testUsesSpecifiedValidatorClassWithFullNamespace(): void public function testNestedInputsRulesReceiveParameters(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: RulesWithParameters): ID } @@ -138,10 +138,10 @@ public function testNestedInputsRulesReceiveParameters(): void input RulesWithParameters @validator { foo: [RuleWithParameter]! } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -151,7 +151,7 @@ public function testNestedInputsRulesReceiveParameters(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.foo.0.bar', AppVersion::atLeast(10.0) ? 'The input.foo.0.bar field must contain 2 items.' : 'The input.foo.0.bar must contain 2 items.'); @@ -159,7 +159,7 @@ public function testNestedInputsRulesReceiveParameters(): void public function testCustomMessage(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: EmailCustomMessage): ID } @@ -167,10 +167,10 @@ public function testCustomMessage(): void input EmailCustomMessage @validator { email: String } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -178,13 +178,13 @@ public function testCustomMessage(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.email', EmailCustomMessageValidator::MESSAGE); } public function testCustomAttributes(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: EmailCustomAttribute): ID } @@ -192,10 +192,10 @@ public function testCustomAttributes(): void input EmailCustomAttribute @validator { email: String } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -203,7 +203,7 @@ public function testCustomAttributes(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.email', AppVersion::atLeast(10.0) ? 'The email address field must be a valid email address.' : 'The email address must be a valid email address.'); @@ -211,7 +211,7 @@ public function testCustomAttributes(): void public function testWithGlobalId(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: WithGlobalId!): ID } @@ -219,13 +219,13 @@ public function testWithGlobalId(): void input WithGlobalId @validator { id: ID! @globalId } - '; + GRAPHQL; $encoder = $this->app->make(GlobalId::class); $globalId = $encoder->encode('asdf', '123'); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: ID!) { foo( input: { @@ -233,7 +233,7 @@ public function testWithGlobalId(): void } ) } - ', [ + GRAPHQL, [ 'id' => $globalId, ]) ->assertGraphQLValidationPasses(); @@ -241,20 +241,20 @@ public function testWithGlobalId(): void public function testFieldValidatorConvention(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(email: String): ID @validator } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( email: "not an email" ) } - ') + GRAPHQL) ->assertGraphQLValidationError('email', AppVersion::atLeast(10.0) ? 'The email field must be a valid email address.' : 'The email must be a valid email address.'); @@ -262,7 +262,7 @@ public function testFieldValidatorConvention(): void public function testFieldValidatorConventionOnExtendedType(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { bar: ID } @@ -270,16 +270,16 @@ public function testFieldValidatorConventionOnExtendedType(): void extend type Query { foo(email: String): ID @validator } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( email: "not an email" ) } - ') + GRAPHQL) ->assertGraphQLValidationError('email', AppVersion::atLeast(10.0) ? 'The email field must be a valid email address.' : 'The email must be a valid email address.'); @@ -287,20 +287,20 @@ public function testFieldValidatorConventionOnExtendedType(): void public function testExplicitValidatorOnField(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { - bar(email: String): ID @validator(class: "Query\\\\FooValidator") + bar(email: String): ID @validator(class: "Query\\FooValidator") } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { bar( email: "not an email" ) } - ') + GRAPHQL) ->assertGraphQLValidationError('email', AppVersion::atLeast(10.0) ? 'The email field must be a valid email address.' : 'The email must be a valid email address.'); @@ -308,7 +308,7 @@ public function testExplicitValidatorOnField(): void public function testArgumentReferencesAreQualified(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: BarRequiredWithoutFoo): String } @@ -318,10 +318,10 @@ public function testArgumentReferencesAreQualified(): void bar: String baz: String } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: { @@ -329,17 +329,17 @@ public function testArgumentReferencesAreQualified(): void } ) } - ') + GRAPHQL) ->assertGraphQLValidationPasses(); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: {} ) } - ') + GRAPHQL) ->assertGraphQLValidationError('input.bar', 'The input.bar field is required when input.foo is not present.'); } } diff --git a/tests/Integration/ValidationCachingTest.php b/tests/Integration/ValidationCachingTest.php index 7fb0abe417..0cb2e88dff 100644 --- a/tests/Integration/ValidationCachingTest.php +++ b/tests/Integration/ValidationCachingTest.php @@ -20,11 +20,11 @@ public function testEnabled(): void $event = Event::fake(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -35,11 +35,11 @@ public function testEnabled(): void $event->assertDispatchedTimes(KeyWritten::class, 1); // second request should be hit - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -58,11 +58,11 @@ public function testDisabled(): void $event = Event::fake(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -81,11 +81,11 @@ public function testErrorsAreNotCached(): void $event = Event::fake(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { bar } - ')->assertGraphQLErrorMessage('Cannot query field "bar" on type "Query".'); + GRAPHQL)->assertGraphQLErrorMessage('Cannot query field "bar" on type "Query".'); $event->assertDispatchedTimes(CacheMissed::class, 1); $event->assertDispatchedTimes(CacheHit::class, 0); @@ -100,22 +100,22 @@ public function testDifferentQueriesHasDifferentKeys(): void $event = Event::fake(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -134,11 +134,11 @@ public function testSameSchemaAndSameQueryHaveSameKeys(): void $event = Event::fake(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -160,11 +160,11 @@ public function testSameSchemaAndSameQueryHaveSameKeys(): void $config->set('lighthouse.query_cache.enable', false); $config->set('lighthouse.validation_cache.enable', true); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -183,11 +183,11 @@ public function testDifferentSchemasHasDifferentKeys(): void $event = Event::fake(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -215,11 +215,11 @@ public function testDifferentSchemasHasDifferentKeys(): void $config->set('lighthouse.query_cache.enable', false); $config->set('lighthouse.validation_cache.enable', true); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertGraphQLErrorMessage('Cannot query field "foo" on type "Query".'); + GRAPHQL)->assertGraphQLErrorMessage('Cannot query field "foo" on type "Query".'); $event->assertDispatchedTimes(CacheMissed::class, 2); $event->assertDispatchedTimes(CacheHit::class, 0); diff --git a/tests/Integration/WhereConditions/WhereConditionsDirectiveTest.php b/tests/Integration/WhereConditions/WhereConditionsDirectiveTest.php index 38c3699af8..bfa75b35d8 100644 --- a/tests/Integration/WhereConditions/WhereConditionsDirectiveTest.php +++ b/tests/Integration/WhereConditions/WhereConditionsDirectiveTest.php @@ -17,7 +17,7 @@ final class WhereConditionsDirectiveTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String @@ -46,7 +46,7 @@ enum UserColumn { ID @enum(value: "id") NAME @enum(value: "name") } - '; + GRAPHQL; protected function getPackageProviders($app): array { @@ -68,7 +68,7 @@ public function testBetweenWithMultipleVariables(): void $user2->date_of_birth = Carbon::createStrict(1995, 1, 1); $user2->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($dobMin: Mixed, $dobMax: Mixed) { users( where: { @@ -80,7 +80,7 @@ public function testBetweenWithMultipleVariables(): void id } } - ', [ + GRAPHQL, [ 'dobMin' => '1990-01-01', 'dobMax' => '1999-01-01', ])->assertExactJson([ @@ -106,7 +106,7 @@ public function testBetweenWithOneVariable(): void $user2->date_of_birth = Carbon::createStrict(1995, 1, 1); $user2->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($dates: Mixed) { users( where: { @@ -118,7 +118,7 @@ public function testBetweenWithOneVariable(): void id } } - ', [ + GRAPHQL, [ 'dates' => ['1990-01-01', '1999-01-01'], ])->assertExactJson([ 'data' => [ @@ -143,7 +143,7 @@ public function testBetweenWithLiteralValues(): void $user2->date_of_birth = Carbon::createStrict(1995, 1, 1); $user2->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query { users( where: { @@ -155,7 +155,7 @@ public function testBetweenWithLiteralValues(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -170,7 +170,7 @@ public function testDefaultsToWhereEqual(): void { factory(User::class, 2)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -181,14 +181,14 @@ public function testDefaultsToWhereEqual(): void id } } - ')->assertJsonCount(1, 'data.users'); + GRAPHQL)->assertJsonCount(1, 'data.users'); } public function testOverwritesTheOperator(): void { factory(User::class, 3)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -200,7 +200,7 @@ public function testOverwritesTheOperator(): void id } } - ')->assertJsonCount(2, 'data.users'); + GRAPHQL)->assertJsonCount(2, 'data.users'); } public function testOperatorNotLike(): void @@ -215,7 +215,7 @@ public function testOperatorNotLike(): void $user2->name = 'bar'; $user2->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -227,7 +227,7 @@ public function testOperatorNotLike(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -242,7 +242,7 @@ public function testOperatorIn(): void { factory(User::class, 5)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -254,7 +254,7 @@ public function testOperatorIn(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -280,7 +280,7 @@ public function testOperatorIsNull(): void $postWithBody->body = 'foobar'; $postWithBody->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts( where: { @@ -291,7 +291,7 @@ public function testOperatorIsNull(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'posts' => [ [ @@ -314,7 +314,7 @@ public function testOperatorNotNull(): void $postWithBody->body = 'foobar'; $postWithBody->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts( where: { @@ -325,7 +325,7 @@ public function testOperatorNotNull(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'posts' => [ [ @@ -340,7 +340,7 @@ public function testOperatorNotBetween(): void { factory(User::class, 5)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -352,7 +352,7 @@ public function testOperatorNotBetween(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -370,7 +370,7 @@ public function testAddsNestedAnd(): void { factory(User::class, 3)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -391,14 +391,14 @@ public function testAddsNestedAnd(): void id } } - ')->assertJsonCount(1, 'data.users'); + GRAPHQL)->assertJsonCount(1, 'data.users'); } public function testAddsNestedOr(): void { factory(User::class, 5)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -426,7 +426,7 @@ public function testAddsNestedOr(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -447,7 +447,7 @@ public function testAddsNestedAndOr(): void { factory(User::class, 5)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -476,7 +476,7 @@ public function testAddsNestedAndOr(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -537,7 +537,7 @@ public function testHasMixed(): void $commentFive->comment = 'none'; $commentFive->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -566,7 +566,7 @@ public function testHasMixed(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -598,7 +598,7 @@ public function testHasRelation(): void $commentTwo->comment = 'none'; $commentTwo->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -610,7 +610,7 @@ public function testHasRelation(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -649,7 +649,7 @@ public function testHasAmount(): void $commentBatchTwo->save(); } - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -662,7 +662,7 @@ public function testHasAmount(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -698,7 +698,7 @@ public function testHasOperator(): void $commentBatchTwo->save(); } - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -712,7 +712,7 @@ public function testHasOperator(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -744,7 +744,7 @@ public function testHasCondition(): void $commentTwo->comment = 'none'; $commentTwo->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -760,7 +760,7 @@ public function testHasCondition(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -792,7 +792,7 @@ public function testHasRecursive(): void $commentTwo->comment = 'none'; $commentTwo->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -809,7 +809,7 @@ public function testHasRecursive(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -846,7 +846,7 @@ public function testHasNested(): void $task->user_id = 2; $task->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -868,7 +868,7 @@ public function testHasNested(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -881,13 +881,13 @@ public function testHasNested(): void public function testRejectsInvalidColumnName(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { AND: [ { - column: "Robert\'); DROP TABLE Students;--" + column: "Robert'); DROP TABLE Students;--" value: "https://xkcd.com/327/" } ] @@ -896,7 +896,7 @@ public function testRejectsInvalidColumnName(): void id } } - ')->assertGraphQLErrorMessage(WhereConditionsHandler::invalidColumnName("Robert'); DROP TABLE Students;--")); + GRAPHQL)->assertGraphQLErrorMessage(WhereConditionsHandler::invalidColumnName("Robert'); DROP TABLE Students;--")); } public function testQueryForNull(): void @@ -908,7 +908,7 @@ public function testQueryForNull(): void $userNamedNull->name = null; $userNamedNull->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -920,7 +920,7 @@ public function testQueryForNull(): void name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ [ @@ -934,7 +934,7 @@ public function testQueryForNull(): void public function testRequiresAValueForAColumn(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -944,7 +944,7 @@ public function testRequiresAValueForAColumn(): void id } } - ')->assertGraphQLError(SQLOperator::missingValueForColumn('no_value')); + GRAPHQL)->assertGraphQLError(SQLOperator::missingValueForColumn('no_value')); } public function testOnlyAllowsWhitelistedColumns(): void @@ -952,7 +952,7 @@ public function testOnlyAllowsWhitelistedColumns(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: Mixed!) { whitelistedColumns( where: { @@ -963,7 +963,7 @@ public function testOnlyAllowsWhitelistedColumns(): void id } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertExactJson([ 'data' => [ @@ -996,7 +996,7 @@ public function testUseColumnEnumsArg(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: Mixed!) { enumColumns( where: { @@ -1007,7 +1007,7 @@ enumColumns( id } } - ', [ + GRAPHQL, [ 'id' => $user->id, ])->assertExactJson([ 'data' => [ @@ -1025,7 +1025,7 @@ public function testIgnoreNullCondition(): void $user = factory(User::class)->create(); $this->assertInstanceOf(User::class, $user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: null @@ -1033,7 +1033,7 @@ public function testIgnoreNullCondition(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -1046,7 +1046,7 @@ public function testIgnoreNullCondition(): void public function testWhereConditionOnJSONColumn(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<make(); $this->assertInstanceOf(Location::class, $location); @@ -1065,7 +1065,7 @@ public function testWhereConditionOnJSONColumn(): void factory(Location::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { locations( where: { @@ -1076,7 +1076,7 @@ public function testWhereConditionOnJSONColumn(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'locations' => [ [ @@ -1100,7 +1100,7 @@ public function testHandler(): void handler: "{$this->qualifyTestResolver('valueTwiceHandler')}") ): [User!]! @all } -GRAPHQL; + GRAPHQL; $user1 = factory(User::class)->make(); $this->assertInstanceOf(User::class, $user1); @@ -1112,7 +1112,7 @@ public function testHandler(): void $user2->name = 'foofoo'; $user2->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( where: { @@ -1123,7 +1123,7 @@ public function testHandler(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -1150,7 +1150,7 @@ public function testWhereHasConditionsColumnDefaultsToString(): void $post2->user()->associate($user2); $post2->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { enumColumns( where: { @@ -1166,7 +1166,7 @@ enumColumns( id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'enumColumns' => [ [ @@ -1203,7 +1203,7 @@ public function testWhereHasConditionsWithNestedHas(): void $comment2->post()->associate($post2); $comment2->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { enumColumns( where: { @@ -1224,7 +1224,7 @@ enumColumns( id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'enumColumns' => [ [ @@ -1262,7 +1262,7 @@ public function testWhereHasConditionsWithAndOr(): void $post3->save(); // Find users with posts where (title = 'First' OR title = 'Second') AND body = 'Alpha' - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { enumColumns( where: { @@ -1285,7 +1285,7 @@ enumColumns( id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'enumColumns' => [ [ diff --git a/tests/Integration/WhereConditions/WhereHasConditionsDirectiveTest.php b/tests/Integration/WhereConditions/WhereHasConditionsDirectiveTest.php index ee533b0554..cb05baf354 100644 --- a/tests/Integration/WhereConditions/WhereHasConditionsDirectiveTest.php +++ b/tests/Integration/WhereConditions/WhereHasConditionsDirectiveTest.php @@ -12,7 +12,7 @@ final class WhereHasConditionsDirectiveTest extends DBTestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String @@ -78,7 +78,7 @@ final class WhereHasConditionsDirectiveTest extends DBTestCase hasChildren: _ @whereHasConditions(columns: ["id"]) ): [Location!]! @all } - '; + GRAPHQL; protected function getPackageProviders($app): array { @@ -97,7 +97,7 @@ public function testExistenceWithEmptyCondition(): void factory(User::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( hasCompany: {} @@ -105,7 +105,7 @@ public function testExistenceWithEmptyCondition(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -120,7 +120,7 @@ public function testIgnoreNullCondition(): void { factory(User::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( hasCompany: null @@ -128,7 +128,7 @@ public function testIgnoreNullCondition(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -143,7 +143,7 @@ public function testWithoutRelationName(): void { factory(User::class)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { withoutRelation( hasCompany: { @@ -154,7 +154,7 @@ public function testWithoutRelationName(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'withoutRelation' => [ [ @@ -169,7 +169,7 @@ public function testOperatorOr(): void { factory(User::class, 5)->create(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users( hasCompany: { @@ -188,7 +188,7 @@ public function testOperatorOr(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ [ @@ -214,7 +214,7 @@ public function testWhereHasBelongsToMany(): void $user->roles()->attach($role); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($id: Mixed!) { users( hasRoles: { @@ -225,7 +225,7 @@ public function testWhereHasBelongsToMany(): void id } } - ', [ + GRAPHQL, [ 'id' => $role->getKey(), ])->assertExactJson([ 'data' => [ @@ -274,7 +274,7 @@ public function testWhereHasBelongsToManyOrNestedConditions(): void $postWithCategoryWithParentWithFooPosts = factory(Post::class)->create(); $postWithCategoryWithParentWithFooPosts->categories()->attach($categoryWithParentWithFooPosts); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts( hasCategories: { @@ -290,7 +290,7 @@ public function testWhereHasBelongsToManyOrNestedConditions(): void id } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'posts' => [ [ @@ -335,7 +335,7 @@ public function testWhereHasNestedRelationWithDotNotation(): void $post5 = factory(Post::class)->create(); $post5->categories()->attach($category5); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($categoryId: Mixed!) { posts( hasCategories: { @@ -372,7 +372,7 @@ public function testWhereHasNestedRelationWithDotNotation(): void id } } - ', [ + GRAPHQL, [ 'categoryId' => $category3->getKey(), ])->assertExactJson([ 'data' => [ @@ -410,7 +410,7 @@ public function testWhereConditionsHasNestedTables(): void $post = factory(Post::class)->create(); $post->categories()->attach($category4); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($hasCategories: WhereConditions) { posts(hasCategories: $hasCategories) { id @@ -434,7 +434,7 @@ public function testWhereConditionsHasNestedTables(): void } } } - ', [ + GRAPHQL, [ 'hasCategories' => [ 'HAS' => [ 'relation' => 'parent.parent.parent', @@ -485,7 +485,7 @@ public function testWhereHasBelongsToSameTableRelationship(): void $child->parent()->associate($parent); $child->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($hasParent: QueryLocationsHasParentWhereHasConditions) { locations(hasParent: $hasParent) { id @@ -497,7 +497,7 @@ public function testWhereHasBelongsToSameTableRelationship(): void } } } - ', [ + GRAPHQL, [ 'hasParent' => [ 'column' => 'ID', 'value' => $parent->id, @@ -527,7 +527,7 @@ public function testWhereHasHasManySameTableRelationship(): void $child->parent()->associate($parent); $child->save(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($hasChildren: QueryLocationsHasChildrenWhereHasConditions) { locations(hasChildren: $hasChildren) { id @@ -539,7 +539,7 @@ public function testWhereHasHasManySameTableRelationship(): void } } } - ', [ + GRAPHQL, [ 'hasChildren' => [ 'column' => 'ID', 'value' => $child->id, diff --git a/tests/Unit/Auth/AuthDirectiveTest.php b/tests/Unit/Auth/AuthDirectiveTest.php index 2bae425dff..7b9a06c13b 100644 --- a/tests/Unit/Auth/AuthDirectiveTest.php +++ b/tests/Unit/Auth/AuthDirectiveTest.php @@ -15,7 +15,7 @@ public function testResolveAuthenticatedUser(): void $user->name = 'foo'; $this->be($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! } @@ -23,15 +23,15 @@ public function testResolveAuthenticatedUser(): void type Query { user: User! @auth } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => $user->name, @@ -48,7 +48,7 @@ public function testResolveAuthenticatedUserWithGuardsArgument(): void $authFactory = $this->app->make(AuthFactory::class); $authFactory->guard('web')->setUser($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! } @@ -56,15 +56,15 @@ public function testResolveAuthenticatedUserWithGuardsArgument(): void type Query { user: User! @auth(guards: ["web"]) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => $user->name, @@ -94,7 +94,7 @@ public function testResolveAuthenticatedUserWithMultipleGuardsArgument(): void $authFactory = $this->app->make(AuthFactory::class); $authFactory->guard('api')->setUser($user); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! } @@ -102,15 +102,15 @@ public function testResolveAuthenticatedUserWithMultipleGuardsArgument(): void type Query { user: User! @auth(guards: ["web", "api"]) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => $user->name, diff --git a/tests/Unit/Auth/CanDirectiveTest.php b/tests/Unit/Auth/CanDirectiveTest.php index 3be9f83080..47e665299e 100644 --- a/tests/Unit/Auth/CanDirectiveTest.php +++ b/tests/Unit/Auth/CanDirectiveTest.php @@ -15,7 +15,7 @@ public function testThrowsIfNotAuthorized(): void { $this->be(new User()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @can(ability: "adminOnly") @@ -25,22 +25,22 @@ public function testThrowsIfNotAuthorized(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertGraphQLErrorMessage(AuthorizationException::MESSAGE); + GRAPHQL)->assertGraphQLErrorMessage(AuthorizationException::MESSAGE); } public function testThrowsWithCustomMessageIfNotAuthorized(): void { $this->be(new User()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @can(ability: "superAdminOnly") @@ -50,16 +50,16 @@ public function testThrowsWithCustomMessageIfNotAuthorized(): void type User { name: String } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ') + GRAPHQL) ->assertGraphQLErrorMessage(UserPolicy::SUPER_ADMINS_ONLY_MESSAGE); } @@ -67,7 +67,7 @@ public function testThrowsFirstWithCustomMessageIfNotAuthorized(): void { $this->be(new User()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @can(ability: ["superAdminOnly", "adminOnly"]) @@ -77,16 +77,16 @@ public function testThrowsFirstWithCustomMessageIfNotAuthorized(): void type User { name: String } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ') + GRAPHQL) ->assertGraphQLErrorMessage(UserPolicy::SUPER_ADMINS_ONLY_MESSAGE); } @@ -98,7 +98,7 @@ public function testPassesAuthIfAuthorized(): void $this->mockResolver(fn (): User => $this->resolveUser()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @can(ability: "adminOnly") @@ -108,15 +108,15 @@ public function testPassesAuthIfAuthorized(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foo', @@ -133,7 +133,7 @@ public function testChecksAgainstResolvedModels(): void $this->mockResolver(fn (): User => $this->resolveUser()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @can(ability: "view", resolved: true) @@ -143,15 +143,15 @@ public function testChecksAgainstResolvedModels(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foo', @@ -164,7 +164,7 @@ public function testAcceptsGuestUser(): void { $this->mockResolver(fn (): User => $this->resolveUser()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @can(ability: "guestOnly") @@ -174,15 +174,15 @@ public function testAcceptsGuestUser(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foo', @@ -199,7 +199,7 @@ public function testPassesMultiplePolicies(): void $this->mockResolver(fn (): User => $this->resolveUser()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @can(ability: ["adminOnly", "alwaysTrue"]) @@ -209,15 +209,15 @@ public function testPassesMultiplePolicies(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foo', @@ -228,7 +228,7 @@ public function testPassesMultiplePolicies(): void public function testProcessesTheArgsArgument(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @can(ability: "dependingOnArg", args: [false]) @@ -238,15 +238,15 @@ public function testProcessesTheArgsArgument(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertGraphQLErrorMessage(AuthorizationException::MESSAGE); + GRAPHQL)->assertGraphQLErrorMessage(AuthorizationException::MESSAGE); } public function testInjectArgsPassesClientArgumentToPolicy(): void @@ -255,7 +255,7 @@ public function testInjectArgsPassesClientArgumentToPolicy(): void $this->mockResolver(fn (): User => $this->resolveUser()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(foo: String): User! @can(ability: "injectArgs", injectArgs: true) @@ -265,15 +265,15 @@ public function testInjectArgsPassesClientArgumentToPolicy(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(foo: "bar") { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foo', @@ -288,7 +288,7 @@ public function testChecksAgainstRootModel(): void $this->mockResolver(fn (): User => $this->resolveUser()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(foo: String): User! @mock } @@ -297,16 +297,16 @@ public function testChecksAgainstRootModel(): void name: String @can(ability: "view", root: true) email: String @can(ability: "superAdminOnly", root: true) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(foo: "bar") { name email } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foo', @@ -324,7 +324,7 @@ public function testInjectedArgsAndStaticArgs(): void $this->mockResolver(fn (): User => $this->resolveUser()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(foo: String): User! @can( @@ -338,15 +338,15 @@ public function testInjectedArgsAndStaticArgs(): void type User { name: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(foo: "dynamic") { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => 'foo', @@ -367,10 +367,10 @@ public static function resolveUser(): User public function testThrowsIfResolvedIsUsedOnMutation(): void { $this->expectExceptionObject(CanDirective::resolvedIsUnsafeInMutations('foo')); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Mutation { foo: ID @can(resolved: true) } - '); + GRAPHQL); } } diff --git a/tests/Unit/Auth/CanDirectiveTestBase.php b/tests/Unit/Auth/CanDirectiveTestBase.php index 32c954ad7d..91db49686a 100644 --- a/tests/Unit/Auth/CanDirectiveTestBase.php +++ b/tests/Unit/Auth/CanDirectiveTestBase.php @@ -14,13 +14,13 @@ abstract public static function getSchema(string $commonArgs): string; protected function getQuery(): string { - return /** @lang GraphQL */ ' + return /** @lang GraphQL */ <<<'GRAPHQL' query ($foo: String) { user(foo: $foo) { name } } - '; + GRAPHQL; } protected function query(?string $foo = null): TestResponse diff --git a/tests/Unit/Auth/CanModelDirectiveTest.php b/tests/Unit/Auth/CanModelDirectiveTest.php index fb12a9a7aa..b79f0ebbf1 100644 --- a/tests/Unit/Auth/CanModelDirectiveTest.php +++ b/tests/Unit/Auth/CanModelDirectiveTest.php @@ -6,7 +6,7 @@ final class CanModelDirectiveTest extends CanDirectiveTestBase { public static function getSchema(string $commonArgs): string { - return /** @lang GraphQL */ " + return /** @lang GraphQL */ <<mockResolver(fn (): User => $this->resolveUser()); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User! @canRoot(ability: "globalAdmin") @@ -166,7 +166,7 @@ public function testGlobalGate(): void type User { name(foo: String): String } - '; + GRAPHQL; $this->query()->assertJson([ 'data' => [ diff --git a/tests/Unit/Auth/GuardDirectiveTest.php b/tests/Unit/Auth/GuardDirectiveTest.php index 330ecce455..db31724399 100644 --- a/tests/Unit/Auth/GuardDirectiveTest.php +++ b/tests/Unit/Auth/GuardDirectiveTest.php @@ -13,32 +13,32 @@ final class GuardDirectiveTest extends TestCase { public function testGuardDefault(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @guard } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertGraphQLErrorMessage(AuthenticationException::MESSAGE); + GRAPHQL)->assertGraphQLErrorMessage(AuthenticationException::MESSAGE); } public function testGuardWith(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @guard(with: ["web"]) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'errors' => [ [ 'message' => AuthenticationException::MESSAGE, @@ -54,19 +54,19 @@ public function testGuardWith(): void public function testPassesOneFieldButThrowsInAnother(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int bar: String @guard } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo bar } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, 'bar' => null, @@ -84,7 +84,7 @@ public function testPassesOneFieldButThrowsInAnother(): void public function testGuardHappensBeforeOtherDirectivesIfAddedFromType(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query @guard { user: User! @can(ability: "adminOnly") @@ -94,16 +94,16 @@ public function testGuardHappensBeforeOtherDirectivesIfAddedFromType(): void type User { name: String } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ') + GRAPHQL) ->assertGraphQLErrorMessage(AuthenticationException::MESSAGE); } @@ -112,7 +112,7 @@ public function testGuardAppliesToFieldsOnExtendTypeOnly(): void $value = 42; $this->mockResolver($value); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { unguarded: Int! @mock } @@ -120,20 +120,20 @@ public function testGuardAppliesToFieldsOnExtendTypeOnly(): void extend type Query @guard { guarded: Int! @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { guarded } - ') + GRAPHQL) ->assertGraphQLErrorMessage(AuthenticationException::MESSAGE); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { unguarded } - ') + GRAPHQL) ->assertExactJson([ 'data' => [ 'unguarded' => $value, @@ -166,7 +166,7 @@ public function testMultiGuardWithAuthorization(): void $this->mockResolver($team); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Team { id: ID! } @@ -174,18 +174,18 @@ public function testMultiGuardWithAuthorization(): void type Query { team: Team! @guard(with: ["team"]) - @can(ability: "onlyTeams", model: "Tests\\\\Utils\\\\Models\\\\Team") + @can(ability: "onlyTeams", model: "Tests\\Utils\\Models\\Team") @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { team { id } } - ') + GRAPHQL) ->assertGraphQLErrorFree() ->assertJson([ 'data' => [ diff --git a/tests/Unit/Auth/UserContextTest.php b/tests/Unit/Auth/UserContextTest.php index 44eda831f9..439714126e 100644 --- a/tests/Unit/Auth/UserContextTest.php +++ b/tests/Unit/Auth/UserContextTest.php @@ -15,7 +15,7 @@ protected function setUp(): void { parent::setUp(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { name: String! } @@ -23,7 +23,7 @@ protected function setUp(): void type Query { user: User @mock } - '; + GRAPHQL; $this->mockResolver(static fn ($_, array $args, GraphQLContext $context): ?Authenticatable => $context->user()); } @@ -34,13 +34,13 @@ public function testResolveAuthenticatedUserUsingContext(): void $user->name = 'foo'; $this->be($user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => $user->name, @@ -51,13 +51,13 @@ public function testResolveAuthenticatedUserUsingContext(): void public function testResolveGuestUserUsingContext(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => null, ], @@ -87,13 +87,13 @@ public function testResolveAuthenticatedUserUsingContextWithMultipleGuards(): vo $authFactory = $this->app->make(AuthFactory::class); $authFactory->guard('api')->setUser($user); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'name' => $user->name, diff --git a/tests/Unit/Deprecation/DeprecationTest.php b/tests/Unit/Deprecation/DeprecationTest.php index 94a215d170..5cff22dc6a 100644 --- a/tests/Unit/Deprecation/DeprecationTest.php +++ b/tests/Unit/Deprecation/DeprecationTest.php @@ -32,17 +32,17 @@ protected function tearDown(): void public function testDetectsDeprecatedFields(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @deprecated } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -55,17 +55,17 @@ public function testDetectsDeprecatedFields(): void public function testDetectsDeprecatedFieldWithReason(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @deprecated(reason: "bar") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -78,18 +78,18 @@ public function testDetectsDeprecatedFieldWithReason(): void public function testDetectsDeprecatedFieldsMultipleTimes(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @deprecated } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo bar: foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, 'bar' => Foo::THE_ANSWER, @@ -103,7 +103,7 @@ public function testDetectsDeprecatedFieldsMultipleTimes(): void public function testDetectsDeprecatedEnumValueUsage(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' enum Foo { A B @deprecated @@ -112,13 +112,13 @@ enum Foo { type Query { foo(foo: Foo): Int } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(foo: B) } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -132,7 +132,7 @@ enum Foo { /** @return never */ public function testDetectsDeprecatedEnumValueUsageInVariables(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' enum Foo { A B @deprecated @@ -141,13 +141,13 @@ enum Foo { type Query { foo(foo: Foo): Int } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($foo: Foo!) { foo(foo: $foo) } - ', [ + GRAPHQL, [ 'foo' => 'B', ])->assertExactJson([ 'data' => [ @@ -163,7 +163,7 @@ public function testDetectsDeprecatedEnumValueUsageInResults(): void { $this->mockResolver('B'); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' enum Foo { A B @deprecated @@ -172,13 +172,13 @@ enum Foo { type Query { foo: Foo @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => 'B', ], diff --git a/tests/Unit/Events/BuildSchemaStringTest.php b/tests/Unit/Events/BuildSchemaStringTest.php index cd64d2e6ff..723bab0c01 100644 --- a/tests/Unit/Events/BuildSchemaStringTest.php +++ b/tests/Unit/Events/BuildSchemaStringTest.php @@ -27,28 +27,28 @@ public function testAddAdditionalSchemaThroughEvent(): void } "); - $this->schema = /** @lang GraphQL */ " + $this->schema = /** @lang GraphQL */ <<qualifyTestResolver('resolveFoo')}\") + foo: String @field(resolver: "{$this->qualifyTestResolver('resolveFoo')}") } - "; + GRAPHQL; - $queryForBaseSchema = /** @lang GraphQL */ ' + $queryForBaseSchema = /** @lang GraphQL */ <<<'GRAPHQL' { foo } - '; + GRAPHQL; $this->graphQL($queryForBaseSchema)->assertJson([ 'data' => [ 'foo' => 'foo', ], ]); - $queryForAdditionalSchema = /** @lang GraphQL */ ' + $queryForAdditionalSchema = /** @lang GraphQL */ <<<'GRAPHQL' { sayHello } - '; + GRAPHQL; $this->graphQL($queryForAdditionalSchema)->assertJson([ 'data' => [ 'sayHello' => 'hello', diff --git a/tests/Unit/Events/ManipulateASTTest.php b/tests/Unit/Events/ManipulateASTTest.php index 828eece792..bfd77d834c 100644 --- a/tests/Unit/Events/ManipulateASTTest.php +++ b/tests/Unit/Events/ManipulateASTTest.php @@ -11,11 +11,11 @@ final class ManipulateASTTest extends TestCase { public function testManipulateTheAST(): void { - $this->schema = ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { bar: String } - '; + GRAPHQL; Event::listen(ManipulateAST::class, static function (ManipulateAST $manipulateAST): void { $manipulateAST->documentAST->setTypeDefinition( @@ -23,11 +23,11 @@ public function testManipulateTheAST(): void ); }); - $this->graphQL(' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => 42, ], diff --git a/tests/Unit/Events/ManipulateResultTest.php b/tests/Unit/Events/ManipulateResultTest.php index 007476fffe..768dba6dc2 100644 --- a/tests/Unit/Events/ManipulateResultTest.php +++ b/tests/Unit/Events/ManipulateResultTest.php @@ -20,11 +20,11 @@ static function (ManipulateResult $manipulateResult): void { }, ); - $this->graphQL(' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER + 1, ], diff --git a/tests/Unit/Execution/Arguments/ArgumentSetFactoryTest.php b/tests/Unit/Execution/Arguments/ArgumentSetFactoryTest.php index 0b9ada21c2..bc35386fda 100644 --- a/tests/Unit/Execution/Arguments/ArgumentSetFactoryTest.php +++ b/tests/Unit/Execution/Arguments/ArgumentSetFactoryTest.php @@ -18,11 +18,11 @@ final class ArgumentSetFactoryTest extends TestCase { public function testSimpleField(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: Int): Int } - '; + GRAPHQL; $argumentSet = $this->rootQueryArgumentSet([ 'bar' => 123, @@ -36,11 +36,11 @@ public function testSimpleField(): void public function testNullableList(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: [Int!]): Int } - '; + GRAPHQL; $argumentSet = $this->rootQueryArgumentSet([ 'bar' => null, @@ -54,7 +54,7 @@ public function testNullableList(): void public function testItsListsAllTheWayDown(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: # Level 1 @@ -72,7 +72,7 @@ public function testItsListsAllTheWayDown(): void ] ): Int } - '; + GRAPHQL; // Level 1 $barValue = [ @@ -125,7 +125,7 @@ public function testItsListsAllTheWayDown(): void public function testNullableInputObject(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: Bar): Int } @@ -133,7 +133,7 @@ public function testNullableInputObject(): void input Bar { baz: ID } - '; + GRAPHQL; $argumentSet = $this->rootQueryArgumentSet([ 'bar' => null, @@ -147,11 +147,11 @@ public function testNullableInputObject(): void public function testWithUndefined(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: ID): Int } - '; + GRAPHQL; $argumentSet = $this->rootQueryArgumentSet([]); diff --git a/tests/Unit/Execution/Arguments/Fixtures/Nested.php b/tests/Unit/Execution/Arguments/Fixtures/Nested.php index 30b953334b..4a8014369a 100644 --- a/tests/Unit/Execution/Arguments/Fixtures/Nested.php +++ b/tests/Unit/Execution/Arguments/Fixtures/Nested.php @@ -11,6 +11,8 @@ public function __invoke(mixed $root, $args): void {} public static function definition(): string { - return /** @lang GraphQL */ 'directive @nested on FIELD_DEFINITION'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @nested on FIELD_DEFINITION + GRAPHQL; } } diff --git a/tests/Unit/Execution/CreatesContextTest.php b/tests/Unit/Execution/CreatesContextTest.php index fbfec4bb78..9ec193a8f9 100644 --- a/tests/Unit/Execution/CreatesContextTest.php +++ b/tests/Unit/Execution/CreatesContextTest.php @@ -30,17 +30,17 @@ public function testGenerateCustomContext(): void return $context->foo(); }); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { context: String @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { context } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'context' => FooContext::FROM_FOO_CONTEXT, ], diff --git a/tests/Unit/Federation/ExternalDirectiveTest.php b/tests/Unit/Federation/ExternalDirectiveTest.php index a421a53c59..f6cfabc22f 100644 --- a/tests/Unit/Federation/ExternalDirectiveTest.php +++ b/tests/Unit/Federation/ExternalDirectiveTest.php @@ -21,7 +21,7 @@ public function testExternalDirectiveForwardsScalars(): void $this->mockResolver($id); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Foo! @mock } @@ -29,15 +29,15 @@ public function testExternalDirectiveForwardsScalars(): void type Foo @key(fields: "id") { id: ID! @external } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => [ 'id' => $id, @@ -52,7 +52,7 @@ public function testExternalDirectiveForwardsScalarsWithinIterable(): void $two = 2; $this->mockResolver([$one, $two]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foos: [Foo!]! @mock } @@ -60,15 +60,15 @@ public function testExternalDirectiveForwardsScalarsWithinIterable(): void type Foo @key(fields: "id") { id: ID! @external } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foos { id } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foos' => [ [ @@ -90,7 +90,7 @@ public function testExternalDirectiveFallbackToDefaultFieldResolver(): void ]; $this->mockResolver($foo); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Foo! @mock } @@ -99,16 +99,16 @@ public function testExternalDirectiveFallbackToDefaultFieldResolver(): void id: ID! @external someFieldWeOwn: String! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { id someFieldWeOwn } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => $foo, ], diff --git a/tests/Unit/Federation/SchemaBuilderTest.php b/tests/Unit/Federation/SchemaBuilderTest.php index 27e41b211a..5eb3e43e80 100644 --- a/tests/Unit/Federation/SchemaBuilderTest.php +++ b/tests/Unit/Federation/SchemaBuilderTest.php @@ -20,7 +20,7 @@ protected function getPackageProviders($app): array public function testFederatedSchema(): void { - $schema = $this->buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! foo: String! @@ -29,7 +29,7 @@ public function testFederatedSchema(): void type Query { foo: Int } - '); + GRAPHQL); $this->assertTrue($schema->hasType('_Entity')); $this->assertTrue($schema->hasType('_Service')); @@ -42,12 +42,12 @@ public function testFederatedSchema(): void public function testAddsQueryTypeIfNotDefined(): void { - $schema = $this->buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! foo: String! } - '); + GRAPHQL); $this->assertSchemaHasQueryTypeWithFederationFields($schema); } diff --git a/tests/Unit/Federation/SchemaValidatorTest.php b/tests/Unit/Federation/SchemaValidatorTest.php index 7e3ad0c3e6..ef64d61069 100644 --- a/tests/Unit/Federation/SchemaValidatorTest.php +++ b/tests/Unit/Federation/SchemaValidatorTest.php @@ -21,11 +21,11 @@ protected function getPackageProviders($app): array public function testHooksIntoValidateSchemaCommand(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "not_defined_on_the_object_type") { id: ID! } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $tester = $this->commandTester(new ValidateSchemaCommand()); $this->expectException(FederationException::class); @@ -34,11 +34,11 @@ public function testHooksIntoValidateSchemaCommand(): void public function testValidatesSuccessfully(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") { id: ID! } - '); + GRAPHQL); $validator = $this->app->make(SchemaValidator::class); $validator->handle(new ValidateSchema($schema)); @@ -47,11 +47,11 @@ public function testValidatesSuccessfully(): void public function testValidatesUsesFieldNodes(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "...{ id }") { id: ID! } - '); + GRAPHQL); $validator = $this->app->make(SchemaValidator::class); $this->expectException(FederationException::class); @@ -60,11 +60,11 @@ public function testValidatesUsesFieldNodes(): void public function testValidatesMissingExternalDirective(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id") @extends { id: ID! @mock } - '); + GRAPHQL); $validator = $this->app->make(SchemaValidator::class); $this->expectException(FederationException::class); @@ -73,7 +73,7 @@ public function testValidatesMissingExternalDirective(): void public function testValidatesNestedSuccessfully(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id bar { id }") { id: ID! bar: Bar! @@ -82,7 +82,7 @@ public function testValidatesNestedSuccessfully(): void type Bar { id: ID! } - '); + GRAPHQL); $validator = $this->app->make(SchemaValidator::class); $validator->handle(new ValidateSchema($schema)); @@ -91,7 +91,7 @@ public function testValidatesNestedSuccessfully(): void public function testValidatesNestedMissingExternal(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type Foo @key(fields: "id foo { id }") @extends { id: ID! @external bar: Bar! @external @@ -100,7 +100,7 @@ public function testValidatesNestedMissingExternal(): void type Bar { id: ID! } - '); + GRAPHQL); $validator = $this->app->make(SchemaValidator::class); $this->expectException(FederationException::class); diff --git a/tests/Unit/GlobalId/GlobalIdDirectiveTest.php b/tests/Unit/GlobalId/GlobalIdDirectiveTest.php index 27f757a8f3..bc125bfabe 100644 --- a/tests/Unit/GlobalId/GlobalIdDirectiveTest.php +++ b/tests/Unit/GlobalId/GlobalIdDirectiveTest.php @@ -21,17 +21,17 @@ protected function setUp(): void public function testDecodesGlobalId(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: String! @globalId } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => $this->globalId->encode(RootType::QUERY, Foo::THE_ANSWER), ], @@ -42,27 +42,27 @@ public function testNullableArgument(): void { $this->mockResolver(static fn ($_, array $args): ?string => $args['bar'] ?? null); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: String @globalId): String @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => null, ], ]); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: null) } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => null, ], @@ -73,17 +73,17 @@ public function testNullableResult(): void { $this->mockResolver(); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: String @mock @globalId } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => null, ], @@ -94,7 +94,7 @@ public function testDecodesGlobalIdOnInput(): void { $this->mockResolver(static fn ($_, array $args): array => $args['input']['bar']); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: FooInput!): [String!]! @mock } @@ -102,18 +102,18 @@ public function testDecodesGlobalIdOnInput(): void input FooInput { bar: String! @globalId } - '; + GRAPHQL; $globalId = $this->globalId->encode('foo', 'bar'); $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($bar: String!) { foo(input: { bar: $bar }) } - ', [ + GRAPHQL, [ 'bar' => $globalId, ]) ->assertJson([ @@ -127,7 +127,7 @@ public function testDecodesGlobalIdInDifferentWays(): void { $this->mockResolver(static fn ($_, array $args): array => $args); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( type: ID! @globalId(decode: TYPE) @@ -141,23 +141,23 @@ public function testDecodesGlobalIdInDifferentWays(): void id: ID! array: [String!]! } - '; + GRAPHQL; $globalId = $this->globalId->encode('Foo', 'bar'); - $this->graphQL(/** @lang GraphQL */ " + $this->graphQL(/** @lang GraphQL */ <<assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => [ 'type' => 'Foo', diff --git a/tests/Unit/Http/Middleware/AttemptAuthenticationTest.php b/tests/Unit/Http/Middleware/AttemptAuthenticationTest.php index 6021d94e99..41aa8917cc 100644 --- a/tests/Unit/Http/Middleware/AttemptAuthenticationTest.php +++ b/tests/Unit/Http/Middleware/AttemptAuthenticationTest.php @@ -41,17 +41,17 @@ public function testAttemptsAuthenticationGuest(): void new Callback(fn (GraphQLContext $context): bool => $this->user === null), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } public function testAttemptsAuthenticationUser(): void @@ -65,16 +65,16 @@ public function testAttemptsAuthenticationUser(): void new Callback(fn (GraphQLContext $context): bool => $this->user === $context->user()), ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } } diff --git a/tests/Unit/Pagination/PaginateDirectiveTest.php b/tests/Unit/Pagination/PaginateDirectiveTest.php index cff7144f5e..9ff5a74024 100644 --- a/tests/Unit/Pagination/PaginateDirectiveTest.php +++ b/tests/Unit/Pagination/PaginateDirectiveTest.php @@ -19,7 +19,7 @@ final class PaginateDirectiveTest extends TestCase { public function testIncludesPaginatorInfoTypeInSchema(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -28,10 +28,10 @@ public function testIncludesPaginatorInfoTypeInSchema(): void extend type Query { users: [User!]! @paginate } - '); + GRAPHQL); $schemaString = SchemaPrinter::doPrint($schema); - $this->assertStringContainsString(/** @lang GraphQL */ <<<'GRAPHQL' + $this->assertStringContainsString(/** @lang GraphQL */ <<buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -72,10 +72,10 @@ public function testIncludesSimplePaginatorInfoTypeInSchema(): void extend type Query { users: [User!]! @paginate(type: SIMPLE) } - '); + GRAPHQL); $schemaString = SchemaPrinter::doPrint($schema); - $this->assertStringContainsString(/** @lang GraphQL */ <<<'GRAPHQL' + $this->assertStringContainsString(/** @lang GraphQL */ <<buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -110,10 +110,10 @@ public function testIncludesPageInfoTypeInSchema(): void extend type Query { users: [User!]! @paginate(type: CONNECTION) } - '); + GRAPHQL); $schemaString = SchemaPrinter::doPrint($schema); - $this->assertStringContainsString(/** @lang GraphQL */ <<<'GRAPHQL' + $this->assertStringContainsString(/** @lang GraphQL */ <<buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -163,7 +163,7 @@ public function testManipulatesPaginator(): void type Query { users: [User!]! @paginate } - '); + GRAPHQL); $schemaString = SchemaPrinter::doPrint($schema); $this->assertStringContainsString(/** @lang GraphQL */ <<assertStringContainsString(/** @lang GraphQL */ <<<'GRAPHQL' + $this->assertStringContainsString(/** @lang GraphQL */ <<buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -203,7 +202,7 @@ public function testManipulatesSimplePaginator(): void type Query { users: [User!]! @paginate(type: SIMPLE) } - '); + GRAPHQL); $schemaString = SchemaPrinter::doPrint($schema); $this->assertStringContainsString(/** @lang GraphQL */ <<assertStringContainsString(/** @lang GraphQL */ <<<'GRAPHQL' + $this->assertStringContainsString(/** @lang GraphQL */ <<buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -243,7 +241,7 @@ public function testManipulatesConnection(): void type Query { users: [User!]! @paginate(type: CONNECTION) } - '); + GRAPHQL); $schemaString = SchemaPrinter::doPrint($schema); $this->assertStringContainsString(/** @lang GraphQL */ <<assertStringContainsString(/** @lang GraphQL */ <<<'GRAPHQL' + $this->assertStringContainsString(/** @lang GraphQL */ <<assertStringContainsString(/** @lang GraphQL */ <<<'GRAPHQL' + $this->assertStringContainsString(/** @lang GraphQL */ <<buildSchema(/** @lang GraphQL */ " + $schema = $this->buildSchema(/** @lang GraphQL */ <<getQueryType(); $this->assertInstanceOf(ObjectType::class, $queryType); @@ -312,7 +309,7 @@ protected function getConnectionQueryField(string $type): FieldDefinition public function testOnlyRegistersOneTypeForMultiplePaginators(): void { - $schema = $this->buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type User { name: String usersPaginated: [User!]! @paginate @@ -325,7 +322,7 @@ public function testOnlyRegistersOneTypeForMultiplePaginators(): void usersConnection: [User!]! @paginate(type: CONNECTION) usersSimplePaginated: [User!]! @paginate(type: SIMPLE) } - '); + GRAPHQL); $typeMap = $schema->getTypeMap(); $this->assertArrayHasKey('UserPaginator', $typeMap); @@ -335,7 +332,7 @@ public function testOnlyRegistersOneTypeForMultiplePaginators(): void public function testRegistersPaginatorFromTypeExtensionField(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -344,7 +341,7 @@ public function testRegistersPaginatorFromTypeExtensionField(): void extend type Query { users: [User!]! @paginate } - '); + GRAPHQL); $typeMap = $schema->getTypeMap(); $this->assertArrayHasKey('UserPaginator', $typeMap); @@ -358,7 +355,7 @@ public function testHasMaxCountInGeneratedCountDescription(): void config(['lighthouse.pagination.max_count' => 5]); $queryType = $this - ->buildSchema(/** @lang GraphQL */ ' + ->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { defaultPaginated: [User!]! @paginate defaultRelay: [User!]! @paginate(type: CONNECTION) @@ -371,7 +368,7 @@ public function testHasMaxCountInGeneratedCountDescription(): void type User { id: ID! } - ') + GRAPHQL) ->getQueryType(); $this->assertInstanceOf(ObjectType::class, $queryType); @@ -416,7 +413,7 @@ public function testIsLimitedByMaxCountFromDirective(): void { config(['lighthouse.pagination.max_count' => 5]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -425,9 +422,9 @@ public function testIsLimitedByMaxCountFromDirective(): void type Query { users: [User!]! @paginate(maxCount: 6) } - '; + GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 10) { data { @@ -436,7 +433,7 @@ public function testIsLimitedByMaxCountFromDirective(): void } } } - '); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(6, 10), @@ -459,7 +456,7 @@ public function testIsLimitedByMaxCountFromDirectiveWithResolver(): void } GRAPHQL; - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 10) { data { @@ -468,7 +465,7 @@ public function testIsLimitedByMaxCountFromDirectiveWithResolver(): void } } } - '); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(6, 10), @@ -480,7 +477,7 @@ public function testIsLimitedToMaxCountFromConfig(): void { config(['lighthouse.pagination.max_count' => 5]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -491,9 +488,9 @@ public function testIsLimitedToMaxCountFromConfig(): void usersConnection: [User!]! @paginate(type: CONNECTION) usersSimplePaginated: [User!]! @paginate(type: SIMPLE) } - '; + GRAPHQL; - $resultFromDefaultPagination = $this->graphQL(/** @lang GraphQL */ ' + $resultFromDefaultPagination = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { usersPaginated(first: 10) { data { @@ -502,14 +499,14 @@ public function testIsLimitedToMaxCountFromConfig(): void } } } - '); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(5, 10), $resultFromDefaultPagination->json('errors.0.message'), ); - $resultFromRelayPagination = $this->graphQL(/** @lang GraphQL */ ' + $resultFromRelayPagination = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { usersConnection(first: 10) { edges { @@ -520,14 +517,14 @@ public function testIsLimitedToMaxCountFromConfig(): void } } } - '); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(5, 10), $resultFromRelayPagination->json('errors.0.message'), ); - $resultFromSimplePagination = $this->graphQL(/** @lang GraphQL */ ' + $resultFromSimplePagination = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { usersSimplePaginated(first: 10) { data { @@ -536,7 +533,7 @@ public function testIsLimitedToMaxCountFromConfig(): void } } } - '); + GRAPHQL); $this->assertSame( PaginationArgs::requestedTooManyItems(5, 10), @@ -548,7 +545,7 @@ public function testCountExplicitlyRequiredFromDirective(): void { config(['lighthouse.pagination.default_count' => 2]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -557,10 +554,10 @@ public function testCountExplicitlyRequiredFromDirective(): void type Query { users: [User!]! @paginate(defaultCount: null) } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users { data { @@ -568,13 +565,13 @@ public function testCountExplicitlyRequiredFromDirective(): void } } } - ') + GRAPHQL) ->assertGraphQLErrorMessage('Field "users" argument "first" of type "Int!" is required but not provided.'); } public function testThrowsWhenPaginationWithNegativeCountIsRequested(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! name: String! @@ -583,10 +580,10 @@ public function testThrowsWhenPaginationWithNegativeCountIsRequested(): void type Query { users: [User!]! @paginate } - '; + GRAPHQL; $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: -1) { data { @@ -594,21 +591,21 @@ public function testThrowsWhenPaginationWithNegativeCountIsRequested(): void } } } - ') + GRAPHQL) ->assertGraphQLErrorMessage(PaginationArgs::requestedLessThanZeroItems(-1)); } public function testDoesNotRequireModelWhenUsingBuilder(): void { - $schema = $this->buildSchema(/** @lang GraphQL */ " + $schema = $this->buildSchema(/** @lang GraphQL */ <<qualifyTestResolver('testDoesNotRequireModelWhenUsingBuilder')}\") + users: [NotAnActualModelName!]! @paginate(builder: "{$this->qualifyTestResolver('testDoesNotRequireModelWhenUsingBuilder')}") } type NotAnActualModelName { id: ID! } - "); + GRAPHQL); $paginator = $schema->getType('NotAnActualModelNamePaginator'); $this->assertInstanceOf(ObjectType::class, $paginator); @@ -618,16 +615,16 @@ public function testThrowsIfBuilderIsNotPresent(): void { $this->expectExceptionObject(new DefinitionException('Failed to find class NonexistingClass in namespaces [] for directive @paginate.')); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [Query!]! @paginate(builder: "NonexistingClass@notFound") } - '); + GRAPHQL); } public function testAllowsMultiplePaginatedFieldsOfTheSameModel(): void { - $schema = $this->buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [User!]! @paginate users2: [User!]! @paginate @@ -636,7 +633,7 @@ public function testAllowsMultiplePaginatedFieldsOfTheSameModel(): void type User { id: ID } - '); + GRAPHQL); $userPaginator = $schema->getType('UserPaginator'); $this->assertInstanceOf(ObjectType::class, $userPaginator); @@ -649,7 +646,7 @@ public function testAllowsMultiplePaginatedFieldsOfTheSameModel(): void public function testDisallowFirstNull(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -657,9 +654,9 @@ public function testDisallowFirstNull(): void type Query { users: [User!]! @paginate(defaultCount: 2) } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: null) { data { @@ -667,12 +664,12 @@ public function testDisallowFirstNull(): void } } } - ')->assertGraphQLErrorMessage('Expected value of type "Int!", found null.'); + GRAPHQL)->assertGraphQLErrorMessage('Expected value of type "Int!", found null.'); } public function testQueriesFirst0SimplePaginator(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { id: ID! } @@ -680,9 +677,9 @@ public function testQueriesFirst0SimplePaginator(): void type Query { users: [User!]! @paginate } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 0) { data { @@ -690,7 +687,7 @@ public function testQueriesFirst0SimplePaginator(): void } } } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'users' => [ 'data' => [], @@ -718,17 +715,17 @@ public static function returnPaginatedDataInsteadOfBuilder(mixed $root, array $a public function testPaginatorResolver(): void { - $this->buildSchema(/* @lang GraphQL */ " + $this->buildSchema(/** @lang GraphQL */ <<qualifyTestResolver('returnPaginatedDataInsteadOfBuilder')}\") + users: [User!]! @paginate(resolver: "{$this->qualifyTestResolver('returnPaginatedDataInsteadOfBuilder')}") } type User { id: ID } - "); + GRAPHQL); - $this->graphQL(/* @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { users(first: 5) { paginatorInfo { @@ -739,7 +736,7 @@ public function testPaginatorResolver(): void } } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'users' => [ 'paginatorInfo' => [ @@ -758,11 +755,11 @@ public function testThrowsIfResolverIsNotPresent(): void { $this->expectExceptionObject(new DefinitionException('Failed to find class NonexistingClass in namespaces [] for directive @paginate.')); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { users: [Query!]! @paginate(resolver: "NonexistingClass@notFound") } - '); + GRAPHQL); } public function testCustomizeQueryComplexityResolver(): void @@ -770,18 +767,18 @@ public function testCustomizeQueryComplexityResolver(): void $max = 42; $this->setMaxQueryComplexity($max); - $this->buildSchema(/* @lang GraphQL */ " + $this->buildSchema(/** @lang GraphQL */ <<qualifyTestResolver('complexityResolver')}\") + users(complexity: Int!): [User!]! @paginate(complexityResolver: "{$this->qualifyTestResolver('complexityResolver')}") } type User { id: ID } - "); + GRAPHQL); $complexity = 123; - $this->graphQL(/* @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' query ($complexity: Int!) { users(first: 5, complexity: $complexity) { data { @@ -789,7 +786,7 @@ public function testCustomizeQueryComplexityResolver(): void } } } - ', [ + GRAPHQL, [ 'complexity' => $complexity, ])->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, $complexity)); } diff --git a/tests/Unit/Schema/AST/ASTBuilderTest.php b/tests/Unit/Schema/AST/ASTBuilderTest.php index 3938ffa655..223eaa6851 100644 --- a/tests/Unit/Schema/AST/ASTBuilderTest.php +++ b/tests/Unit/Schema/AST/ASTBuilderTest.php @@ -31,19 +31,19 @@ protected function setUp(): void public function testMergeTypeExtensionFields(): void { - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: String - } - - extend type Query { - bar: Int! - } - - extend type Query { - baz: Boolean - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: String + } + + extend type Query { + bar: Int! + } + + extend type Query { + baz: Boolean + } + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $queryType = $documentAST->types[RootType::QUERY]; @@ -57,22 +57,24 @@ public function testMergeTypeExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo repeatable on OBJECT'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @foo repeatable on OBJECT + GRAPHQL; } }; $directiveLocator = $this->app->make(DirectiveLocator::class); $directiveLocator->setResolved('foo', $directive::class); - $this->schema = /** @lang GraphQL */ ' - type MyType { - field: String - } - - extend type MyType @foo - - extend type MyType @foo - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type MyType { + field: String + } + + extend type MyType @foo + + extend type MyType @foo + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $myType = $documentAST->types['MyType']; @@ -84,17 +86,17 @@ public static function definition(): string public function testAllowsExtendingUndefinedRootTypes(): void { $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' - extend type Query { - foo: ID - } - - extend type Mutation { - bar: ID - } - - extend type Subscription { - baz: ID - } + extend type Query { + foo: ID + } + + extend type Mutation { + bar: ID + } + + extend type Subscription { + baz: ID + } GRAPHQL; $documentAST = $this->astBuilder->documentAST(); @@ -116,19 +118,19 @@ public function testAllowsExtendingUndefinedRootTypes(): void public function testMergeInputExtensionFields(): void { - $this->schema = /** @lang GraphQL */ ' - input Inputs { - foo: String - } - - extend input Inputs { - bar: Int! - } - - extend input Inputs { - baz: Boolean - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + input Inputs { + foo: String + } + + extend input Inputs { + bar: Int! + } + + extend input Inputs { + baz: Boolean + } + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $inputs = $documentAST->types['Inputs']; @@ -142,22 +144,24 @@ public function testMergeInputExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo repeatable on INPUT_OBJECT'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @foo repeatable on INPUT_OBJECT + GRAPHQL; } }; $directiveLocator = $this->app->make(DirectiveLocator::class); $directiveLocator->setResolved('foo', $directive::class); - $this->schema = /** @lang GraphQL */ ' - input MyInput { - field: String - } - - extend input MyInput @foo - - extend input MyInput @foo - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + input MyInput { + field: String + } + + extend input MyInput @foo + + extend input MyInput @foo + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $myInput = $documentAST->types['MyInput']; @@ -168,19 +172,19 @@ public static function definition(): string public function testMergeInterfaceExtensionFields(): void { - $this->schema = /** @lang GraphQL */ ' - interface Named { - name: String! - } - - extend interface Named { - bar: Int! - } - - extend interface Named { - baz: Boolean - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + interface Named { + name: String! + } + + extend interface Named { + bar: Int! + } + + extend interface Named { + baz: Boolean + } + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $named = $documentAST->types['Named']; @@ -194,22 +198,24 @@ public function testMergeInterfaceExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo repeatable on INTERFACE'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @foo repeatable on INTERFACE + GRAPHQL; } }; $directiveLocator = $this->app->make(DirectiveLocator::class); $directiveLocator->setResolved('foo', $directive::class); - $this->schema = /** @lang GraphQL */ ' - interface MyInterface { - field: String - } - - extend interface MyInterface @foo - - extend interface MyInterface @foo - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + interface MyInterface { + field: String + } + + extend interface MyInterface @foo + + extend interface MyInterface @foo + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $myInterface = $documentAST->types['MyInterface']; @@ -223,20 +229,22 @@ public function testMergeScalarExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo repeatable on SCALAR'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @foo repeatable on SCALAR + GRAPHQL; } }; $directiveLocator = $this->app->make(DirectiveLocator::class); $directiveLocator->setResolved('foo', $directive::class); - $this->schema = /** @lang GraphQL */ ' - scalar MyScalar - - extend scalar MyScalar @foo - - extend scalar MyScalar @foo - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar MyScalar + + extend scalar MyScalar @foo + + extend scalar MyScalar @foo + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $myScalar = $documentAST->types['MyScalar']; @@ -247,20 +255,20 @@ public static function definition(): string public function testMergeEnumExtensionFields(): void { - $this->schema = /** @lang GraphQL */ ' - enum MyEnum { - ONE - TWO - } - - extend enum MyEnum { - THREE - } - - extend enum MyEnum { - FOUR - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + enum MyEnum { + ONE + TWO + } + + extend enum MyEnum { + THREE + } + + extend enum MyEnum { + FOUR + } + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $myEnum = $documentAST->types['MyEnum']; @@ -274,23 +282,25 @@ public function testMergeEnumExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo repeatable on ENUM'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @foo repeatable on ENUM + GRAPHQL; } }; $directiveLocator = $this->app->make(DirectiveLocator::class); $directiveLocator->setResolved('foo', $directive::class); - $this->schema = /** @lang GraphQL */ ' - enum MyEnum { - ONE - TWO - } - - extend enum MyEnum @foo - - extend enum MyEnum @foo - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + enum MyEnum { + ONE + TWO + } + + extend enum MyEnum @foo + + extend enum MyEnum @foo + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $myEnum = $documentAST->types['MyEnum']; @@ -301,17 +311,17 @@ enum MyEnum { public function testMergeUnionExtensionFields(): void { - $this->schema = /** @lang GraphQL */ ' - type Foo - type Bar - type Baz - - union MyUnion = Foo - - extend union MyUnion = Bar - - extend union MyUnion = Baz - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Foo + type Bar + type Baz + + union MyUnion = Foo + + extend union MyUnion = Bar + + extend union MyUnion = Baz + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $myUnion = $documentAST->types['MyUnion']; @@ -325,16 +335,18 @@ public function testDoesNotAllowExtendingUndefinedScalar(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo repeatable on SCALAR'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @foo repeatable on SCALAR + GRAPHQL; } }; $directiveLocator = $this->app->make(DirectiveLocator::class); $directiveLocator->setResolved('foo', $directive::class); - $this->schema = /** @lang GraphQL */ ' - extend scalar MyScalar @foo - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + extend scalar MyScalar @foo + GRAPHQL; $this->expectExceptionObject(new DefinitionException('Could not find a base definition MyScalar of kind ' . NodeKind::SCALAR_TYPE_EXTENSION . ' to extend.')); $this->astBuilder->documentAST(); @@ -342,15 +354,15 @@ public static function definition(): string public function testDoesNotAllowExtendingUndefinedTypes(): void { - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: String - } - - extend type Foo { - foo: Int - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: String + } + + extend type Foo { + foo: Int + } + GRAPHQL; $this->expectExceptionObject(new DefinitionException('Could not find a base definition Foo of kind ' . NodeKind::OBJECT_TYPE_EXTENSION . ' to extend.')); $this->astBuilder->documentAST(); @@ -358,11 +370,11 @@ public function testDoesNotAllowExtendingUndefinedTypes(): void public function testDoesNotAllowExtendingUndefinedUnions(): void { - $this->schema = /** @lang GraphQL */ ' - union MyFirstEnum = String - - extend union MySecondUnion = Int - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + union MyFirstEnum = String + + extend union MySecondUnion = Int + GRAPHQL; $this->expectExceptionObject(new DefinitionException('Could not find a base definition MySecondUnion of kind ' . NodeKind::UNION_TYPE_EXTENSION . ' to extend.')); $this->astBuilder->documentAST(); @@ -370,15 +382,15 @@ public function testDoesNotAllowExtendingUndefinedUnions(): void public function testDoesNotAllowDuplicateFieldsOnTypeExtensions(): void { - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: String - } - - extend type Query { - foo: Int - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: String + } + + extend type Query { + foo: Int + } + GRAPHQL; $this->expectExceptionObject(new DefinitionException(ASTHelper::duplicateDefinition('foo'))); $this->astBuilder->documentAST(); @@ -386,15 +398,15 @@ public function testDoesNotAllowDuplicateFieldsOnTypeExtensions(): void public function testDoesNotAllowDuplicateFieldsOnInputExtensions(): void { - $this->schema = /** @lang GraphQL */ ' - input Inputs { - foo: String - } - - extend input Inputs { - foo: Int - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + input Inputs { + foo: String + } + + extend input Inputs { + foo: Int + } + GRAPHQL; $this->expectExceptionObject(new DefinitionException(ASTHelper::duplicateDefinition('foo'))); $this->astBuilder->documentAST(); @@ -402,15 +414,15 @@ public function testDoesNotAllowDuplicateFieldsOnInputExtensions(): void public function testDoesNotAllowDuplicateFieldsOnInterfaceExtensions(): void { - $this->schema = /** @lang GraphQL */ ' - interface Named { - foo: String - } - - extend interface Named{ - foo: Int - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + interface Named { + foo: String + } + + extend interface Named{ + foo: Int + } + GRAPHQL; $this->expectExceptionObject(new DefinitionException(ASTHelper::duplicateDefinition('foo'))); $this->astBuilder->documentAST(); @@ -418,17 +430,17 @@ interface Named { public function testDoesNotAllowDuplicateValuesOnEnumExtensions(): void { - $this->schema = /** @lang GraphQL */ ' - enum MyEnum { - ONE - TWO - } - - extend enum MyEnum { - TWO - THREE - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + enum MyEnum { + ONE + TWO + } + + extend enum MyEnum { + TWO + THREE + } + GRAPHQL; $this->expectExceptionObject(new DefinitionException(ASTHelper::duplicateDefinition('TWO'))); $this->astBuilder->documentAST(); @@ -436,14 +448,14 @@ enum MyEnum { public function testDoesNotAllowDuplicateTypesOnUnionExtensions(): void { - $this->schema = /** @lang GraphQL */ ' - type Foo - type Bar - - union MyUnion = Foo | Bar - - extend union MyUnion = Bar - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Foo + type Bar + + union MyUnion = Foo | Bar + + extend union MyUnion = Bar + GRAPHQL; $this->expectExceptionObject(new DefinitionException(ASTHelper::duplicateDefinition('Bar'))); $this->astBuilder->documentAST(); @@ -451,15 +463,15 @@ public function testDoesNotAllowDuplicateTypesOnUnionExtensions(): void public function testDoesNotAllowMergingNonMatchingTypes(): void { - $this->schema = /** @lang GraphQL */ ' - type Foo { - bar: ID - } - - extend interface Foo { - baz: ID - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Foo { + bar: ID + } + + extend interface Foo { + baz: ID + } + GRAPHQL; $this->expectExceptionObject(new DefinitionException('The type extension Foo of kind ' . NodeKind::INTERFACE_TYPE_EXTENSION . ' can not extend a definition of kind ' . NodeKind::OBJECT_TYPE_DEFINITION . '.')); $this->astBuilder->documentAST(); @@ -467,23 +479,23 @@ public function testDoesNotAllowMergingNonMatchingTypes(): void public function testMergeTypeExtensionInterfaces(): void { - $this->schema = /** @lang GraphQL */ ' - type User implements Emailable { - email: String! - } - - interface Emailable { - email: String! - } - - interface Nameable { - name: String! - } - - extend type User implements Nameable { - name: String! - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type User implements Emailable { + email: String! + } + + interface Emailable { + email: String! + } + + interface Nameable { + name: String! + } + + extend type User implements Nameable { + name: String! + } + GRAPHQL; $documentAST = $this->astBuilder->documentAST(); $userType = $documentAST->types['User']; diff --git a/tests/Unit/Schema/AST/ASTHelperTest.php b/tests/Unit/Schema/AST/ASTHelperTest.php index f55cdd15a1..2498e75140 100644 --- a/tests/Unit/Schema/AST/ASTHelperTest.php +++ b/tests/Unit/Schema/AST/ASTHelperTest.php @@ -27,17 +27,17 @@ final class ASTHelperTest extends TestCase { public function testThrowsWhenMergingUniqueNodeListWithCollision(): void { - $objectType1 = Parser::objectTypeDefinition(/** @lang GraphQL */ ' - type User { - email: String - } - '); - - $objectType2 = Parser::objectTypeDefinition(/** @lang GraphQL */ ' - type User { - email(bar: String): Int - } - '); + $objectType1 = Parser::objectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + type User { + email: String + } + GRAPHQL); + + $objectType2 = Parser::objectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + type User { + email(bar: String): Int + } + GRAPHQL); $this->expectException(DefinitionException::class); ASTHelper::mergeUniqueNodeList( @@ -48,19 +48,19 @@ public function testThrowsWhenMergingUniqueNodeListWithCollision(): void public function testMergesUniqueNodeListsWithOverwrite(): void { - $objectType1 = Parser::objectTypeDefinition(/** @lang GraphQL */ ' - type User { - first_name: String - email: String - } - '); - - $objectType2 = Parser::objectTypeDefinition(/** @lang GraphQL */ ' - type User { - first_name: String @foo - last_name: String - } - '); + $objectType1 = Parser::objectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + type User { + first_name: String + email: String + } + GRAPHQL); + + $objectType2 = Parser::objectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + type User { + first_name: String @foo + last_name: String + } + GRAPHQL); $objectType1->fields = ASTHelper::mergeUniqueNodeList( $objectType1->fields, @@ -78,7 +78,9 @@ public function testMergesUniqueNodeListsWithOverwrite(): void public function testExtractStringArguments(): void { - $directive = Parser::constDirective(/** @lang GraphQL */ '@foo(bar: "baz")'); + $directive = Parser::constDirective(/** @lang GraphQL */ <<<'GRAPHQL' + @foo(bar: "baz") + GRAPHQL); $this->assertSame( 'baz', ASTHelper::directiveArgValue($directive, 'bar'), @@ -87,7 +89,9 @@ public function testExtractStringArguments(): void public function testExtractBooleanArguments(): void { - $directive = Parser::constDirective(/** @lang GraphQL */ '@foo(bar: true)'); + $directive = Parser::constDirective(/** @lang GraphQL */ <<<'GRAPHQL' + @foo(bar: true) + GRAPHQL); $this->assertTrue( ASTHelper::directiveArgValue($directive, 'bar'), ); @@ -95,7 +99,9 @@ public function testExtractBooleanArguments(): void public function testExtractArrayArguments(): void { - $directive = Parser::constDirective(/** @lang GraphQL */ '@foo(bar: ["one", "two"])'); + $directive = Parser::constDirective(/** @lang GraphQL */ <<<'GRAPHQL' + @foo(bar: ["one", "two"]) + GRAPHQL); $this->assertSame( ['one', 'two'], ASTHelper::directiveArgValue($directive, 'bar'), @@ -104,7 +110,9 @@ public function testExtractArrayArguments(): void public function testExtractObjectArguments(): void { - $directive = Parser::constDirective(/** @lang GraphQL */ '@foo(bar: { baz: "foobar" })'); + $directive = Parser::constDirective(/** @lang GraphQL */ <<<'GRAPHQL' + @foo(bar: { baz: "foobar" }) + GRAPHQL); $this->assertSame( ['baz' => 'foobar'], ASTHelper::directiveArgValue($directive, 'bar'), @@ -113,7 +121,9 @@ public function testExtractObjectArguments(): void public function testReturnsNullForNonExistingArgumentOnDirective(): void { - $directive = Parser::constDirective(/** @lang GraphQL */ '@foo'); + $directive = Parser::constDirective(/** @lang GraphQL */ <<<'GRAPHQL' + @foo + GRAPHQL); $this->assertNull( ASTHelper::directiveArgValue($directive, 'bar'), ); @@ -121,25 +131,27 @@ public function testReturnsNullForNonExistingArgumentOnDirective(): void public function testChecksWhetherTypeImplementsInterface(): void { - $type = Parser::objectTypeDefinition(/** @lang GraphQL */ ' - type Foo implements Bar { - baz: String - } - '); + $type = Parser::objectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + type Foo implements Bar { + baz: String + } + GRAPHQL); $this->assertTrue(ASTHelper::typeImplementsInterface($type, 'Bar')); $this->assertFalse(ASTHelper::typeImplementsInterface($type, 'FakeInterface')); } public function testAddDirectiveToFields(): void { - $object = Parser::objectTypeDefinition(/** @lang GraphQL */ ' - type Query { - foo: Int - } - '); + $object = Parser::objectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: Int + } + GRAPHQL); ASTHelper::addDirectiveToFields( - Parser::constDirective(/** @lang GraphQL */ '@guard'), + Parser::constDirective(/** @lang GraphQL */ <<<'GRAPHQL' + @guard + GRAPHQL), $object, ); @@ -151,15 +163,17 @@ public function testAddDirectiveToFields(): void public function testPrefersFieldDirectivesOverTypeDirectives(): void { - $object = Parser::objectTypeDefinition(/** @lang GraphQL */ ' - type Query { - foo: Int @complexity(resolver: "Foo") - bar: String - } - '); + $object = Parser::objectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: Int @complexity(resolver: "Foo") + bar: String + } + GRAPHQL); ASTHelper::addDirectiveToFields( - Parser::constDirective(/** @lang GraphQL */ '@complexity'), + Parser::constDirective(/** @lang GraphQL */ <<<'GRAPHQL' + @complexity + GRAPHQL), $object, ); @@ -172,15 +186,17 @@ public function testPrefersFieldDirectivesOverTypeDirectives(): void public function testExtractDirectiveDefinition(): void { - $directive = ASTHelper::extractDirectiveDefinition(/** @lang GraphQL */ 'directive @foo on OBJECT'); + $directive = ASTHelper::extractDirectiveDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + directive @foo on OBJECT + GRAPHQL); $this->assertSame('foo', $directive->name->value); } public function testExtractDirectiveDefinitionAllowsAuxiliaryTypes(): void { $directive = ASTHelper::extractDirectiveDefinition(/** @lang GraphQL */ <<<'GRAPHQL' - directive @foo on OBJECT - scalar Bar + directive @foo on OBJECT + scalar Bar GRAPHQL); $this->assertSame('foo', $directive->name->value); } @@ -189,7 +205,7 @@ public function testThrowsOnSyntaxError(): void { $this->expectException(DefinitionException::class); ASTHelper::extractDirectiveDefinition(/** @lang GraphQL */ <<<'GRAPHQL' - invalid GraphQL + invalid GraphQL GRAPHQL); } @@ -197,7 +213,7 @@ public function testThrowsIfMissingDirectiveDefinitions(): void { $this->expectException(DefinitionException::class); ASTHelper::extractDirectiveDefinition(/** @lang GraphQL */ <<<'GRAPHQL' - scalar Foo + scalar Foo GRAPHQL); } @@ -205,8 +221,8 @@ public function testThrowsOnMultipleDirectiveDefinitions(): void { $this->expectException(DefinitionException::class); ASTHelper::extractDirectiveDefinition(/** @lang GraphQL */ <<<'GRAPHQL' - directive @foo on OBJECT - directive @bar on OBJECT + directive @foo on OBJECT + directive @bar on OBJECT GRAPHQL); } @@ -243,7 +259,9 @@ public function testDynamicallyAddedFieldManipulatorDirective(): void $directive = new class() extends BaseDirective implements FieldManipulator { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo on FIELD_DEFINITION'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @foo on FIELD_DEFINITION + GRAPHQL; } public function manipulateFieldDefinition( @@ -261,7 +279,9 @@ public function manipulateFieldDefinition( $dynamicDirective = new class() extends BaseDirective implements FieldManipulator { public static function definition(): string { - return /** @lang GraphQL */ 'directive @dynamic on FIELD_DEFINITION'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @dynamic on FIELD_DEFINITION + GRAPHQL; } public function manipulateFieldDefinition( @@ -278,11 +298,11 @@ public function manipulateFieldDefinition( $directiveLocator->setResolved('dynamic', $dynamicDirective::class); - $this->schema = /** @lang GraphQL */ ' - type Query { - foo: String @dynamic - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo: String @dynamic + } + GRAPHQL; $documentAST = $astBuilder->documentAST(); $queryType = $documentAST->types[RootType::QUERY]; @@ -302,7 +322,9 @@ public function testDynamicallyAddedArgManipulatorDirective(): void $directive = new class() extends BaseDirective implements ArgManipulator { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo on ARGUMENT_DEFINITION'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @foo on ARGUMENT_DEFINITION + GRAPHQL; } public function manipulateArgDefinition( @@ -321,7 +343,9 @@ public function manipulateArgDefinition( $dynamicDirective = new class() extends BaseDirective implements ArgManipulator { public static function definition(): string { - return /** @lang GraphQL */ 'directive @dynamic on ARGUMENT_DEFINITION'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @dynamic on ARGUMENT_DEFINITION + GRAPHQL; } public function manipulateArgDefinition( @@ -339,11 +363,11 @@ public function manipulateArgDefinition( $directiveLocator->setResolved('dynamic', $dynamicDirective::class); - $this->schema = /** @lang GraphQL */ ' - type Query { - foo(name: String @dynamic): String - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query { + foo(name: String @dynamic): String + } + GRAPHQL; $astBuilder = $this->app->make(ASTBuilder::class); $documentAST = $astBuilder->documentAST(); @@ -367,7 +391,9 @@ public function testDynamicallyAddedInputFieldManipulatorDirective(): void $directive = new class() extends BaseDirective implements InputFieldManipulator { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo on INPUT_FIELD_DEFINITION'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @foo on INPUT_FIELD_DEFINITION + GRAPHQL; } public function manipulateInputFieldDefinition( @@ -385,7 +411,9 @@ public function manipulateInputFieldDefinition( $dynamicDirective = new class() extends BaseDirective implements InputFieldManipulator { public static function definition(): string { - return /** @lang GraphQL */ 'directive @dynamic on INPUT_FIELD_DEFINITION'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @dynamic on INPUT_FIELD_DEFINITION + GRAPHQL; } public function manipulateInputFieldDefinition( @@ -402,15 +430,15 @@ public function manipulateInputFieldDefinition( $directiveLocator->setResolved('dynamic', $dynamicDirective::class); - $this->schema = /** @lang GraphQL */ ' - input Input { - name: String @dynamic - } - - type Query { - foo(name: Input): String - } - '; + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + input Input { + name: String @dynamic + } + + type Query { + foo(name: Input): String + } + GRAPHQL; $astBuilder = $this->app->make(ASTBuilder::class); $documentAST = $astBuilder->documentAST(); diff --git a/tests/Unit/Schema/AST/DocumentASTTest.php b/tests/Unit/Schema/AST/DocumentASTTest.php index f5ea2b6428..fd6ad27008 100644 --- a/tests/Unit/Schema/AST/DocumentASTTest.php +++ b/tests/Unit/Schema/AST/DocumentASTTest.php @@ -15,13 +15,13 @@ final class DocumentASTTest extends TestCase { public function testParsesSimpleSchema(): void { - $schema = /** @lang GraphQL */ ' + $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int } - '; + GRAPHQL; // calculated as hash('sha256', $schema) - $schemaHash = '99fd7bd3f58a98d8932c1f5d1da718707f6f471e93d96e0bc913436445a947ac'; + $schemaHash = '774433c158904b98b4f69eddee3424679b99a70736960a189b7d7b5923695bac'; $documentAST = DocumentAST::fromSource($schema); $this->assertInstanceOf( @@ -37,7 +37,7 @@ public function testThrowsOnInvalidSchema(): void $this->expectException(SchemaSyntaxErrorException::class); $this->expectExceptionMessage('Syntax Error: Expected Name, found !, near: '); - DocumentAST::fromSource(/** @lang GraphQL */ ' + DocumentAST::fromSource(/** @lang GraphQL */ <<<'GRAPHQL' type Mutation { bar: Int } @@ -49,7 +49,7 @@ public function testThrowsOnInvalidSchema(): void type Foo { bar: ID } - '); + GRAPHQL); } public function testThrowsOnUnknownModelClasses(): void @@ -57,26 +57,26 @@ public function testThrowsOnUnknownModelClasses(): void $this->expectException(DefinitionException::class); $this->expectExceptionMessage('Failed to find a model class Unknown in namespaces [Tests\Utils\Models, Tests\Utils\ModelsSecondary] referenced in @model on type Query.'); - DocumentAST::fromSource(/** @lang GraphQL */ ' + DocumentAST::fromSource(/** @lang GraphQL */ <<<'GRAPHQL' type Query @model(class: "Unknown") { foo: Int! } - '); + GRAPHQL); } public function testOverwritesDefinitionWithSameName(): void { - $documentAST = DocumentAST::fromSource(/** @lang GraphQL */ ' + $documentAST = DocumentAST::fromSource(/** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int } - '); + GRAPHQL); - $overwrite = Parser::objectTypeDefinition(/** @lang GraphQL */ ' + $overwrite = Parser::objectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' type Query { bar: Int } - '); + GRAPHQL); $documentAST->types[$overwrite->name->value] = $overwrite; @@ -88,7 +88,7 @@ public function testOverwritesDefinitionWithSameName(): void public function testBeSerialized(): void { - $documentAST = DocumentAST::fromSource(/** @lang GraphQL */ ' + $documentAST = DocumentAST::fromSource(/** @lang GraphQL */ <<<'GRAPHQL' extend schema @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key"]) type Query @model(class: "User") { @@ -96,7 +96,7 @@ public function testBeSerialized(): void } directive @foo on FIELD - '); + GRAPHQL); $reserialized = unserialize( serialize($documentAST), diff --git a/tests/Unit/Schema/DirectiveLocatorTest.php b/tests/Unit/Schema/DirectiveLocatorTest.php index ec8ab319ac..48ac7781bc 100644 --- a/tests/Unit/Schema/DirectiveLocatorTest.php +++ b/tests/Unit/Schema/DirectiveLocatorTest.php @@ -34,9 +34,9 @@ public function testRegistersLighthouseDirectives(): void public function testHydratesBaseDirectives(): void { - $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ ' - foo: String @field - '); + $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + foo: String @field + GRAPHQL); $fieldDirective = $this ->directiveLocator @@ -52,14 +52,16 @@ public function testHydratesBaseDirectives(): void public function testSkipsHydrationForNonBaseDirectives(): void { - $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ ' - foo: String @foo - '); + $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + foo: String @foo + GRAPHQL); $directive = new class() implements FieldMiddleware { public static function definition(): string { - return /** @lang GraphQL */ 'foo'; + return /** @lang GraphQL */ <<<'GRAPHQL' + foo + GRAPHQL; } public function handleField(FieldValue $fieldValue): void {} @@ -84,9 +86,9 @@ public function testThrowsIfDirectiveNameCanNotBeResolved(): void public function testCreateSingleDirective(): void { - $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ ' - foo: [Foo!]! @hasMany - '); + $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + foo: [Foo!]! @hasMany + GRAPHQL); $resolver = $this->directiveLocator->exclusiveOfType($fieldDefinition, FieldResolver::class); $this->assertInstanceOf(FieldResolver::class, $resolver); @@ -97,18 +99,18 @@ public function testThrowsExceptionWhenMultipleFieldResolverDirectives(): void $this->expectException(DirectiveException::class); $this->expectExceptionMessage("Node bar can only have one directive of type Nuwave\Lighthouse\Support\Contracts\FieldResolver but found [@hasMany, @belongsTo]."); - $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ ' - bar: [Bar!]! @hasMany @belongsTo - '); + $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + bar: [Bar!]! @hasMany @belongsTo + GRAPHQL); $this->directiveLocator->exclusiveOfType($fieldDefinition, FieldResolver::class); } public function testCreateMultipleDirectives(): void { - $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ ' - bar: String @can(if: ["viewBar"]) @event - '); + $fieldDefinition = Parser::fieldDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + bar: String @can(if: ["viewBar"]) @event + GRAPHQL); $middleware = $this->directiveLocator->associatedOfType($fieldDefinition, FieldMiddleware::class); $this->assertCount(2, $middleware); diff --git a/tests/Unit/Schema/Directives/BaseDirectiveTest.php b/tests/Unit/Schema/Directives/BaseDirectiveTest.php index be62be460e..c3f3ed3037 100644 --- a/tests/Unit/Schema/Directives/BaseDirectiveTest.php +++ b/tests/Unit/Schema/Directives/BaseDirectiveTest.php @@ -25,11 +25,11 @@ final class BaseDirectiveTest extends TestCase { public function testGetsModelClassFromDirective(): void { - $this->schema .= /** @lang GraphQL */ ' - type User @model(class: "Team") { - id: ID - } - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type User @model(class: "Team") { + id: ID + } + GRAPHQL; $directive = $this->constructFieldDirective('foo: User @dummy'); @@ -41,11 +41,11 @@ public function testGetsModelClassFromDirective(): void public function testDefaultsToFieldTypeForTheModelClassIfObject(): void { - $this->schema .= /** @lang GraphQL */ ' - type User { - id: ID - } - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type User { + id: ID + } + GRAPHQL; $directive = $this->constructFieldDirective('foo: User @dummy'); @@ -57,11 +57,11 @@ public function testDefaultsToFieldTypeForTheModelClassIfObject(): void public function testDefaultsToFieldTypeForTheModelClassIfInterface(): void { - $this->schema .= /** @lang GraphQL */ ' - interface User { - id: ID - } - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + interface User { + id: ID + } + GRAPHQL; $directive = $this->constructFieldDirective('foo: User @dummy'); @@ -73,17 +73,17 @@ interface User { public function testDefaultsToFieldTypeForTheModelClassIfUnion(): void { - $this->schema .= /** @lang GraphQL */ ' - union User = Admin | Member - - type Admin { - id: ID - } - - type Member { - id: ID - } - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + union User = Admin | Member + + type Admin { + id: ID + } + + type Member { + id: ID + } + GRAPHQL; $directive = $this->constructFieldDirective('foo: User @dummy'); @@ -95,9 +95,9 @@ public function testDefaultsToFieldTypeForTheModelClassIfUnion(): void public function testDoesntDefaultToFieldTypeForTheModelClassIfScalar(): void { - $this->schema .= /** @lang GraphQL */ ' - scalar User - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + scalar User + GRAPHQL; $directive = $this->constructFieldDirective('foo: User @dummy'); @@ -125,11 +125,11 @@ public function testBuiltInTypeTolerated(): void public function testThrowsIfTheClassIsNotAModel(): void { - $this->schema .= /** @lang GraphQL */ ' - type Exception { - id: ID - } - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type Exception { + id: ID + } + GRAPHQL; $directive = $this->constructFieldDirective('foo: Exception @dummy'); @@ -139,11 +139,11 @@ public function testThrowsIfTheClassIsNotAModel(): void public function testResolvesAModelThatIsNamedLikeABaseClass(): void { - $this->schema .= /** @lang GraphQL */ ' - type Closure { - id: ID - } - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type Closure { + id: ID + } + GRAPHQL; $directive = $this->constructFieldDirective('foo: Closure @dummy'); @@ -155,11 +155,11 @@ public function testResolvesAModelThatIsNamedLikeABaseClass(): void public function testPrefersThePrimaryModelNamespace(): void { - $this->schema .= /** @lang GraphQL */ ' - type Category { - id: ID - } - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type Category { + id: ID + } + GRAPHQL; $directive = $this->constructFieldDirective('foo: Category @dummy'); @@ -171,11 +171,11 @@ public function testPrefersThePrimaryModelNamespace(): void public function testAllowsOverwritingTheDefaultModel(): void { - $this->schema .= /** @lang GraphQL */ ' - type OnlyHere { - id: ID - } - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type OnlyHere { + id: ID + } + GRAPHQL; $directive = $this->constructFieldDirective('foo: OnlyHere @dummy(model: "Tests\\\Utils\\\ModelsSecondary\\\Category")'); @@ -187,11 +187,11 @@ public function testAllowsOverwritingTheDefaultModel(): void public function testResolvesFromTheSecondaryModelNamespace(): void { - $this->schema .= /** @lang GraphQL */ ' - type OnlyHere { - id: ID - } - '; + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' + type OnlyHere { + id: ID + } + GRAPHQL; $directive = $this->constructFieldDirective('foo: OnlyHere @dummy'); @@ -269,7 +269,9 @@ private function constructFieldDirective(string $definition): BaseDirective $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @base on FIELD_DEFINITION'; + return /** @lang GraphQL */ <<<'GRAPHQL' + directive @base on FIELD_DEFINITION + GRAPHQL; } /** diff --git a/tests/Unit/Schema/Directives/ComplexityDirectiveTest.php b/tests/Unit/Schema/Directives/ComplexityDirectiveTest.php index bbae0966d0..182510ec26 100644 --- a/tests/Unit/Schema/Directives/ComplexityDirectiveTest.php +++ b/tests/Unit/Schema/Directives/ComplexityDirectiveTest.php @@ -26,7 +26,7 @@ public function testDefaultComplexity(): void $max = 1; $this->setMaxQueryComplexity($max); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { posts: [Post!]! @all } @@ -34,15 +34,15 @@ public function testDefaultComplexity(): void type Post { title: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts { title } } - ')->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, 2)); + GRAPHQL)->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, 2)); $this->assertCount(1, $events); @@ -58,7 +58,7 @@ public function testKnowsPagination(): void $max = 1; $this->setMaxQueryComplexity($max); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { posts: [Post!]! @paginate } @@ -66,12 +66,12 @@ public function testKnowsPagination(): void type Post { title: String } - '; + GRAPHQL; // 1 + (2 for data & title * 10 first items) $expectedCount = 21; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts(first: 10) { data { @@ -79,7 +79,7 @@ public function testKnowsPagination(): void } } } - ')->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, $expectedCount)); + GRAPHQL)->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, $expectedCount)); } public function testIgnoresFirstArgumentUnrelatedToPagination(): void @@ -87,7 +87,7 @@ public function testIgnoresFirstArgumentUnrelatedToPagination(): void $max = 1; $this->setMaxQueryComplexity($max); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { posts(first: String!): [Post!]! @all } @@ -95,15 +95,15 @@ public function testIgnoresFirstArgumentUnrelatedToPagination(): void type Post { title: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { posts(first: "named like the generated argument of @paginate, but should not increase complexity here") { title } } - ')->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, 2)); + GRAPHQL)->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, 2)); } public function testCustomComplexityResolver(): void @@ -117,11 +117,11 @@ public function testCustomComplexityResolver(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, self::CUSTOM_COMPLEXITY)); + GRAPHQL)->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, self::CUSTOM_COMPLEXITY)); } public function testResolvesComplexityResolverThroughDefaultNamespace(): void @@ -135,11 +135,11 @@ public function testResolvesComplexityResolverThroughDefaultNamespace(): void } GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, Foo::THE_ANSWER)); + GRAPHQL)->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, Foo::THE_ANSWER)); } public static function complexity(): int diff --git a/tests/Unit/Schema/Directives/DeprecatedDirectiveTest.php b/tests/Unit/Schema/Directives/DeprecatedDirectiveTest.php index afb6c58884..a99ff5f838 100644 --- a/tests/Unit/Schema/Directives/DeprecatedDirectiveTest.php +++ b/tests/Unit/Schema/Directives/DeprecatedDirectiveTest.php @@ -11,10 +11,10 @@ final class DeprecatedDirectiveTest extends TestCase public function testRemoveDeprecatedFieldsFromIntrospection(): void { $reason = 'Use `bar` field'; - $this->schema = /** @lang GraphQL */ " + $this->schema = /** @lang GraphQL */ <<graphQL( $introspectionQuery, [ diff --git a/tests/Unit/Schema/Directives/DropDirectiveTest.php b/tests/Unit/Schema/Directives/DropDirectiveTest.php index 820d90117a..85cd2b5b57 100644 --- a/tests/Unit/Schema/Directives/DropDirectiveTest.php +++ b/tests/Unit/Schema/Directives/DropDirectiveTest.php @@ -16,20 +16,20 @@ public function testDropArgument(): void ], ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( baz: String @drop bar: String ): Boolean @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(baz: "something", bar: "something") } - '); + GRAPHQL); } public function testDropListOfInputs(): void @@ -44,7 +44,7 @@ public function testDropListOfInputs(): void ], ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( input: [FooInput] @@ -55,9 +55,9 @@ public function testDropListOfInputs(): void baz: String @drop bar: String } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: [ @@ -68,6 +68,6 @@ public function testDropListOfInputs(): void ] ) } - '); + GRAPHQL); } } diff --git a/tests/Unit/Schema/Directives/FieldDirectiveTest.php b/tests/Unit/Schema/Directives/FieldDirectiveTest.php index 882faba248..5e3a57c667 100644 --- a/tests/Unit/Schema/Directives/FieldDirectiveTest.php +++ b/tests/Unit/Schema/Directives/FieldDirectiveTest.php @@ -11,17 +11,17 @@ final class FieldDirectiveTest extends TestCase { public function testAssignsResolverFromCombinedDefinition(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { - bar: String! @field(resolver:"Tests\\\Utils\\\Resolvers\\\Foo@bar") + bar: String! @field(resolver:"Tests\\Utils\\Resolvers\\Foo@bar") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { bar } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'bar' => 'foo.bar', ], @@ -30,17 +30,17 @@ public function testAssignsResolverFromCombinedDefinition(): void public function testAssignsResolverWithInvokableClass(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { - baz: String! @field(resolver:"Tests\\\Utils\\\Resolvers\\\Foo") + baz: String! @field(resolver:"Tests\\Utils\\Resolvers\\Foo") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { baz } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'baz' => 'foo.baz', ], @@ -49,17 +49,17 @@ public function testAssignsResolverWithInvokableClass(): void public function testUsesDefaultFieldNamespace(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { baz: String! @field(resolver: "FooBar") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { baz } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'baz' => FooBar::INVOKE_RESULT, ], @@ -70,7 +70,7 @@ public function testUsesNonRootParentNamespace(): void { $this->mockResolver([]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User @mock } @@ -78,15 +78,15 @@ public function testUsesNonRootParentNamespace(): void type User { foo: String! @field(resolver: "NonRootClassResolver") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { foo } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'user' => [ 'foo' => NonRootClassResolver::RESULT, @@ -97,17 +97,17 @@ public function testUsesNonRootParentNamespace(): void public function testUsesDefaultFieldNamespaceWithCustomMethodName(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { bar: String! @field(resolver: "FooBar@customResolve") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { bar } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'bar' => FooBar::CUSTOM_RESOLVE_RESULT, ], @@ -116,35 +116,35 @@ public function testUsesDefaultFieldNamespaceWithCustomMethodName(): void public function testThrowsAnErrorWhenNoClassFound(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: String! @field(resolver: "NonExisting") } - '; + GRAPHQL; $this->expectException(DefinitionException::class); $this->expectExceptionMessage('Failed to find class NonExisting in namespaces [Tests\Utils\Queries, Tests\Utils\QueriesSecondary] for directive @field.'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } public function testThrowsAnErrorWhenClassIsNotInvokable(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { bar: String! @field(resolver: "MissingInvoke") } - '; + GRAPHQL; $this->expectException(DefinitionException::class); $this->expectExceptionMessage("Method '__invoke' does not exist on class 'Tests\Utils\Queries\MissingInvoke'."); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { bar } - '); + GRAPHQL); } } diff --git a/tests/Unit/Schema/Directives/HasManyDirectiveTest.php b/tests/Unit/Schema/Directives/HasManyDirectiveTest.php index 6688eae8b4..1a6bfbc108 100644 --- a/tests/Unit/Schema/Directives/HasManyDirectiveTest.php +++ b/tests/Unit/Schema/Directives/HasManyDirectiveTest.php @@ -10,7 +10,7 @@ final class HasManyDirectiveTest extends DBTestCase { public function testUsesEdgeTypeForRelayConnections(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type User { tasks: [Task!]! @hasMany ( type: CONNECTION @@ -31,7 +31,7 @@ public function testUsesEdgeTypeForRelayConnections(): void type Query { user: User @auth } - '; + GRAPHQL; $expectedConnectionName = 'TaskEdgeConnection'; @@ -57,7 +57,7 @@ public function testThrowsErrorWithUnknownTypeArg(): void { $this->expectExceptionObject(new DefinitionException('Found invalid pagination type: foo')); - $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type User { tasks(first: Int! after: Int): [Task!]! @hasMany(type: "foo") } @@ -65,6 +65,6 @@ public function testThrowsErrorWithUnknownTypeArg(): void type Task { foo: String } - '); + GRAPHQL); } } diff --git a/tests/Unit/Schema/Directives/HashDirectiveTest.php b/tests/Unit/Schema/Directives/HashDirectiveTest.php index b29e46ce5c..2c1b1a7359 100644 --- a/tests/Unit/Schema/Directives/HashDirectiveTest.php +++ b/tests/Unit/Schema/Directives/HashDirectiveTest.php @@ -8,7 +8,7 @@ final class HashDirectiveTest extends TestCase { public function testHashAnArgument(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: String! @hash): Foo @mock } @@ -16,18 +16,18 @@ public function testHashAnArgument(): void type Foo { bar: String! } - '; + GRAPHQL; $this->mockResolver(static fn ($_, array $args): array => $args); $password = $this - ->graphQL(/** @lang GraphQL */ ' + ->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: "password") { bar } } - ') + GRAPHQL) ->json('data.foo.bar'); $this->assertNotSame('password', $password); @@ -36,7 +36,7 @@ public function testHashAnArgument(): void public function testHashAnArgumentInInputObjectAndArray(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(input: UserInput!): User @mock } @@ -52,11 +52,11 @@ public function testHashAnArgumentInInputObjectAndArray(): void alt_passwords: [String!] @hash friends: [UserInput!] } - '; + GRAPHQL; $this->mockResolver(static fn ($_, array $args): array => $args['input']); - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(input: { password: "password" @@ -82,7 +82,7 @@ public function testHashAnArgumentInInputObjectAndArray(): void } } } - '); + GRAPHQL); $password = $result->json('data.user.password'); $this->assertNotSame('password', $password); @@ -117,7 +117,7 @@ public function testHashAnArgumentInInputObjectAndArray(): void public function testHashWithRename(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user(input: UserInput!): User @mock } @@ -129,11 +129,11 @@ public function testHashWithRename(): void input UserInput { password: String! @hash @rename(attribute: "password_renamed") } - '; + GRAPHQL; $this->mockResolver(static fn ($_, array $args): array => $args['input']); - $result = $this->graphQL(/** @lang GraphQL */ ' + $result = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user(input: { password: "password" @@ -141,7 +141,7 @@ public function testHashWithRename(): void password_renamed } } - '); + GRAPHQL); $password = $result->json('data.user.password_renamed'); $this->assertNotSame('password', $password); diff --git a/tests/Unit/Schema/Directives/HideDirectiveTest.php b/tests/Unit/Schema/Directives/HideDirectiveTest.php index 1602779572..0ad5888bbe 100644 --- a/tests/Unit/Schema/Directives/HideDirectiveTest.php +++ b/tests/Unit/Schema/Directives/HideDirectiveTest.php @@ -9,14 +9,14 @@ final class HideDirectiveTest extends TestCase { public function testHiddenOnTestingEnv(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { shownField: String! @mock hiddenField: String! @mock @hide(env: ["testing"]) } - '; + GRAPHQL; - $introspectionQuery = /** @lang GraphQL */ ' + $introspectionQuery = /** @lang GraphQL */ <<<'GRAPHQL' { __schema { queryType { @@ -26,29 +26,29 @@ public function testHiddenOnTestingEnv(): void } } } - '; + GRAPHQL; $this->graphQL($introspectionQuery) ->assertJsonPath('data.__schema.queryType.fields.*.name', ['shownField']); - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' { hiddenField } - '; + GRAPHQL; $this->graphQL($query)->assertGraphQLErrorMessage('Cannot query field "hiddenField" on type "Query". Did you mean "shownField"?'); } public function testHiddenArgs(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { field(hiddenArg: String @hide(env: ["testing"])): String! @mock } - '; + GRAPHQL; - $introspectionQuery = /** @lang GraphQL */ ' + $introspectionQuery = /** @lang GraphQL */ <<<'GRAPHQL' { __schema { queryType { @@ -60,7 +60,7 @@ public function testHiddenArgs(): void } } } - '; + GRAPHQL; $this->graphQL($introspectionQuery) ->assertJsonCount(0, 'data.__schema.queryType.fields.0.args'); @@ -68,16 +68,16 @@ public function testHiddenArgs(): void public function testHiddenType(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { field: String! @mock } type HiddenType @hide(env: ["testing"]) { field: String! } - '; + GRAPHQL; - $introspectionQuery = /** @lang GraphQL */ ' + $introspectionQuery = /** @lang GraphQL */ <<<'GRAPHQL' { __schema { types { @@ -85,7 +85,7 @@ public function testHiddenType(): void } } } - '; + GRAPHQL; $types = $this->graphQL($introspectionQuery) ->json('data.__schema.types.*.name'); @@ -95,7 +95,7 @@ public function testHiddenType(): void public function testHiddenInputField(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { field: String! @mock } @@ -103,9 +103,9 @@ public function testHiddenInputField(): void input Input { hiddenInputField: String! @hide(env: ["testing"]) } - '; + GRAPHQL; - $introspectionQuery = /** @lang GraphQL */ ' + $introspectionQuery = /** @lang GraphQL */ <<<'GRAPHQL' { __schema { types { @@ -116,7 +116,7 @@ public function testHiddenInputField(): void } } } - '; + GRAPHQL; $types = $this->graphQL($introspectionQuery) ->json('data.__schema.types'); @@ -129,13 +129,13 @@ public function testHiddenInputField(): void public function testHiddenWhenManuallySettingEnv(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { hiddenField: String! @mock @hide(env: ["production"]) } - '; + GRAPHQL; - $introspectionQuery = /** @lang GraphQL */ ' + $introspectionQuery = /** @lang GraphQL */ <<<'GRAPHQL' { __schema { queryType { @@ -145,7 +145,7 @@ public function testHiddenWhenManuallySettingEnv(): void } } } - '; + GRAPHQL; Container::getInstance()->instance('env', 'production'); $this->graphQL($introspectionQuery) @@ -154,13 +154,13 @@ public function testHiddenWhenManuallySettingEnv(): void public function testShownOnAnotherEnv(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { hiddenField: String! @mock @hide(env: ["production"]) } - '; + GRAPHQL; - $introspectionQuery = /** @lang GraphQL */ ' + $introspectionQuery = /** @lang GraphQL */ <<<'GRAPHQL' { __schema { queryType { @@ -170,7 +170,7 @@ public function testShownOnAnotherEnv(): void } } } - '; + GRAPHQL; $this->graphQL($introspectionQuery) ->assertJsonCount(1, 'data.__schema.queryType.fields') diff --git a/tests/Unit/Schema/Directives/MethodDirectiveTest.php b/tests/Unit/Schema/Directives/MethodDirectiveTest.php index 7e7bac7fb8..46032feb59 100644 --- a/tests/Unit/Schema/Directives/MethodDirectiveTest.php +++ b/tests/Unit/Schema/Directives/MethodDirectiveTest.php @@ -8,72 +8,72 @@ final class MethodDirectiveTest extends TestCase { - protected string $schema = /** @lang GraphQL */ ' + protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Foo @mock } - '; + GRAPHQL; public function testDefaultToFieldNameAsMethodName(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Foo { bar: ID @method } - '; + GRAPHQL; $foo = $this->mockFoo(); $foo->expects($this->once()) ->method('bar') ->with(); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { bar } } - '); + GRAPHQL); } public function testWillPreferExplicitName(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Foo { asdf: ID @method(name: "bar") } - '; + GRAPHQL; $foo = $this->mockFoo(); $foo->expects($this->once()) ->method('bar'); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { asdf } } - '); + GRAPHQL); } public function testPassArgsInLexicalOrderOfDefinition(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Foo { bar( first: ID second: ID ): ID @method } - '; + GRAPHQL; $foo = $this->mockFoo(); $foo->expects($this->once()) ->method('bar') ->with(1, 2); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { bar( @@ -82,31 +82,31 @@ public function testPassArgsInLexicalOrderOfDefinition(): void ) } } - '); + GRAPHQL); } public function testPassOrderedDefaultsToNull(): void { - $this->schema .= /** @lang GraphQL */ ' + $this->schema .= /** @lang GraphQL */ <<<'GRAPHQL' type Foo { bar( baz: ID ): ID @method } - '; + GRAPHQL; $foo = $this->mockFoo(); $foo->expects($this->once()) ->method('bar') ->with(null); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { bar } } - '); + GRAPHQL); } private function mockFoo(): MockObject diff --git a/tests/Unit/Schema/Directives/NamespaceDirectiveTest.php b/tests/Unit/Schema/Directives/NamespaceDirectiveTest.php index accaae80ca..6ce3161c91 100644 --- a/tests/Unit/Schema/Directives/NamespaceDirectiveTest.php +++ b/tests/Unit/Schema/Directives/NamespaceDirectiveTest.php @@ -9,19 +9,19 @@ final class NamespaceDirectiveTest extends TestCase { public function testSetNamespaceOnField(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: String @field(resolver: "Foo") - @namespace(field: "Tests\\\Utils\\\QueriesSecondary") + @namespace(field: "Tests\\Utils\\QueriesSecondary") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => Foo::NOT_THE_ANSWER, ], @@ -30,17 +30,17 @@ public function testSetNamespaceOnField(): void public function testSetNamespaceFromType(): void { - $this->schema = /** @lang GraphQL */ ' - type Query @namespace(field: "Tests\\\Utils\\\QueriesSecondary") { + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query @namespace(field: "Tests\\Utils\\QueriesSecondary") { foo: String @field(resolver: "Foo") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => Foo::NOT_THE_ANSWER, ], @@ -49,19 +49,19 @@ public function testSetNamespaceFromType(): void public function testPrefersFieldNamespaceOverTypeNamespace(): void { - $this->schema = /** @lang GraphQL */ ' - type Query @namespace(field: "Tests\\\Utils\\\QueriesSecondary") { + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + type Query @namespace(field: "Tests\\Utils\\QueriesSecondary") { foo: Int @field(resolver: "Foo") - @namespace(field: "Tests\\\Utils\\\Queries") + @namespace(field: "Tests\\Utils\\Queries") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => \Tests\Utils\Queries\Foo::THE_ANSWER, ], diff --git a/tests/Unit/Schema/Directives/RenameDirectiveTest.php b/tests/Unit/Schema/Directives/RenameDirectiveTest.php index 53dfa19bce..12efb3bcaf 100644 --- a/tests/Unit/Schema/Directives/RenameDirectiveTest.php +++ b/tests/Unit/Schema/Directives/RenameDirectiveTest.php @@ -13,7 +13,7 @@ public function testRenameField(): void 'baz' => 'asdf', ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Foo @mock } @@ -21,15 +21,15 @@ public function testRenameField(): void type Foo { bar: String! @rename(attribute: "baz") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo { bar } } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => [ 'bar' => 'asdf', @@ -42,17 +42,17 @@ public function testThrowsAnExceptionIfNoAttributeDefined(): void { $this->expectException(DefinitionException::class); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: String! @rename } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } public function testRenameArgument(): void @@ -63,19 +63,19 @@ public function testRenameArgument(): void ['bar' => 'something'], ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( baz: String @rename(attribute: "bar") ): Boolean @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(baz: "something") } - '); + GRAPHQL); } public function testRenameListOfInputs(): void @@ -90,7 +90,7 @@ public function testRenameListOfInputs(): void ], ); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( input: [FooInput] @@ -100,9 +100,9 @@ public function testRenameListOfInputs(): void input FooInput { baz: String @rename(attribute: "bar") } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo( input: [ @@ -112,6 +112,6 @@ public function testRenameListOfInputs(): void ] ) } - '); + GRAPHQL); } } diff --git a/tests/Unit/Schema/Directives/ShowDirectiveTest.php b/tests/Unit/Schema/Directives/ShowDirectiveTest.php index 8840366e2f..599ee13915 100644 --- a/tests/Unit/Schema/Directives/ShowDirectiveTest.php +++ b/tests/Unit/Schema/Directives/ShowDirectiveTest.php @@ -9,14 +9,14 @@ final class ShowDirectiveTest extends TestCase { public function testHiddenOnTestingEnv(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { shownField: String! @mock hiddenField: String! @mock @show(env: ["production"]) } - '; + GRAPHQL; - $introspectionQuery = /** @lang GraphQL */ ' + $introspectionQuery = /** @lang GraphQL */ <<<'GRAPHQL' { __schema { queryType { @@ -26,29 +26,29 @@ public function testHiddenOnTestingEnv(): void } } } - '; + GRAPHQL; $this->graphQL($introspectionQuery) ->assertJsonPath('data.__schema.queryType.fields.*.name', ['shownField']); - $query = /** @lang GraphQL */ ' + $query = /** @lang GraphQL */ <<<'GRAPHQL' { hiddenField } - '; + GRAPHQL; $this->graphQL($query)->assertGraphQLErrorMessage('Cannot query field "hiddenField" on type "Query". Did you mean "shownField"?'); } public function testShownOnAnotherEnv(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { hiddenField: String! @mock @show(env: ["production"]) } - '; + GRAPHQL; - $introspectionQuery = /** @lang GraphQL */ ' + $introspectionQuery = /** @lang GraphQL */ <<<'GRAPHQL' { __schema { queryType { @@ -58,7 +58,7 @@ public function testShownOnAnotherEnv(): void } } } - '; + GRAPHQL; Container::getInstance()->instance('env', 'production'); $this->graphQL($introspectionQuery) diff --git a/tests/Unit/Schema/Directives/SpreadDirectiveTest.php b/tests/Unit/Schema/Directives/SpreadDirectiveTest.php index e3159c79e4..ebbd6917c0 100644 --- a/tests/Unit/Schema/Directives/SpreadDirectiveTest.php +++ b/tests/Unit/Schema/Directives/SpreadDirectiveTest.php @@ -14,7 +14,7 @@ public function testSpread(): void 'foo' => 1, ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Foo @spread): Int @mock } @@ -22,15 +22,15 @@ public function testSpread(): void input Foo { foo: Int } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(input: { foo: 1 }) } - '); + GRAPHQL); } public function testNestedSpread(): void @@ -41,7 +41,7 @@ public function testNestedSpread(): void 'baz' => 2, ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: Foo @spread): Int @mock } @@ -54,9 +54,9 @@ public function testNestedSpread(): void input Bar { baz: Int } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(input: { foo: 1 @@ -65,7 +65,7 @@ public function testNestedSpread(): void } }) } - '); + GRAPHQL); } public function testNestedSpreadInList(): void @@ -79,7 +79,7 @@ public function testNestedSpreadInList(): void ], ]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: [Foo!]!): Int @mock } @@ -91,9 +91,9 @@ public function testNestedSpreadInList(): void input Bar { baz: Int! } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(input: [ { @@ -103,13 +103,13 @@ public function testNestedSpreadInList(): void } ]) } - '); + GRAPHQL); } public function testSpreadOnListThrows(): void { $this->expectExceptionObject(new DefinitionException('Cannot use @spread on argument Query.foo:input with a list type.')); - $this->buildSchema(/** @lang GraphQL */ ' + $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(input: [Foo!]! @spread): Int } @@ -117,6 +117,6 @@ public function testSpreadOnListThrows(): void input Foo { bar: Int! } - '); + GRAPHQL); } } diff --git a/tests/Unit/Schema/Directives/ThrottleDirectiveTest.php b/tests/Unit/Schema/Directives/ThrottleDirectiveTest.php index adda90a255..e7a80ac672 100644 --- a/tests/Unit/Schema/Directives/ThrottleDirectiveTest.php +++ b/tests/Unit/Schema/Directives/ThrottleDirectiveTest.php @@ -15,11 +15,11 @@ final class ThrottleDirectiveTest extends TestCase { public function testNamedLimiter(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @throttle(name: "test") } - '; + GRAPHQL; $queriedKeys = []; @@ -46,11 +46,11 @@ public function testNamedLimiter(): void $this->app->singleton(RateLimiter::class, static fn (): RateLimiter => $rateLimiter); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -62,11 +62,11 @@ public function testNamedLimiter(): void public function testUnlimitedNamedLimiter(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @throttle(name: "test") } - '; + GRAPHQL; $rateLimiter = $this->createMock(RateLimiter::class); $rateLimiter->expects($this->atLeast(1)) @@ -82,11 +82,11 @@ public function testUnlimitedNamedLimiter(): void $this->app->singleton(RateLimiter::class, static fn (): RateLimiter => $rateLimiter); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], @@ -95,11 +95,11 @@ public function testUnlimitedNamedLimiter(): void public function testWithNullRequest(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: Int @throttle(name: "test") } - '; + GRAPHQL; $rateLimiter = $this->createMock(RateLimiter::class); $rateLimiter->expects($this->atLeast(1)) @@ -122,11 +122,11 @@ public function generate(?Request $request): GraphQLContext $this->app->singleton(RateLimiter::class, static fn (): RateLimiter => $rateLimiter); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertJson([ + GRAPHQL)->assertJson([ 'data' => [ 'foo' => Foo::THE_ANSWER, ], diff --git a/tests/Unit/Schema/Directives/UploadDirectiveTest.php b/tests/Unit/Schema/Directives/UploadDirectiveTest.php index bbd25986e6..0c586d4d1e 100644 --- a/tests/Unit/Schema/Directives/UploadDirectiveTest.php +++ b/tests/Unit/Schema/Directives/UploadDirectiveTest.php @@ -21,25 +21,25 @@ public function testUploadArgumentWithDefaultParameters(): void Storage::fake('uploadDisk'); - $this->schema = /** @lang GraphQL */ ' - scalar Upload @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Upload") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload") type Mutation { upload( file: Upload! @upload ): String @mock } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $file = UploadedFile::fake()->create('test.pdf', 500); $this->multipartGraphQL( [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file: Upload!) { file: upload(file: $file) } - ', + GRAPHQL, 'variables' => [ 'file' => null, ], @@ -64,25 +64,25 @@ public function testUploadArgumentWithDiskParameter(): void return $filePath = $args['file']; }); - $this->schema = /** @lang GraphQL */ ' - scalar Upload @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Upload") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload") type Mutation { upload( file: Upload! @upload(disk:"uploadDisk") ): String @mock } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $file = UploadedFile::fake()->create('test.pdf', 500); $this->multipartGraphQL( [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file: Upload!) { file: upload(file: $file) } - ', + GRAPHQL, 'variables' => [ 'file' => null, ], @@ -106,25 +106,25 @@ public function testUploadArgumentWithPathParameter(): void return $filePath = $args['file']; }); - $this->schema = /** @lang GraphQL */ ' - scalar Upload @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Upload") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload") type Mutation { upload( file: Upload! @upload(path:"test") ): String @mock } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $file = UploadedFile::fake()->create('test.pdf', 500); $this->multipartGraphQL( [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file: Upload!) { file: upload(file: $file) } - ', + GRAPHQL, 'variables' => [ 'file' => null, ], @@ -148,25 +148,25 @@ public function testUploadArgumentWithPublicParameter(): void return $filePath = $args['file']; }); - $this->schema = /** @lang GraphQL */ ' - scalar Upload @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Upload") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload") type Mutation { upload( file: Upload! @upload(public: true disk:"uploadDisk") ): String @mock } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $file = UploadedFile::fake()->create('test.pdf', 500); $this->multipartGraphQL( [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file: Upload!) { file: upload(file: $file) } - ', + GRAPHQL, 'variables' => [ 'file' => null, ], @@ -189,23 +189,23 @@ public function testUploadArgumentWhereValueIsNull(): void return $filePath = $args['file']; }); - $this->schema = /** @lang GraphQL */ ' - scalar Upload @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Upload") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload") type Mutation { upload( file: Upload @upload ): String @mock } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $this->multipartGraphQL( [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file: Upload) { file: upload(file: $file) } - ', + GRAPHQL, 'variables' => [ 'file' => null, ], @@ -223,15 +223,15 @@ public function testThrowsAnExceptionIfDiskIsMissing(): void { config(['filesystems.default' => 'uploadDisk']); - $this->schema = /** @lang GraphQL */ ' - scalar Upload @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Upload") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload") type Mutation { upload( file: Upload! @upload(disk:"uploadDisk") ): Boolean } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $file = UploadedFile::fake()->create('test.pdf', 500); @@ -239,11 +239,11 @@ public function testThrowsAnExceptionIfDiskIsMissing(): void $this->multipartGraphQL( [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file: Upload!) { file: upload(file: $file) } - ', + GRAPHQL, 'variables' => [ 'file' => null, ], @@ -258,15 +258,15 @@ public function testThrowsAnExceptionIfStoringFails(): void config(['filesystems.default' => 'uploadDisk']); Storage::fake('uploadDisk'); - $this->schema = /** @lang GraphQL */ ' - scalar Upload @scalar(class: "Nuwave\\\\Lighthouse\\\\Schema\\\\Types\\\\Scalars\\\\Upload") + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' + scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload") type Mutation { upload( file: Upload! @upload(path:"/") ): String } - ' . self::PLACEHOLDER_QUERY; + GRAPHQL . self::PLACEHOLDER_QUERY; $file = \Mockery::mock(File::class); @@ -280,11 +280,11 @@ public function testThrowsAnExceptionIfStoringFails(): void $this->multipartGraphQL( [ - 'query' => /** @lang GraphQL */ ' + 'query' => /** @lang GraphQL */ <<<'GRAPHQL' mutation ($file: Upload!) { file: upload(file: $file) } - ', + GRAPHQL, 'variables' => [ 'file' => null, ], @@ -296,19 +296,19 @@ public function testThrowsAnExceptionIfStoringFails(): void public function testThrowsAnExceptionIfAttributeIsNotUploadedFile(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( baz: String @upload ): Boolean } - '; + GRAPHQL; $this->expectExceptionObject(new \InvalidArgumentException('Expected argument `baz` to be instanceof Illuminate\\Http\\UploadedFile.')); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(baz: "something") } - '); + GRAPHQL); } } diff --git a/tests/Unit/Schema/Factories/DirectiveFactoryTest.php b/tests/Unit/Schema/Factories/DirectiveFactoryTest.php index 23fd75e111..f6d3846045 100644 --- a/tests/Unit/Schema/Factories/DirectiveFactoryTest.php +++ b/tests/Unit/Schema/Factories/DirectiveFactoryTest.php @@ -26,7 +26,7 @@ protected function setUp(): void public function testConvertDirectiveFromNodeToExecutable(): void { - $node = Parser::directiveDefinition(/** @lang GraphQL */ ' + $node = Parser::directiveDefinition(/** @lang GraphQL */ <<<'GRAPHQL' "foo description" directive @foo( """ @@ -35,7 +35,7 @@ public function testConvertDirectiveFromNodeToExecutable(): void """ baz: Int ) repeatable on OBJECT - '); + GRAPHQL); $executable = $this->directiveFactory->handle($node); $this->assertSame('foo description', $executable->description); diff --git a/tests/Unit/Schema/ResolverProviderTest.php b/tests/Unit/Schema/ResolverProviderTest.php index 22b71d89e7..10382df494 100644 --- a/tests/Unit/Schema/ResolverProviderTest.php +++ b/tests/Unit/Schema/ResolverProviderTest.php @@ -55,11 +55,11 @@ public function testThrowsIfRootFieldHasNoResolver(): void private function constructFieldValue(string $fieldDefinition, string $parentTypeName = RootType::QUERY): FieldValue { - $queryType = Parser::objectTypeDefinition(/** @lang GraphQL */ " + $queryType = Parser::objectTypeDefinition(/** @lang GraphQL */ <<buildSchema(/** @lang GraphQL */ ' + ->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query extend type Query { foo: Int } - ') + GRAPHQL) ->assertValid(); $this->expectNotToPerformAssertions(); @@ -40,7 +40,7 @@ public function testGeneratesWithEmptyQueryType(): void public function testGeneratesWithEmptyMutationType(): void { - $schema = $this->buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query type Mutation @@ -48,7 +48,7 @@ public function testGeneratesWithEmptyMutationType(): void extend type Mutation { foo(bar: String! baz: String): String } - '); + GRAPHQL); $mutationObjectType = $schema->getType(RootType::MUTATION); $this->assertInstanceOf(ObjectType::class, $mutationObjectType); @@ -58,7 +58,7 @@ public function testGeneratesWithEmptyMutationType(): void public function testResolveEnumTypes(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' "Role description" enum Role { "Company administrator." @@ -67,7 +67,7 @@ enum Role { "Company employee." EMPLOYEE @enum(value: "employee") } - '); + GRAPHQL); $enumType = $schema->getType('Role'); $this->assertInstanceOf(EnumType::class, $enumType); @@ -83,7 +83,7 @@ enum Role { public function testResolveInterfaceTypes(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' """ int """ @@ -91,7 +91,7 @@ interface Foo { "bar is baz" bar: String! } - '); + GRAPHQL); $interfaceType = $schema->getType('Foo'); $this->assertInstanceOf(InterfaceType::class, $interfaceType); @@ -102,7 +102,7 @@ interface Foo { public function testResolveObjectTypes(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' "asdf" type Foo { "bar attribute of Foo" @@ -111,7 +111,7 @@ public function testResolveObjectTypes(): void baz: Boolean = false ): String! } - '); + GRAPHQL); $foo = $schema->getType('Foo'); $this->assertInstanceOf(ObjectType::class, $foo); @@ -129,14 +129,14 @@ public function testResolveObjectTypes(): void public function testResolveInputObjectTypes(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' "bla" input CreateFoo { "xyz" foo: String! bar: Int = 123 } - '); + GRAPHQL); $inputObjectType = $schema->getType('CreateFoo'); $this->assertInstanceOf(InputObjectType::class, $inputObjectType); @@ -149,11 +149,11 @@ public function testResolveInputObjectTypes(): void public function testResolveMutations(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type Mutation { foo(bar: String! baz: String): String } - '); + GRAPHQL); $mutationObjectType = $schema->getType(RootType::MUTATION); $this->assertInstanceOf(ObjectType::class, $mutationObjectType); @@ -173,7 +173,7 @@ public function testResolveQueries(): void public function testExtendObjectTypes(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type Foo { bar: String! } @@ -181,7 +181,7 @@ public function testExtendObjectTypes(): void extend type Foo { baz: String! } - '); + GRAPHQL); $objectType = $schema->getType('Foo'); $this->assertInstanceOf(ObjectType::class, $objectType); @@ -192,7 +192,7 @@ public function testExtendObjectTypes(): void public function testExtendTypes(): void { - $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ ' + $schema = $this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL' type Foo { foo: String! } @@ -201,7 +201,7 @@ public function testExtendTypes(): void "yo?" bar: String! } - '); + GRAPHQL); $type = $schema->getType('Foo'); $this->assertInstanceOf(ObjectType::class, $type); @@ -211,7 +211,7 @@ public function testExtendTypes(): void public function testResolvesEnumDefaultValuesToInternalValues(): void { - $schema = $this->buildSchema(/** @lang GraphQL */ ' + $schema = $this->buildSchema(/** @lang GraphQL */ <<<'GRAPHQL' type Query { foo( bar: Baz = FOOBAR @@ -221,7 +221,7 @@ public function testResolvesEnumDefaultValuesToInternalValues(): void enum Baz { FOOBAR @enum(value: "internal") } - '); + GRAPHQL); $queryType = $schema->getQueryType(); $this->assertInstanceOf(ObjectType::class, $queryType); diff --git a/tests/Unit/Schema/SecurityTest.php b/tests/Unit/Schema/SecurityTest.php index f6806f9f19..4f7d648daa 100644 --- a/tests/Unit/Schema/SecurityTest.php +++ b/tests/Unit/Schema/SecurityTest.php @@ -13,7 +13,7 @@ public function testSetMaxComplexityThroughConfig(): void { config(['lighthouse.security.max_query_complexity' => 1]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User @first } @@ -21,7 +21,7 @@ public function testSetMaxComplexityThroughConfig(): void type User { name: String } - '; + GRAPHQL; $this->assertMaxQueryComplexityIs1(); } @@ -30,7 +30,7 @@ public function testSetMaxDepthThroughConfig(): void { config(['lighthouse.security.max_query_depth' => 1]); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { user: User @first } @@ -39,7 +39,7 @@ public function testSetMaxDepthThroughConfig(): void name: String user: User } - '; + GRAPHQL; $this->assertMaxQueryDepthIs1(); } @@ -53,20 +53,20 @@ public function testDisableIntrospectionThroughConfig(): void private function assertMaxQueryComplexityIs1(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { name } } - ')->assertGraphQLErrorMessage( + GRAPHQL)->assertGraphQLErrorMessage( QueryComplexity::maxQueryComplexityErrorMessage(1, 2), ); } private function assertMaxQueryDepthIs1(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { user { user { @@ -76,14 +76,14 @@ private function assertMaxQueryDepthIs1(): void } } } - ')->assertGraphQLErrorMessage( + GRAPHQL)->assertGraphQLErrorMessage( QueryDepth::maxQueryDepthErrorMessage(1, 2), ); } private function assertIntrospectionIsDisabled(): void { - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { __schema { queryType { @@ -91,7 +91,7 @@ private function assertIntrospectionIsDisabled(): void } } } - ')->assertGraphQLErrorMessage( + GRAPHQL)->assertGraphQLErrorMessage( DisableIntrospection::introspectionDisabledMessage(), ); } diff --git a/tests/Unit/Schema/TypeRegistryTest.php b/tests/Unit/Schema/TypeRegistryTest.php index 845e721a4b..37a1bb02a3 100644 --- a/tests/Unit/Schema/TypeRegistryTest.php +++ b/tests/Unit/Schema/TypeRegistryTest.php @@ -30,11 +30,11 @@ protected function setUp(): void public function testSetsEnumValueThroughDirective(): void { - $enumNode = Parser::enumTypeDefinition(/** @lang GraphQL */ ' + $enumNode = Parser::enumTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' enum Role { ADMIN @enum(value: 123) } - '); + GRAPHQL); $enumType = $this->typeRegistry->handle($enumNode); $this->assertInstanceOf(EnumType::class, $enumType); @@ -49,11 +49,11 @@ enum Role { public function testDefaultsEnumValueToItsName(): void { - $enumNode = Parser::enumTypeDefinition(/** @lang GraphQL */ ' + $enumNode = Parser::enumTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' enum Role { EMPLOYEE } - '); + GRAPHQL); $enumType = $this->typeRegistry->handle($enumNode); $this->assertInstanceOf(EnumType::class, $enumType); @@ -68,9 +68,9 @@ enum Role { public function testTransformScalars(): void { - $scalarNode = Parser::scalarTypeDefinition(/** @lang GraphQL */ ' + $scalarNode = Parser::scalarTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' scalar Email - '); + GRAPHQL); $scalarType = $this->typeRegistry->handle($scalarNode); $this->assertInstanceOf(ScalarType::class, $scalarType); @@ -80,9 +80,9 @@ public function testTransformScalars(): void public function testPointToScalarClassThroughDirective(): void { - $scalarNode = Parser::scalarTypeDefinition(/** @lang GraphQL */ ' - scalar DateTime @scalar(class: "Nuwave\\\Lighthouse\\\Schema\\\Types\\\Scalars\\\DateTime") - '); + $scalarNode = Parser::scalarTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' + scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime") + GRAPHQL); $scalarType = $this->typeRegistry->handle($scalarNode); $this->assertInstanceOf(ScalarType::class, $scalarType); @@ -92,9 +92,9 @@ public function testPointToScalarClassThroughDirective(): void public function testPointToScalarClassThroughDirectiveWithoutNamespace(): void { - $scalarNode = Parser::scalarTypeDefinition(/** @lang GraphQL */ ' + $scalarNode = Parser::scalarTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' scalar SomeEmail @scalar(class: "Email") - '); + GRAPHQL); $scalarType = $this->typeRegistry->handle($scalarNode); $this->assertInstanceOf(ScalarType::class, $scalarType); @@ -112,11 +112,11 @@ public function testTransformInterfaces(): void ]); $this->typeRegistry->overwrite($bar); - $interfaceNode = Parser::interfaceTypeDefinition(/** @lang GraphQL */ ' + $interfaceNode = Parser::interfaceTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' interface Foo implements Bar { bar: String } - '); + GRAPHQL); $interfaceType = $this->typeRegistry->handle($interfaceNode); $this->assertInstanceOf(InterfaceType::class, $interfaceType); @@ -128,11 +128,11 @@ interface Foo implements Bar { public function testResolvesInterfaceThoughNamespace(): void { - $interfaceNode = Parser::interfaceTypeDefinition(/** @lang GraphQL */ ' + $interfaceNode = Parser::interfaceTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' interface Nameable { bar: String } - '); + GRAPHQL); $interfaceType = $this->typeRegistry->handle($interfaceNode); $this->assertInstanceOf(InterfaceType::class, $interfaceType); @@ -142,11 +142,11 @@ interface Nameable { public function testResolvesInterfaceThoughSecondaryNamespace(): void { - $interfaceNode = Parser::interfaceTypeDefinition(/** @lang GraphQL */ ' + $interfaceNode = Parser::interfaceTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' interface Bar { bar: String } - '); + GRAPHQL); $interfaceType = $this->typeRegistry->handle($interfaceNode); $this->assertInstanceOf(InterfaceType::class, $interfaceType); @@ -156,9 +156,9 @@ interface Bar { public function testTransformUnions(): void { - $unionNode = Parser::unionTypeDefinition(/** @lang GraphQL */ ' + $unionNode = Parser::unionTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' union Foo = Bar - '); + GRAPHQL); $unionType = $this->typeRegistry->handle($unionNode); $this->assertInstanceOf(UnionType::class, $unionType); @@ -169,11 +169,11 @@ public function testTransformUnions(): void public function testTransformObjectTypes(): void { - $objectTypeNode = Parser::objectTypeDefinition(/** @lang GraphQL */ ' + $objectTypeNode = Parser::objectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' type User { foo(bar: String! @hash): String! } - '); + GRAPHQL); $objectType = $this->typeRegistry->handle($objectTypeNode); $this->assertInstanceOf(ObjectType::class, $objectType); @@ -184,11 +184,11 @@ public function testTransformObjectTypes(): void public function testTransformInputObjectTypes(): void { - $inputNode = Parser::inputObjectTypeDefinition(/** @lang GraphQL */ ' + $inputNode = Parser::inputObjectTypeDefinition(/** @lang GraphQL */ <<<'GRAPHQL' input UserInput { foo: String! } - '); + GRAPHQL); $inputObjectType = $this->typeRegistry->handle($inputNode); $this->assertInstanceOf(InputObjectType::class, $inputObjectType); @@ -299,11 +299,11 @@ public function testPossibleTypes(): void { $documentTypeName = 'Foo'; - $this->schema = /** @lang GraphQL */ " + $this->schema = /** @lang GraphQL */ <<app->forgetInstance(ASTBuilder::class); $astBuilder = $this->app->make(ASTBuilder::class); @@ -335,11 +335,11 @@ public function testPossibleTypesMaintainsSingletons(): void { $documentTypeName = 'Foo'; - $this->schema = /** @lang GraphQL */ " + $this->schema = /** @lang GraphQL */ <<app->forgetInstance(ASTBuilder::class); $astBuilder = $this->app->make(ASTBuilder::class); diff --git a/tests/Unit/Schema/Types/LaravelEnumTypeTest.php b/tests/Unit/Schema/Types/LaravelEnumTypeTest.php index 59289cba90..5f482f9946 100644 --- a/tests/Unit/Schema/Types/LaravelEnumTypeTest.php +++ b/tests/Unit/Schema/Types/LaravelEnumTypeTest.php @@ -73,8 +73,7 @@ enum PartiallyDeprecated { "Deprecated with reason" DEPRECATED_WITH_REASON @deprecated(reason: "some reason") } -GRAPHQL - , +GRAPHQL, SchemaPrinter::printType($enumType), ); } else { @@ -89,8 +88,7 @@ enum PartiallyDeprecated { "Deprecated with reason" DEPRECATED_WITH_REASON @deprecated(reason: "some reason") } -GRAPHQL - , +GRAPHQL, SchemaPrinter::printType($enumType), ); } @@ -98,11 +96,11 @@ enum PartiallyDeprecated { public function testReceivesEnumInstanceInternally(): void { - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(bar: AOrB): Boolean @mock } - '; + GRAPHQL; $this->typeRegistry->register( new LaravelEnumType(AOrB::class), @@ -111,11 +109,11 @@ public function testReceivesEnumInstanceInternally(): void $this->mockResolver() ->with(null, new Callback(static fn (array $args): bool => $args['bar'] instanceof AOrB)); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(bar: A) } - '); + GRAPHQL); } public function testClassDoesNotExist(): void diff --git a/tests/Unit/Subscriptions/Storage/CacheStorageManagerTest.php b/tests/Unit/Subscriptions/Storage/CacheStorageManagerTest.php index 02a08ea479..bd2561db2a 100644 --- a/tests/Unit/Subscriptions/Storage/CacheStorageManagerTest.php +++ b/tests/Unit/Subscriptions/Storage/CacheStorageManagerTest.php @@ -34,7 +34,9 @@ private function subscriber(string $queryString): Subscriber public function testStoreAndRetrieveByChannel(): void { - $subscriber = $this->subscriber(/** @lang GraphQL */ '{ me }'); + $subscriber = $this->subscriber(/** @lang GraphQL */ <<<'GRAPHQL' + { me } + GRAPHQL); $this->storage->storeSubscriber($subscriber, 'foo'); $this->assertSubscriberIsSame( @@ -46,13 +48,19 @@ public function testStoreAndRetrieveByChannel(): void public function testStoreAndRetrieveByTopics(): void { $fooTopic = 'foo'; - $fooSubscriber1 = $this->subscriber(/** @lang GraphQL */ '{ me }'); - $fooSubscriber2 = $this->subscriber(/** @lang GraphQL */ '{ viewer }'); + $fooSubscriber1 = $this->subscriber(/** @lang GraphQL */ <<<'GRAPHQL' + { me } + GRAPHQL); + $fooSubscriber2 = $this->subscriber(/** @lang GraphQL */ <<<'GRAPHQL' + { viewer } + GRAPHQL); $this->storage->storeSubscriber($fooSubscriber1, $fooTopic); $this->storage->storeSubscriber($fooSubscriber2, $fooTopic); $barTopic = 'bar'; - $barSubscriber = $this->subscriber(/** @lang GraphQL */ '{ bar }'); + $barSubscriber = $this->subscriber(/** @lang GraphQL */ <<<'GRAPHQL' + { bar } + GRAPHQL); $this->storage->storeSubscriber($barSubscriber, $barTopic); $fooSubscribers = $this->storage->subscribersByTopic($fooTopic); @@ -64,8 +72,12 @@ public function testStoreAndRetrieveByTopics(): void public function testDeleteSubscribersInCache(): void { - $subscriber1 = $this->subscriber(/** @lang GraphQL */ '{ me }'); - $subscriber2 = $this->subscriber(/** @lang GraphQL */ '{ viewer }'); + $subscriber1 = $this->subscriber(/** @lang GraphQL */ <<<'GRAPHQL' + { me } + GRAPHQL); + $subscriber2 = $this->subscriber(/** @lang GraphQL */ <<<'GRAPHQL' + { viewer } + GRAPHQL); $topic = 'foo'; $this->storage->storeSubscriber($subscriber1, $topic); diff --git a/tests/Unit/Testing/MakesGraphQLRequestsTest.php b/tests/Unit/Testing/MakesGraphQLRequestsTest.php index 257aeea223..a3569e3ac7 100644 --- a/tests/Unit/Testing/MakesGraphQLRequestsTest.php +++ b/tests/Unit/Testing/MakesGraphQLRequestsTest.php @@ -32,26 +32,26 @@ public function testRethrowGraphQLErrors(): void throw $error; }); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - ')->assertGraphQLError($error); + GRAPHQL)->assertGraphQLError($error); $this->rethrowGraphQLErrors(); $this->expectExceptionObject($error); - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo } - '); + GRAPHQL); } public function testGraphQLWithHeaders(): void @@ -62,22 +62,24 @@ public function testGraphQLWithHeaders(): void $request = $this->app->make(Request::class); }); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo: ID @mock } - '; + GRAPHQL; $key = 'foo'; $value = 'bar'; $this->graphQL( /** @lang GraphQL */ - ' + <<<'GRAPHQL' + { foo } - ', + + GRAPHQL, [], [], [$key => $value], diff --git a/tests/Unit/Testing/MocksResolversTest.php b/tests/Unit/Testing/MocksResolversTest.php index 1595961a93..66d1020d9f 100644 --- a/tests/Unit/Testing/MocksResolversTest.php +++ b/tests/Unit/Testing/MocksResolversTest.php @@ -14,17 +14,17 @@ public function testCallsMock(): void ]) ->willReturn(2); - $this->schema = /** @lang GraphQL */ ' + $this->schema = /** @lang GraphQL */ <<<'GRAPHQL' type Query { foo(foo: Int): Int @mock } - '; + GRAPHQL; - $this->graphQL(/** @lang GraphQL */ ' + $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL' { foo(foo: 1) } - ')->assertExactJson([ + GRAPHQL)->assertExactJson([ 'data' => [ 'foo' => 2, ],