diff --git a/CHANGELOG.md b/CHANGELOG.md index b8857ed803..c678e5f3ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add compatibility layer to allow `@middleware` to support Lumen https://github.com/nuwave/lighthouse/pull/786 - Add option `decode` to `@globaldId` to control the result of decoding https://github.com/nuwave/lighthouse/pull/796 - Add config option `cache.ttl` for customizing expiration time of schema cache https://github.com/nuwave/lighthouse/pull/801 +- Extract test helpers into a reusable trait `\Nuwave\Lighthouse\Testing\MakesGraphQLRequests` https://github.com/nuwave/lighthouse/pull/802 - Support custom rule classes in `@rules` and `@rulesForArray` https://github.com/nuwave/lighthouse/pull/812 ### Fixed diff --git a/src/Support/Http/routes.php b/src/Support/Http/routes.php index 6334818fbb..c1a45a0d20 100644 --- a/src/Support/Http/routes.php +++ b/src/Support/Http/routes.php @@ -1,6 +1,9 @@ group(config('lighthouse.route', []), function (): void { +/** @var \Illuminate\Contracts\Routing\Registrar $router */ +$router = app('router'); + +$router->group(config('lighthouse.route', []), function () use ($router): void { $routeName = config('lighthouse.route_name', 'graphql'); $controller = config('lighthouse.controller'); @@ -8,7 +11,7 @@ ? ['GET', 'POST'] : ['POST']; - app('router')->match($methods, $routeName, [ + $router->match($methods, $routeName, [ 'as' => 'lighthouse.graphql', 'uses' => $controller, ]); diff --git a/src/Testing/MakesGraphQLRequests.php b/src/Testing/MakesGraphQLRequests.php new file mode 100644 index 0000000000..122136708b --- /dev/null +++ b/src/Testing/MakesGraphQLRequests.php @@ -0,0 +1,117 @@ +postGraphQL( + [ + 'query' => $query, + ] + ); + } + + /** + * Execute a query as if it was sent as a request to the server. + * + * @param mixed[] $data + * @param mixed[] $headers + * @return \Illuminate\Foundation\Testing\TestResponse + */ + protected function postGraphQL(array $data, array $headers = []): TestResponse + { + return $this->postJson( + $this->graphQLEndpointUrl(), + $data, + $headers + ); + } + + /** + * Send a multipart form request to GraphQL. + * + * This is used for file uploads conforming to the specification: + * https://github.com/jaydenseric/graphql-multipart-request-spec + * + * @param mixed[] $parameters + * @param mixed[] $files + * @return \Illuminate\Foundation\Testing\TestResponse + */ + protected function multipartGraphQL(array $parameters, array $files): TestResponse + { + return $this->call( + 'POST', + $this->graphQLEndpointUrl(), + $parameters, + [], + $files, + $this->transformHeadersToServerVars([ + 'Content-Type' => 'multipart/form-data', + ]) + ); + } + + /** + * Return the full URL to the GraphQL endpoint. + * + * @return string + */ + private function graphQLEndpointUrl(): string + { + $path = config('lighthouse.route_name'); + + if ($prefix = config('lighthouse.route.prefix')) { + $path = $prefix.$path; + } + + return $path; + } +} diff --git a/tests/Integration/CustomDefaultResolverTest.php b/tests/Integration/CustomDefaultResolverTest.php index 41bb8b544d..d9ec0fa088 100644 --- a/tests/Integration/CustomDefaultResolverTest.php +++ b/tests/Integration/CustomDefaultResolverTest.php @@ -37,7 +37,7 @@ public function itCanSpecifyACustomDefaultResolver(): void return self::CUSTOM_RESOLVER_RESULT; }); - $this->query(' + $this->graphQL(' { foo { bar diff --git a/tests/Integration/Defer/DeferTest.php b/tests/Integration/Defer/DeferTest.php index b0e50d3393..9769e497a3 100644 --- a/tests/Integration/Defer/DeferTest.php +++ b/tests/Integration/Defer/DeferTest.php @@ -424,7 +424,7 @@ public function itThrowsExceptionOnNunNullableFields(): void } "; - $this->query(' + $this->graphQL(' { user { name @@ -471,7 +471,7 @@ public function itSkipsDeferWithIncludeAndSkipDirectives(): void } "; - $this->query(' + $this->graphQL(' { user { name @@ -518,7 +518,7 @@ public function itRequiresDeferDirectiveOnAllFieldDeclarations(): void } "; - $this->query(' + $this->graphQL(' fragment UserWithParent on User { name parent { @@ -574,7 +574,7 @@ public function itSkipsDeferredFieldsOnMutations(): void } "; - $this->query(' + $this->graphQL(' mutation UpdateUser { updateUser(name: "John Doe") { name @@ -613,7 +613,7 @@ public function itDoesNotDeferFieldsIfFalse(): void } "; - $this->query(' + $this->graphQL(' { user { name diff --git a/tests/Integration/Defer/SetUpDefer.php b/tests/Integration/Defer/SetUpDefer.php index 307a690a5a..2a99ca7f58 100644 --- a/tests/Integration/Defer/SetUpDefer.php +++ b/tests/Integration/Defer/SetUpDefer.php @@ -33,7 +33,7 @@ protected function setUpDefer($app) */ protected function getStreamedChunks(string $query): array { - $this->query($query) + $this->graphQL($query) ->baseResponse ->send(); diff --git a/tests/Integration/Events/BuildSchemaStringTest.php b/tests/Integration/Events/BuildSchemaStringTest.php index 808dae3b9e..231f46c22e 100644 --- a/tests/Integration/Events/BuildSchemaStringTest.php +++ b/tests/Integration/Events/BuildSchemaStringTest.php @@ -51,7 +51,7 @@ function (BuildSchemaString $buildSchemaString): string { foo } '; - $this->query($queryForBaseSchema)->assertJson([ + $this->graphQL($queryForBaseSchema)->assertJson([ 'data' => [ 'foo' => 'foo', ], @@ -62,7 +62,7 @@ function (BuildSchemaString $buildSchemaString): string { sayHello } '; - $this->query($queryForAdditionalSchema)->assertJson([ + $this->graphQL($queryForAdditionalSchema)->assertJson([ 'data' => [ 'sayHello' => 'hello', ], diff --git a/tests/Integration/Events/ManipulateResultTest.php b/tests/Integration/Events/ManipulateResultTest.php index 6408c0ad0d..8b7be67f40 100644 --- a/tests/Integration/Events/ManipulateResultTest.php +++ b/tests/Integration/Events/ManipulateResultTest.php @@ -25,7 +25,7 @@ function (ManipulateResult $manipulateResult): void { } ); - $this->query(' + $this->graphQL(' { foo } diff --git a/tests/Integration/Execution/BuilderTest.php b/tests/Integration/Execution/BuilderTest.php index 8fddb09cf0..d2dbdf80cc 100644 --- a/tests/Integration/Execution/BuilderTest.php +++ b/tests/Integration/Execution/BuilderTest.php @@ -47,7 +47,7 @@ public function itCanAttachEqFilterToQuery(): void } '; - $this->query(' + $this->graphQL(' { users(id: '.$this->users->first()->getKey().') { id @@ -71,7 +71,7 @@ public function itCanAttachEqFilterFromInputObject(): void } '; - $this->query(' + $this->graphQL(' { users( input: { @@ -95,7 +95,7 @@ public function itCanAttachNeqFilterToQuery(): void } '; - $this->query(' + $this->graphQL(' { users(id: '.$this->users->first()->getKey().') { id @@ -118,7 +118,7 @@ public function itCanAttachInFilterToQuery(): void $user1 = $this->users->first()->getKey(); $user2 = $this->users->last()->getKey(); - $this->query(' + $this->graphQL(' { users(include: ['.$user1.', '.$user2.']) { id @@ -141,7 +141,7 @@ public function itCanAttachNotInFilterToQuery(): void $user1 = $this->users->first()->getKey(); $user2 = $this->users->last()->getKey(); - $this->query(' + $this->graphQL(' { users(exclude: ['.$user1.', '.$user2.']) { id @@ -163,7 +163,7 @@ public function itCanAttachWhereFilterToQuery(): void $user1 = $this->users->first()->getKey(); - $this->query(' + $this->graphQL(' { users(id: '.$user1.') { id @@ -189,7 +189,7 @@ public function itCanAttachTwoWhereFilterWithTheSameKeyToQuery(): void $user1 = $this->users->first()->getKey(); $user2 = $this->users->last()->getKey(); - $this->query(' + $this->graphQL(' { users(start: '.$user1.' end: '.$user2.') { id @@ -222,7 +222,7 @@ public function itCanAttachWhereBetweenFilterToQuery(): void $start = now()->subDay()->startOfDay()->format('Y-m-d H:i:s'); $end = now()->subDay()->endOfDay()->format('Y-m-d H:i:s'); - $this->query(' + $this->graphQL(' { users( createdBetween: ["'.$start.'", "'.$end.'"] @@ -262,7 +262,7 @@ public function itCanUseInputObjectsForWhereBetweenFilter(): void $start = now()->subDay()->startOfDay()->format('Y-m-d H:i:s'); $end = now()->subDay()->endOfDay()->format('Y-m-d H:i:s'); - $this->query(' + $this->graphQL(' { users( created: { @@ -300,7 +300,7 @@ public function itCanAttachWhereNotBetweenFilterToQuery(): void $start = now()->subDay()->startOfDay()->format('Y-m-d H:i:s'); $end = now()->subDay()->endOfDay()->format('Y-m-d H:i:s'); - $this->query(' + $this->graphQL(' { users( notCreatedBetween: ["'.$start.'", "'.$end.'"] @@ -334,7 +334,7 @@ public function itCanAttachWhereClauseFilterToQuery(): void $year = now()->subYear()->format('Y'); - $this->query(' + $this->graphQL(' { users(created_at: "'.$year.'") { id @@ -357,7 +357,7 @@ public function itOnlyProcessesFilledArguments(): void } '; - $this->query(' + $this->graphQL(' { users(name: "'.$this->users->first()->name.'") { id diff --git a/tests/Integration/Execution/MutationExecutor/BelongsToManyTest.php b/tests/Integration/Execution/MutationExecutor/BelongsToManyTest.php index e1f868b686..d69e0fa3b8 100644 --- a/tests/Integration/Execution/MutationExecutor/BelongsToManyTest.php +++ b/tests/Integration/Execution/MutationExecutor/BelongsToManyTest.php @@ -73,7 +73,7 @@ protected function setUp(): void */ public function itCanCreateWithNewBelongsToMany(): void { - $this->query(' + $this->graphQL(' mutation { createRole(input: { name: "foobar" @@ -118,7 +118,7 @@ public function itCanCreateAndConnectWithBelongsToMany(): void factory(User::class)->create(['name' => 'user_one']); factory(User::class)->create(['name' => 'user_two']); - $this->query(' + $this->graphQL(' mutation { createRole(input: { name: "foobar" @@ -165,7 +165,7 @@ public function itCanCreateWithBelongsToMany(): void 'name' => 'is_admin', ]); - $this->query(' + $this->graphQL(' mutation { updateRole(input: { id: 1 @@ -226,7 +226,7 @@ public function itCanUpdateWithBelongsToMany(): void factory(User::class, 2)->create() ); - $this->query(' + $this->graphQL(' mutation { updateRole(input: { id: 1 @@ -289,7 +289,7 @@ public function itCanDeleteWithBelongsToMany(): void factory(User::class, 2)->create() ); - $this->query(' + $this->graphQL(' mutation { updateRole(input: { id: 1 @@ -341,7 +341,7 @@ public function itCanConnectWithBelongsToMany(): void factory(User::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateRole(input: { id: 1 @@ -390,7 +390,7 @@ public function itCanSyncWithBelongsToMany(): void factory(User::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateRole(input: { id: 1 @@ -438,7 +438,7 @@ public function itCanDisconnectWithBelongsToMany(): void factory(User::class, 2)->create() ); - $this->query(' + $this->graphQL(' mutation { updateRole(input: { id: 1 @@ -480,7 +480,7 @@ public function itCanSyncExistingUsersDuringCreateToABelongsToManyRelation(): vo { factory(User::class, 2)->create(); - $this->query(' + $this->graphQL(' mutation { createRole(input: { name: "foobar" diff --git a/tests/Integration/Execution/MutationExecutor/BelongsToTest.php b/tests/Integration/Execution/MutationExecutor/BelongsToTest.php index 68fcd1bc50..dc53c263be 100644 --- a/tests/Integration/Execution/MutationExecutor/BelongsToTest.php +++ b/tests/Integration/Execution/MutationExecutor/BelongsToTest.php @@ -71,7 +71,7 @@ public function itCanCreateAndConnectWithBelongsTo(): void { factory(User::class)->create(); - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "foo" @@ -104,7 +104,7 @@ public function itCanCreateAndConnectWithBelongsTo(): void */ public function itCanCreateWithNewBelongsTo(): void { - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "foo" @@ -143,7 +143,7 @@ public function itCanCreateAndUpdateBelongsTo(): void 'name' => 'foo', ]); - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "foo" @@ -183,7 +183,7 @@ public function itCanUpdateAndDisconnectBelongsTo(): void { factory(Task::class)->create(); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 @@ -227,7 +227,7 @@ public function itCanUpdateAndDeleteBelongsTo(): void { factory(Task::class)->create(); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 @@ -271,7 +271,7 @@ public function itDoesNotDeleteOrDisconnectOnFalsyValues(): void { factory(Task::class)->create(); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 diff --git a/tests/Integration/Execution/MutationExecutor/HasManyTest.php b/tests/Integration/Execution/MutationExecutor/HasManyTest.php index 187e8a390e..29f0e271ea 100644 --- a/tests/Integration/Execution/MutationExecutor/HasManyTest.php +++ b/tests/Integration/Execution/MutationExecutor/HasManyTest.php @@ -68,7 +68,7 @@ protected function setUp(): void */ public function itCanCreateWithNewHasMany(): void { - $this->query(' + $this->graphQL(' mutation { createUser(input: { name: "foo" @@ -109,7 +109,7 @@ public function itCanCreateHasMany(): void { factory(User::class)->create(); - $this->query(' + $this->graphQL(' mutation { updateUser(input: { id: 1 @@ -156,7 +156,7 @@ public function itCanUpdateHasMany(): void factory(Task::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateUser(input: { id: 1 @@ -204,7 +204,7 @@ public function itCanDeleteHasMany(): void factory(Task::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateUser(input: { id: 1 diff --git a/tests/Integration/Execution/MutationExecutor/HasOneTest.php b/tests/Integration/Execution/MutationExecutor/HasOneTest.php index 61689d5b2c..7967128ee0 100644 --- a/tests/Integration/Execution/MutationExecutor/HasOneTest.php +++ b/tests/Integration/Execution/MutationExecutor/HasOneTest.php @@ -69,7 +69,7 @@ protected function setUp(): void */ public function itCanCreateWithNewHasOne(): void { - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "foo" @@ -108,7 +108,7 @@ public function itCanUpdateWithNewHasOne(): void { factory(Task::class)->create(); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 @@ -153,7 +153,7 @@ public function itCanUpdateAndUpdateHasOne(): void factory(Post::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 @@ -199,7 +199,7 @@ public function itCanUpdateAndDeleteHasOne(): void factory(Post::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 diff --git a/tests/Integration/Execution/MutationExecutor/MorphManyTest.php b/tests/Integration/Execution/MutationExecutor/MorphManyTest.php index d42f59daca..b3156eb40c 100644 --- a/tests/Integration/Execution/MutationExecutor/MorphManyTest.php +++ b/tests/Integration/Execution/MutationExecutor/MorphManyTest.php @@ -67,7 +67,7 @@ protected function setUp(): void */ public function itCanCreateWithNewMorphMany(): void { - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "foo" @@ -106,7 +106,7 @@ public function itCanUpdateWithNewMorphMany(): void { factory(Task::class)->create(); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 @@ -151,7 +151,7 @@ public function itCanUpdateAndUpdateMorphMany(): void factory(Hour::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 @@ -197,7 +197,7 @@ public function itCanUpdateAndDeleteMorphMany(): void factory(Hour::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 diff --git a/tests/Integration/Execution/MutationExecutor/MorphOneTest.php b/tests/Integration/Execution/MutationExecutor/MorphOneTest.php index ed250b361d..a875d55923 100644 --- a/tests/Integration/Execution/MutationExecutor/MorphOneTest.php +++ b/tests/Integration/Execution/MutationExecutor/MorphOneTest.php @@ -67,7 +67,7 @@ protected function setUp(): void */ public function itCanCreateWithNewMorphOne(): void { - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "foo" @@ -104,7 +104,7 @@ public function itCanUpdateWithNewMorphOne(): void { factory(Task::class)->create(); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 @@ -147,7 +147,7 @@ public function itCanUpdateAndUpdateMorphOne(): void factory(Hour::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 @@ -191,7 +191,7 @@ public function itCanUpdateAndDeleteMorphOne(): void factory(Hour::class)->create() ); - $this->query(' + $this->graphQL(' mutation { updateTask(input: { id: 1 diff --git a/tests/Integration/Execution/MutationExecutor/MorphToManyTest.php b/tests/Integration/Execution/MutationExecutor/MorphToManyTest.php index 7ff742f971..9c5db9fb04 100644 --- a/tests/Integration/Execution/MutationExecutor/MorphToManyTest.php +++ b/tests/Integration/Execution/MutationExecutor/MorphToManyTest.php @@ -53,7 +53,7 @@ public function itCanCreateATaskWithExistingTagsByUsingConnect(): void { $id = factory(Tag::class)->create(['name' => 'php'])->id; - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "Finish tests" @@ -86,7 +86,7 @@ public function itCanCreateATaskWithExistingTagsByUsingSync(): void { $id = factory(Tag::class)->create(['name' => 'php'])->id; - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "Finish tests" @@ -117,7 +117,7 @@ public function itCanCreateATaskWithExistingTagsByUsingSync(): void */ public function itCanCreateANewTagRelationByUsingCreate(): void { - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "Finish tests" diff --git a/tests/Integration/Execution/MutationExecutor/MorphToTest.php b/tests/Integration/Execution/MutationExecutor/MorphToTest.php index baff331ace..bf29618f66 100644 --- a/tests/Integration/Execution/MutationExecutor/MorphToTest.php +++ b/tests/Integration/Execution/MutationExecutor/MorphToTest.php @@ -46,7 +46,7 @@ public function itCanCreateAndConnectWithMorphTo(): void { factory(Task::class)->create(['name' => 'first_task']); - $this->query(' + $this->graphQL(' mutation { createHour(input: { hourable_type: "Tests\\\Utils\\\Models\\\Task" diff --git a/tests/Integration/Execution/QueryFilterTest.php b/tests/Integration/Execution/QueryFilterTest.php index 16f4b7389f..7ffa55274a 100644 --- a/tests/Integration/Execution/QueryFilterTest.php +++ b/tests/Integration/Execution/QueryFilterTest.php @@ -61,7 +61,7 @@ public function itCanAttachWhereBetweenFilterToQuery(): void $start = now()->subDay()->startOfDay()->format('Y-m-d H:i:s'); $end = now()->subDay()->endOfDay()->format('Y-m-d H:i:s'); - $this->query(' + $this->graphQL(' { users(count: 5 start: "'.$start.'" end: "'.$end.'") { data { @@ -103,7 +103,7 @@ public function itCanAttachWhereNotBetweenFilterToQuery(): void $start = now()->subDay()->startOfDay()->format('Y-m-d H:i:s'); $end = now()->subDay()->endOfDay()->format('Y-m-d H:i:s'); - $this->query(' + $this->graphQL(' { users(count: 5 start: "'.$start.'" end: "'.$end.'") { data { diff --git a/tests/Integration/GraphQLTest.php b/tests/Integration/GraphQLTest.php index 5dca3c3607..c5a9cd2368 100644 --- a/tests/Integration/GraphQLTest.php +++ b/tests/Integration/GraphQLTest.php @@ -69,7 +69,7 @@ protected function setUp(): void */ public function itResolvesQueryViaPostRequest(): void { - $this->query(' + $this->graphQL(' query UserWithTasks { user { email @@ -203,7 +203,7 @@ public function itResolvesNamedOperation(): void */ public function itRejectsInvalidQuery(): void { - $result = $this->query(' + $result = $this->graphQL(' { nonExistingField } @@ -233,7 +233,7 @@ public function itIgnoresInvalidJSONVariables(): void */ public function itResolvesQueryViaMultipartRequest(): void { - $this->postGraphQLMultipart( + $this->multipartGraphQL( [ 'operations' => /* @lang JSON */ ' @@ -261,7 +261,7 @@ public function itResolvesQueryViaMultipartRequest(): void */ public function itResolvesUploadViaMultipartRequest(): void { - $this->postGraphQLMultipart( + $this->multipartGraphQL( [ 'operations' => /* @lang JSON */ ' @@ -295,7 +295,7 @@ public function itResolvesUploadViaMultipartRequest(): void */ public function itResolvesUploadViaBatchedMultipartRequest(): void { - $this->postGraphQLMultipart( + $this->multipartGraphQL( [ 'operations' => /* @lang JSON */ ' diff --git a/tests/Integration/MultipleRequestsTest.php b/tests/Integration/MultipleRequestsTest.php index adf005a11f..cf3982180f 100644 --- a/tests/Integration/MultipleRequestsTest.php +++ b/tests/Integration/MultipleRequestsTest.php @@ -17,7 +17,7 @@ public function itCanFireMultipleRequestsInOneTest(): void } '; - $this->query(' + $this->graphQL(' { return(this: "foo") } @@ -27,7 +27,7 @@ public function itCanFireMultipleRequestsInOneTest(): void ], ]); - $this->query(' + $this->graphQL(' { return(this: "bar") } diff --git a/tests/Integration/Schema/Directives/AllDirectiveTest.php b/tests/Integration/Schema/Directives/AllDirectiveTest.php index ff4069a205..f6a0f36a36 100644 --- a/tests/Integration/Schema/Directives/AllDirectiveTest.php +++ b/tests/Integration/Schema/Directives/AllDirectiveTest.php @@ -26,7 +26,7 @@ public function itCanGetAllModelsAsRootField(): void } '; - $this->query(' + $this->graphQL(' { users { id @@ -60,7 +60,7 @@ public function itCanGetAllAsNestedField(): void } '; - $this->query(' + $this->graphQL(' { users { posts { @@ -115,7 +115,7 @@ public function itCanGetAllModelsFiltered(): void } '; - $this->query(' + $this->graphQL(' { users(name: "'.$userName.'") { id diff --git a/tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php b/tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php index 7020fb38a6..8096093bf4 100644 --- a/tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php +++ b/tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php @@ -62,7 +62,7 @@ public function itCanQueryBelongsToManyRelationship(): void } '; - $this->query(' + $this->graphQL(' { user { roles { @@ -93,7 +93,7 @@ public function itCanQueryBelongsToManyPaginator(): void } '; - $this->query(' + $this->graphQL(' { user { roles(count: 2) { @@ -143,7 +143,7 @@ public function itCanQueryBelongsToManyRelayConnection(): void } '; - $this->query(' + $this->graphQL(' { user { roles(first: 2) { @@ -202,7 +202,7 @@ public function itCanQueryBelongsToManyNestedRelationships(): void } '; - $result = $this->query(' + $result = $this->graphQL(' { user { roles(first: 2) { diff --git a/tests/Integration/Schema/Directives/BelongsToTest.php b/tests/Integration/Schema/Directives/BelongsToTest.php index 8d2039b1b6..3d6db323e3 100644 --- a/tests/Integration/Schema/Directives/BelongsToTest.php +++ b/tests/Integration/Schema/Directives/BelongsToTest.php @@ -64,7 +64,7 @@ public function itCanResolveBelongsToRelationship(): void } '; - $this->query(' + $this->graphQL(' { user { company { @@ -104,7 +104,7 @@ public function itCanResolveBelongsToWithCustomName(): void } '; - $this->query(' + $this->graphQL(' { user { account { @@ -149,7 +149,7 @@ public function itCanResolveBelongsToRelationshipWithTwoRelation(): void } '; - $this->query(' + $this->graphQL(' { user { company { @@ -202,7 +202,7 @@ public function itCanResolveBelongsToRelationshipWhenMainModelHasCompositePrimar } '; - $this->query(' + $this->graphQL(' { products(count: 2) { data{ diff --git a/tests/Integration/Schema/Directives/BuilderDirectiveTest.php b/tests/Integration/Schema/Directives/BuilderDirectiveTest.php index 075cdb0741..0c9561686b 100644 --- a/tests/Integration/Schema/Directives/BuilderDirectiveTest.php +++ b/tests/Integration/Schema/Directives/BuilderDirectiveTest.php @@ -26,7 +26,7 @@ public function itCallsCustomBuilderMethod(): void factory(User::class, 2)->create(); - $this->query(' + $this->graphQL(' { users(limit: 1) { id diff --git a/tests/Integration/Schema/Directives/CacheDirectiveTest.php b/tests/Integration/Schema/Directives/CacheDirectiveTest.php index 9375d9a9da..aa45326595 100644 --- a/tests/Integration/Schema/Directives/CacheDirectiveTest.php +++ b/tests/Integration/Schema/Directives/CacheDirectiveTest.php @@ -40,7 +40,7 @@ public function itCanStoreResolverResultInCache(): void } "; - $this->query(' + $this->graphQL(' { user { name @@ -74,7 +74,7 @@ public function itCanPlaceCacheKeyOnAnyField(): void } "; - $this->query(' + $this->graphQL(' { user { name @@ -111,7 +111,7 @@ public function itCanStoreResolverResultInPrivateCache(): void } "; - $this->query(' + $this->graphQL(' { user { name @@ -146,7 +146,7 @@ public function itCanStorePaginateResolverInCache(): void } '; - $this->query(' + $this->graphQL(' { users(count: 5) { data { @@ -212,13 +212,13 @@ public function itCanCacheHasManyResolver(): void } }); - $firstResponse = $this->query($query); + $firstResponse = $this->graphQL($query); $posts = $this->cache->get("user:{$user->getKey()}:posts:count:3"); $this->assertInstanceOf(LengthAwarePaginator::class, $posts); $this->assertCount(3, $posts); - $cachedResponse = $this->query($query); + $cachedResponse = $this->graphQL($query); $this->assertSame(1, $dbQueryCountForPost, 'This query should only run once and be cached on the second run.'); $this->assertSame( @@ -279,13 +279,13 @@ public function itCanAttachTagsToCache(): void } }); - $firstResponse = $this->query($query); + $firstResponse = $this->graphQL($query); $posts = $this->cache->tags($tags)->get("user:{$user->getKey()}:posts:count:3"); $this->assertInstanceOf(LengthAwarePaginator::class, $posts); $this->assertCount(3, $posts); - $cachedResponse = $this->query($query); + $cachedResponse = $this->graphQL($query); $this->assertSame(1, $dbQueryCountForPost, 'This query should only run once and be cached on the second run.'); $this->assertSame( diff --git a/tests/Integration/Schema/Directives/CreateDirectiveTest.php b/tests/Integration/Schema/Directives/CreateDirectiveTest.php index 1f0f956536..973465f7ab 100644 --- a/tests/Integration/Schema/Directives/CreateDirectiveTest.php +++ b/tests/Integration/Schema/Directives/CreateDirectiveTest.php @@ -25,7 +25,7 @@ public function itCanCreateFromFieldArguments(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { createCompany(name: "foo") { id @@ -62,7 +62,7 @@ public function itCanCreateFromInputObject(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { createCompany(input: { name: "foo" @@ -97,7 +97,7 @@ public function itCreatesAnEntryWithDatabaseDefaultsAndReturnsItImmediately(): v } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { createTag(name: "foobar"){ name @@ -154,7 +154,7 @@ public function itDoesNotCreateWithFailingRelationship(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { createUser(input: { name: "foo" @@ -224,7 +224,7 @@ public function itDoesCreateWithFailingRelationshipAndTransactionParam(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { createUser(input: { name: "foo" @@ -294,7 +294,7 @@ public function itDoesNotFailWhenPropertyNameMatchesModelsNativeMethods(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { createUser(input: { name: "foo" diff --git a/tests/Integration/Schema/Directives/DeleteDirectiveTest.php b/tests/Integration/Schema/Directives/DeleteDirectiveTest.php index 77b61e0067..762aa1a0f0 100644 --- a/tests/Integration/Schema/Directives/DeleteDirectiveTest.php +++ b/tests/Integration/Schema/Directives/DeleteDirectiveTest.php @@ -25,7 +25,7 @@ public function itDeletesUserAndReturnsIt(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { deleteUser(id: 1) { id @@ -60,7 +60,7 @@ public function itDeletesMultipleUsersAndReturnsThem(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { deleteUsers(id: [1, 2]) { name @@ -89,7 +89,7 @@ public function itRejectsDefinitionWithNullableArgument(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { deleteUser(id: 1) { name @@ -116,7 +116,7 @@ public function itRejectsDefinitionWithNoArgument(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { deleteUser { name @@ -143,7 +143,7 @@ public function itRejectsDefinitionWithMultipleArguments(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { deleteUser { name diff --git a/tests/Integration/Schema/Directives/EventDirectiveTest.php b/tests/Integration/Schema/Directives/EventDirectiveTest.php index 2c6e284183..e22b3c7890 100644 --- a/tests/Integration/Schema/Directives/EventDirectiveTest.php +++ b/tests/Integration/Schema/Directives/EventDirectiveTest.php @@ -43,7 +43,7 @@ public function itDispatchesAnEvent(string $argumentName): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { createCompany(name: "foo") { id diff --git a/tests/Integration/Schema/Directives/FindDirectiveTest.php b/tests/Integration/Schema/Directives/FindDirectiveTest.php index 310a60dee7..a15ce2e206 100644 --- a/tests/Integration/Schema/Directives/FindDirectiveTest.php +++ b/tests/Integration/Schema/Directives/FindDirectiveTest.php @@ -28,7 +28,7 @@ public function itReturnsSingleUser(): void } '; - $this->query(" + $this->graphQL(" { user(id:{$userB->id}) { name @@ -60,7 +60,7 @@ public function itDefaultsToFieldTypeIfNoModelIsSupplied(): void } '; - $this->query(" + $this->graphQL(" { user(id:{$userA->id}) { name @@ -91,7 +91,7 @@ public function itCannotFetchIfMultipleModelsMatch(): void } '; - $this->query(' + $this->graphQL(' { user(name: "A") { name @@ -126,7 +126,7 @@ public function itCanUseScopes(): void } '; - $this->query(' + $this->graphQL(' { user(name: "A" company: "CompanyA") { id @@ -159,7 +159,7 @@ public function itReturnsAnEmptyObjectWhenTheModelIsNotFound(): void } '; - $this->query(' + $this->graphQL(' { user(name: "A") { id diff --git a/tests/Integration/Schema/Directives/FirstDirectiveTest.php b/tests/Integration/Schema/Directives/FirstDirectiveTest.php index 8bfa06bef1..c3921365da 100644 --- a/tests/Integration/Schema/Directives/FirstDirectiveTest.php +++ b/tests/Integration/Schema/Directives/FirstDirectiveTest.php @@ -27,7 +27,7 @@ public function itReturnsASingleUser(): void $userB = factory(User::class)->create(['name' => 'B']); $userC = factory(User::class)->create(['name' => 'C']); - $this->query(" + $this->graphQL(" { user(id: {$userB->id}){ name @@ -62,7 +62,7 @@ public function itReturnsASingleUserWhenMultiplesMatch(): void $userB = factory(User::class)->create(['name' => 'A']); $userC = factory(User::class)->create(['name' => 'B']); - $this->query(' + $this->graphQL(' { user(name: "A") { id diff --git a/tests/Integration/Schema/Directives/HasManyDirectiveTest.php b/tests/Integration/Schema/Directives/HasManyDirectiveTest.php index 92da8de990..f82aed5e9d 100644 --- a/tests/Integration/Schema/Directives/HasManyDirectiveTest.php +++ b/tests/Integration/Schema/Directives/HasManyDirectiveTest.php @@ -68,7 +68,7 @@ public function itCanQueryHasManyRelationship(): void $this->assertSame(4, $tasksWithoutGlobalScope); // Ensure global scopes are respected here - $this->query(' + $this->graphQL(' { user { tasks { @@ -101,7 +101,7 @@ public function itCallsScopeWithResolverArgs(): void } '; - $this->query(' + $this->graphQL(' { user { tasks(foo: 2) { @@ -136,7 +136,7 @@ public function itCanQueryHasManyPaginator(): void } '; - $this->query(' + $this->graphQL(' { user { tasks(count: 2) { @@ -187,7 +187,7 @@ public function paginatorTypeIsLimitedByMaxCountFromDirective(): void } '; - $result = $this->query(' + $result = $this->graphQL(' { user { tasks(count: 5) { @@ -225,7 +225,7 @@ public function itHandlesPaginationWithCountZero(): void } '; - $this->query(' + $this->graphQL(' { user { id @@ -267,7 +267,7 @@ public function relayTypeIsLimitedByMaxCountFromDirective(): void } '; - $result = $this->query(' + $result = $this->graphQL(' { user { tasks(first: 5) { @@ -308,7 +308,7 @@ public function paginatorTypeIsLimitedToMaxCountFromConfig(): void } '; - $result = $this->query(' + $result = $this->graphQL(' { user { tasks(count: 3) { @@ -347,7 +347,7 @@ public function relayTypeIsLimitedToMaxCountFromConfig(): void } '; - $result = $this->query(' + $result = $this->graphQL(' { user { tasks(first: 3) { @@ -386,7 +386,7 @@ public function itCanQueryHasManyPaginatorWithADefaultCount(): void } '; - $this->query(' + $this->graphQL(' { user { tasks { @@ -435,7 +435,7 @@ public function itCanQueryHasManyRelayConnection(): void } '; - $this->query(' + $this->graphQL(' { user { tasks(first: 2) { @@ -482,7 +482,7 @@ public function itCanQueryHasManyRelayConnectionWithADefaultCount(): void } '; - $this->query(' + $this->graphQL(' { user { tasks { @@ -530,7 +530,7 @@ public function itCanQueryHasManyNestedRelationships(): void } '; - $this->query(' + $this->graphQL(' { user { tasks(first: 2) { @@ -598,7 +598,7 @@ public function itCanQueryHasManySelfReferencingRelationships(): void } '; - $this->query(' + $this->graphQL(' { posts { id diff --git a/tests/Integration/Schema/Directives/HasOneDirectiveTest.php b/tests/Integration/Schema/Directives/HasOneDirectiveTest.php index 28727a2f30..3b373a525b 100644 --- a/tests/Integration/Schema/Directives/HasOneDirectiveTest.php +++ b/tests/Integration/Schema/Directives/HasOneDirectiveTest.php @@ -32,7 +32,7 @@ public function itCanQueryHasOneRelationship(): void } '; - $this->query(' + $this->graphQL(' { tasks { post { diff --git a/tests/Integration/Schema/Directives/InjectDirectiveTest.php b/tests/Integration/Schema/Directives/InjectDirectiveTest.php index 3b99433c03..5b69894e84 100644 --- a/tests/Integration/Schema/Directives/InjectDirectiveTest.php +++ b/tests/Integration/Schema/Directives/InjectDirectiveTest.php @@ -35,7 +35,7 @@ public function itCanCreateFromInputObjectWithDeepInjection(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { createTask(input: { name: "foo" diff --git a/tests/Integration/Schema/Directives/PaginateDirectiveTest.php b/tests/Integration/Schema/Directives/PaginateDirectiveTest.php index 7e38ecc077..e1d063155b 100644 --- a/tests/Integration/Schema/Directives/PaginateDirectiveTest.php +++ b/tests/Integration/Schema/Directives/PaginateDirectiveTest.php @@ -29,7 +29,7 @@ public function itCanCreateQueryPaginators(): void } '; - $this->query(' + $this->graphQL(' { users(count: 5) { paginatorInfo { @@ -73,7 +73,7 @@ public function itHandlesPaginationWithCountZero(): void } '; - $this->query(' + $this->graphQL(' { users(count: 0) { data { @@ -109,7 +109,7 @@ public function itCanSpecifyCustomBuilder(): void '; // The custom builder is supposed to change the sort order - $this->query(' + $this->graphQL(' { users(count: 1) { data { @@ -169,7 +169,7 @@ public function itCanCreateQueryPaginatorsWithDifferentPages(): void } '; - $this->query(' + $this->graphQL(' { users(count: 3, page: 1) { paginatorInfo { @@ -244,7 +244,7 @@ public function itCanCreateQueryConnections(): void } '; - $this->query(' + $this->graphQL(' { users(first: 5) { pageInfo { @@ -285,7 +285,7 @@ public function itQueriesConnectionWithNoData(): void } '; - $this->query(' + $this->graphQL(' { users(first: 5) { pageInfo { @@ -339,7 +339,7 @@ public function itQueriesPaginationWithNoData(): void } '; - $this->query(' + $this->graphQL(' { users(count: 5) { paginatorInfo { @@ -393,7 +393,7 @@ public function itPaginatesWhenDefinedInTypeExtension(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' { users(count: 1) { data { @@ -423,7 +423,7 @@ public function itCanHaveADefaultPaginationCount(): void } '; - $this->query(' + $this->graphQL(' { users { paginatorInfo { @@ -469,7 +469,7 @@ public function itIsLimitedToMaxCountFromConfig(): void } '; - $resultFromDefaultPagination = $this->query(' + $resultFromDefaultPagination = $this->graphQL(' { users1(count: 10) { data { @@ -485,7 +485,7 @@ public function itIsLimitedToMaxCountFromConfig(): void $resultFromDefaultPagination->jsonGet('errors.0.message') ); - $resultFromRelayPagination = $this->query(' + $resultFromRelayPagination = $this->graphQL(' { users2(first: 10) { edges { @@ -525,7 +525,7 @@ public function itIsLimitedByMaxCountFromDirective(): void } '; - $result = $this->query(' + $result = $this->graphQL(' { users1(count: 10) { data { @@ -541,7 +541,7 @@ public function itIsLimitedByMaxCountFromDirective(): void $result->jsonGet('errors.0.message') ); - $this->query(' + $this->graphQL(' { users2(count: 10) { data { diff --git a/tests/Integration/Schema/Directives/SearchDirectiveTest.php b/tests/Integration/Schema/Directives/SearchDirectiveTest.php index 4fdf85ba7e..a79387be91 100644 --- a/tests/Integration/Schema/Directives/SearchDirectiveTest.php +++ b/tests/Integration/Schema/Directives/SearchDirectiveTest.php @@ -65,7 +65,7 @@ public function canSearch(): void } '; - $this->query(' + $this->graphQL(' { posts(count: 10 search: "great") { data { @@ -135,7 +135,7 @@ function ($argument) { } '; - $this->query(' + $this->graphQL(' { posts(count: 10 search: "great") { data { @@ -201,7 +201,7 @@ public function itHandlesScoutBuilderPaginationArguments(): void } '; - $this->query(' + $this->graphQL(' { posts(count: 10 search: "great") { data { diff --git a/tests/Integration/Schema/Directives/TrimDirectiveTest.php b/tests/Integration/Schema/Directives/TrimDirectiveTest.php index 9c4c0a3537..2693d05174 100644 --- a/tests/Integration/Schema/Directives/TrimDirectiveTest.php +++ b/tests/Integration/Schema/Directives/TrimDirectiveTest.php @@ -22,7 +22,7 @@ public function itTrimsInput(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { createCompany(name: " foo ") { id diff --git a/tests/Integration/Schema/Directives/UpdateDirectiveTest.php b/tests/Integration/Schema/Directives/UpdateDirectiveTest.php index 720d32df9a..ab05417cdc 100644 --- a/tests/Integration/Schema/Directives/UpdateDirectiveTest.php +++ b/tests/Integration/Schema/Directives/UpdateDirectiveTest.php @@ -30,7 +30,7 @@ public function itCanUpdateFromFieldArguments(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { updateCompany( id: 1 @@ -76,7 +76,7 @@ public function itCanUpdateFromInputObject(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { updateCompany(input: { id: 1 @@ -118,7 +118,7 @@ public function itCanUpdateWithCustomPrimaryKey(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { updateCategory( category_id: 1 @@ -178,7 +178,7 @@ public function itDoesNotUpdateWithFailingRelationship(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' mutation { updateUser(input: { id: 1 diff --git a/tests/Integration/Schema/Directives/WithDirectiveTest.php b/tests/Integration/Schema/Directives/WithDirectiveTest.php index a12b33c59b..8b27c47022 100644 --- a/tests/Integration/Schema/Directives/WithDirectiveTest.php +++ b/tests/Integration/Schema/Directives/WithDirectiveTest.php @@ -58,7 +58,7 @@ public function itCanQueryARelationship(): void $user->relationLoaded('tasks') ); - $this->query(' + $this->graphQL(' { user { task_count_string diff --git a/tests/Integration/Schema/NodeInterfaceTest.php b/tests/Integration/Schema/NodeInterfaceTest.php index 8ac2abc35e..2176ab30d0 100644 --- a/tests/Integration/Schema/NodeInterfaceTest.php +++ b/tests/Integration/Schema/NodeInterfaceTest.php @@ -48,7 +48,7 @@ public function itCanResolveNodes(): void $firstGlobalId = $this->globalIdResolver->encode('User', $this->testTuples[1]['id']); $secondGlobalId = $this->globalIdResolver->encode('User', $this->testTuples[2]['id']); - $this->query(' + $this->graphQL(' { first: node(id: "'.$firstGlobalId.'") { id @@ -102,7 +102,7 @@ public function itCanResolveModelsNodes(): void ); $globalId = $this->globalIdResolver->encode('User', $user->getKey()); - $this->query(' + $this->graphQL(' { node(id: "'.$globalId.'") { id diff --git a/tests/Integration/Schema/Types/InterfaceTest.php b/tests/Integration/Schema/Types/InterfaceTest.php index 16dae86f39..6e9173319f 100644 --- a/tests/Integration/Schema/Types/InterfaceTest.php +++ b/tests/Integration/Schema/Types/InterfaceTest.php @@ -38,7 +38,7 @@ interface Nameable { } '; - $result = $this->query(' + $result = $this->graphQL(' { namedThings { name @@ -84,7 +84,7 @@ interface Nameable @interface(resolveType: "'.$this->qualifyTestResolver('resolv } '; - $this->query(' + $this->graphQL(' { namedThings { name @@ -127,7 +127,7 @@ interface Nameable { } '; - $result = $this->query('{ + $result = $this->graphQL('{ __schema { types { kind diff --git a/tests/Integration/Schema/Types/UnionTest.php b/tests/Integration/Schema/Types/UnionTest.php index f8daaf3329..546824876c 100644 --- a/tests/Integration/Schema/Types/UnionTest.php +++ b/tests/Integration/Schema/Types/UnionTest.php @@ -26,7 +26,7 @@ public function itCanResolveUnionTypes(string $schema, string $query): void $this->schema = $schema; - $this->query($query)->assertJsonStructure([ + $this->graphQL($query)->assertJsonStructure([ 'data' => [ 'stuff' => [ [ diff --git a/tests/Integration/Subscriptions/SubscriptionTest.php b/tests/Integration/Subscriptions/SubscriptionTest.php index 0b97558eb2..d7be29144c 100644 --- a/tests/Integration/Subscriptions/SubscriptionTest.php +++ b/tests/Integration/Subscriptions/SubscriptionTest.php @@ -101,7 +101,7 @@ public function itSendsSubscriptionChannelInBatchedResponse(): void public function itCanBroadcastSubscriptions(): void { $this->subscribe(); - $this->query(' + $this->graphQL(' mutation { createPost(post: "Foobar") { body @@ -123,7 +123,7 @@ public function itCanBroadcastSubscriptions(): void */ public function itThrowsWithMissingOperationName(): void { - $this->query(' + $this->graphQL(' subscription { onPostCreated { body diff --git a/tests/Integration/Tracing/TracingExtensionTest.php b/tests/Integration/Tracing/TracingExtensionTest.php index 7782cfcffb..0f8e52c64c 100644 --- a/tests/Integration/Tracing/TracingExtensionTest.php +++ b/tests/Integration/Tracing/TracingExtensionTest.php @@ -26,7 +26,7 @@ protected function getPackageProviders($app) */ public function itCanAddTracingExtensionMetaToResult(): void { - $this->query(' + $this->graphQL(' { foo } diff --git a/tests/Integration/ValidationTest.php b/tests/Integration/ValidationTest.php index 13d54bd287..aee8756bf6 100644 --- a/tests/Integration/ValidationTest.php +++ b/tests/Integration/ValidationTest.php @@ -82,7 +82,7 @@ public function resolveEmail($root, array $args): string */ public function itValidatesDifferentPathsIndividually(): void { - $result = $this->query(' + $result = $this->graphQL(' { foo( input: [ @@ -118,7 +118,7 @@ public function itValidatesDifferentPathsIndividually(): void */ public function itValidatesList(): void { - $result = $this->query(' + $result = $this->graphQL(' { foo( list: [ @@ -143,7 +143,7 @@ public function itValidatesList(): void */ public function itValidatesInputCount(): void { - $result = $this->query(' + $result = $this->graphQL(' { foo( stringList: [ @@ -184,7 +184,7 @@ public function itValidatesInputCount(): void */ public function itPassesIfNothingRequiredIsMissing(): void { - $this->query(' + $this->graphQL(' { foo(required: "foo") } @@ -200,7 +200,7 @@ public function itPassesIfNothingRequiredIsMissing(): void */ public function itEvaluatesArgDirectivesInDefinitionOrder(): void { - $validPasswordResult = $this->query(' + $validPasswordResult = $this->graphQL(' { password(password: " 1234567 ") } @@ -210,7 +210,7 @@ public function itEvaluatesArgDirectivesInDefinitionOrder(): void $this->assertNotSame(' 1234567 ', $password); $this->assertTrue(password_verify('1234567', $password)); - $invalidPasswordResult = $this->query(' + $invalidPasswordResult = $this->graphQL(' { password(password: " 1234 ") } @@ -228,7 +228,7 @@ public function itEvaluatesArgDirectivesInDefinitionOrder(): void */ public function itEvaluatesConditionalValidation(): void { - $validPasswordResult = $this->query(' + $validPasswordResult = $this->graphQL(' { password } @@ -236,7 +236,7 @@ public function itEvaluatesConditionalValidation(): void $this->assertSame('no-password', $validPasswordResult->jsonGet('data.password')); - $invalidPasswordResult = $this->query(' + $invalidPasswordResult = $this->graphQL(' { password(id: "foo") } @@ -254,7 +254,7 @@ public function itEvaluatesConditionalValidation(): void */ public function itEvaluatesInputArgValidation(): void { - $result = $this->query(' + $result = $this->graphQL(' { password(id: "bar", password: "123456") } @@ -272,7 +272,7 @@ public function itEvaluatesInputArgValidation(): void */ public function itEvaluatesNonNullInputArgValidation(): void { - $this->query(' + $this->graphQL(' { email( userId: 1 @@ -288,7 +288,7 @@ public function itEvaluatesNonNullInputArgValidation(): void ], ]); - $invalidEmailResult = $this->query(' + $invalidEmailResult = $this->graphQL(' { email( userId: 1 @@ -313,7 +313,7 @@ public function itEvaluatesNonNullInputArgValidation(): void */ public function itErrorsIfSomethingRequiredIsMissing(): void { - $result = $this->query(' + $result = $this->graphQL(' { foo } diff --git a/tests/Integration/WhereConstraints/WhereConstraintsDirectiveTest.php b/tests/Integration/WhereConstraints/WhereConstraintsDirectiveTest.php index 8ff7a08b6a..fbfe19aecb 100644 --- a/tests/Integration/WhereConstraints/WhereConstraintsDirectiveTest.php +++ b/tests/Integration/WhereConstraints/WhereConstraintsDirectiveTest.php @@ -47,7 +47,7 @@ public function itAddsASingleWhereFilter(): void { factory(User::class, 2)->create(); - $this->query(' + $this->graphQL(' { users( where: { @@ -68,7 +68,7 @@ public function itOverwritesTheOperator(): void { factory(User::class, 3)->create(); - $this->query(' + $this->graphQL(' { users( where: { @@ -90,7 +90,7 @@ public function itAddsNestedAnd(): void { factory(User::class, 3)->create(); - $this->query(' + $this->graphQL(' { users( where: { @@ -121,7 +121,7 @@ public function itAddsNestedOr(): void { factory(User::class, 3)->create(); - $this->query(' + $this->graphQL(' { users( where: { @@ -150,7 +150,7 @@ public function itAddsNestedNot(): void { factory(User::class, 3)->create(); - $this->query(' + $this->graphQL(' { users( where: { @@ -173,7 +173,7 @@ public function itAddsNestedNot(): void */ public function itRejectsInvalidColumnName(): void { - $this->query(' + $this->graphQL(' { users( where: { @@ -204,7 +204,7 @@ public function itQueriesEmptyStrings(): void 'name' => '', ]); - $this->query(' + $this->graphQL(' { users( where: { diff --git a/tests/TestCase.php b/tests/TestCase.php index 8a43bd0e9e..f9ab4c716b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -14,10 +14,13 @@ use Illuminate\Contracts\Debug\ExceptionHandler; use Nuwave\Lighthouse\LighthouseServiceProvider; use Orchestra\Testbench\TestCase as BaseTestCase; +use Nuwave\Lighthouse\Testing\MakesGraphQLRequests; use Nuwave\Lighthouse\Schema\Source\SchemaSourceProvider; abstract class TestCase extends BaseTestCase { + use MakesGraphQLRequests; + /** * This variable is injected the main GraphQL class * during execution of each test. It may be set either @@ -201,61 +204,6 @@ protected function tearDown(): void CountRuns::$runCounter = 0; } - /** - * Execute a query as if it was sent as a request to the server. - * - * @param string $query - * @return \Illuminate\Foundation\Testing\TestResponse - */ - protected function query(string $query): TestResponse - { - return $this->postGraphQL( - [ - 'query' => $query, - ] - ); - } - - /** - * Execute a query as if it was sent as a request to the server. - * - * @param mixed[] $data - * @param mixed[] $headers - * @return \Illuminate\Foundation\Testing\TestResponse - */ - protected function postGraphQL(array $data, array $headers = []): TestResponse - { - return $this->postJson( - 'graphql', - $data, - $headers - ); - } - - /** - * Send a multipart form request. - * - * This is used for file uploads conforming to the specification: - * https://github.com/jaydenseric/graphql-multipart-request-spec - * - * @param mixed[] $parameters - * @param mixed[] $files - * @return \Illuminate\Foundation\Testing\TestResponse - */ - protected function postGraphQLMultipart(array $parameters, array $files): TestResponse - { - return $this->call( - 'POST', - 'graphql', - $parameters, - [], - $files, - $this->transformHeadersToServerVars([ - 'Content-Type' => 'multipart/form-data', - ]) - ); - } - /** * Build an executable schema from a SDL string, adding on a default Query type. * diff --git a/tests/Unit/Events/ManipulatingASTTest.php b/tests/Unit/Events/ManipulatingASTTest.php index 8bf45f027e..0026962c53 100644 --- a/tests/Unit/Events/ManipulatingASTTest.php +++ b/tests/Unit/Events/ManipulatingASTTest.php @@ -28,7 +28,7 @@ public function itCanManipulateTheAST(): void ); }); - $this->query(' + $this->graphQL(' { foo } diff --git a/tests/Unit/Schema/ClientDirectiveTest.php b/tests/Unit/Schema/ClientDirectiveTest.php index d74876dd63..2503ba7d3f 100644 --- a/tests/Unit/Schema/ClientDirectiveTest.php +++ b/tests/Unit/Schema/ClientDirectiveTest.php @@ -25,7 +25,7 @@ public function itCanDefineAClientDirective(): void } '; - $this->query(' + $this->graphQL(' { foo @filter(key: "baz") } diff --git a/tests/Unit/Schema/Directives/AuthDirectiveTest.php b/tests/Unit/Schema/Directives/AuthDirectiveTest.php index 2f76dada00..a50fdcaebd 100644 --- a/tests/Unit/Schema/Directives/AuthDirectiveTest.php +++ b/tests/Unit/Schema/Directives/AuthDirectiveTest.php @@ -25,7 +25,7 @@ public function itCanResolveAuthenticatedUser(): void } '; - $this->query(' + $this->graphQL(' { user { foo @@ -59,7 +59,7 @@ public function itCanResolveAuthenticatedUserWithGuardArgument(): void } '; - $this->query(' + $this->graphQL(' { user { foo diff --git a/tests/Unit/Schema/Directives/BcryptDirectiveTest.php b/tests/Unit/Schema/Directives/BcryptDirectiveTest.php index 3626663397..b5b243d94c 100644 --- a/tests/Unit/Schema/Directives/BcryptDirectiveTest.php +++ b/tests/Unit/Schema/Directives/BcryptDirectiveTest.php @@ -27,7 +27,7 @@ public function itCanBcryptAnArgument(): void } '; - $passwordFromMutation = $this->query(' + $passwordFromMutation = $this->graphQL(' mutation { foo(bar: "password"){ bar @@ -38,7 +38,7 @@ public function itCanBcryptAnArgument(): void $this->assertNotSame('password', $passwordFromMutation); $this->assertTrue(password_verify('password', $passwordFromMutation)); - $passwordFromQuery = $this->query(' + $passwordFromQuery = $this->graphQL(' { foo(bar: "123"){ bar @@ -74,7 +74,7 @@ public function itCanBcryptAnArgumentInInputObjectAndArray(): void } '; - $result = $this->query(' + $result = $this->graphQL(' query { user(input: { password: "password" diff --git a/tests/Unit/Schema/Directives/CanDirectiveDbTest.php b/tests/Unit/Schema/Directives/CanDirectiveDbTest.php index a9ee360ba8..f7b7d3843a 100644 --- a/tests/Unit/Schema/Directives/CanDirectiveDbTest.php +++ b/tests/Unit/Schema/Directives/CanDirectiveDbTest.php @@ -38,7 +38,7 @@ public function itPassesIfModelInstanceIsNotNull(string $argumentName): void } '; - $this->query(" + $this->graphQL(" { user(id: {$user->getKey()}) { name @@ -89,7 +89,7 @@ public function itThrowsIfNotAuthorized(string $argumentName): void } '; - $this->query(" + $this->graphQL(" { post(id: {$postB->getKey()}) { title diff --git a/tests/Unit/Schema/Directives/CanDirectiveTest.php b/tests/Unit/Schema/Directives/CanDirectiveTest.php index c423729839..76ff391fca 100644 --- a/tests/Unit/Schema/Directives/CanDirectiveTest.php +++ b/tests/Unit/Schema/Directives/CanDirectiveTest.php @@ -31,7 +31,7 @@ public function itThrowsIfNotAuthorized(string $argumentName): void } '; - $this->query(' + $this->graphQL(' { user { name @@ -65,7 +65,7 @@ public function itPassesAuthIfAuthorized(string $argumentName): void } '; - $this->query(' + $this->graphQL(' { user { name @@ -105,7 +105,7 @@ public function itAcceptsGuestUser(string $argumentName): void } '; - $this->query(' + $this->graphQL(' { user { name @@ -145,7 +145,7 @@ public function itPassesMultiplePolicies(string $argumentName): void } '; - $this->query(' + $this->graphQL(' { user { name @@ -181,7 +181,7 @@ public function itProcessesTheArgsArgument(string $argumentName): void } '; - $this->query(' + $this->graphQL(' { user { name diff --git a/tests/Unit/Schema/Directives/DeprecatedDirectiveTest.php b/tests/Unit/Schema/Directives/DeprecatedDirectiveTest.php index bb791b7276..2fcacaa028 100644 --- a/tests/Unit/Schema/Directives/DeprecatedDirectiveTest.php +++ b/tests/Unit/Schema/Directives/DeprecatedDirectiveTest.php @@ -37,7 +37,7 @@ public function itCanRemoveDeprecatedFieldsFromIntrospection(): void } } '; - $this->query($introspectionQuery) + $this->graphQL($introspectionQuery) ->assertJsonCount(1, 'data.__schema.queryType.fields'); $includeDeprecatedIntrospectionQuery = ' @@ -53,7 +53,7 @@ public function itCanRemoveDeprecatedFieldsFromIntrospection(): void } } '; - $result = $this->query($includeDeprecatedIntrospectionQuery); + $result = $this->graphQL($includeDeprecatedIntrospectionQuery); $deprecatedFields = Arr::where( $result->jsonGet('data.__schema.queryType.fields'), @@ -73,7 +73,7 @@ function (array $field): bool { 'Should fallback to the default deprecation reason' ); - $this->query(' + $this->graphQL(' { foo } diff --git a/tests/Unit/Schema/Directives/FieldDirectiveTest.php b/tests/Unit/Schema/Directives/FieldDirectiveTest.php index 77e8176be3..ea034179aa 100644 --- a/tests/Unit/Schema/Directives/FieldDirectiveTest.php +++ b/tests/Unit/Schema/Directives/FieldDirectiveTest.php @@ -19,7 +19,7 @@ public function itAssignsResolverFromCombinedDefinition(): void } '; - $this->query(' + $this->graphQL(' { bar } @@ -41,7 +41,7 @@ public function itCanResolveFieldWithMergedArgs(): void } '; - $this->query(' + $this->graphQL(' { bar } @@ -63,7 +63,7 @@ public function itUsesDefaultFieldNamespace(): void } '; - $this->query(' + $this->graphQL(' { bar } @@ -87,7 +87,7 @@ public function itThrowsAnErrorOnlyOnePartIsDefined(): void } '; - $this->query(' + $this->graphQL(' { bar } diff --git a/tests/Unit/Schema/Directives/GlobalIdDirectiveTest.php b/tests/Unit/Schema/Directives/GlobalIdDirectiveTest.php index 7dcd976867..0118633810 100644 --- a/tests/Unit/Schema/Directives/GlobalIdDirectiveTest.php +++ b/tests/Unit/Schema/Directives/GlobalIdDirectiveTest.php @@ -31,7 +31,7 @@ public function itDecodesGlobalId(): void } '; - $this->query(' + $this->graphQL(' { foo } @@ -65,7 +65,7 @@ public function itDecodesGlobalIds(): void $globalId = $this->globalId->encode('Foo', 'bar'); - $this->query(" + $this->graphQL(" { foo( type: \"{$globalId}\" diff --git a/tests/Unit/Schema/Directives/GroupDirectiveTest.php b/tests/Unit/Schema/Directives/GroupDirectiveTest.php index 725535d4e5..9802f23064 100644 --- a/tests/Unit/Schema/Directives/GroupDirectiveTest.php +++ b/tests/Unit/Schema/Directives/GroupDirectiveTest.php @@ -23,7 +23,7 @@ public function itCanSetNamespaces(): void } '.$this->placeholderQuery(); - $this->query(' + $this->graphQL(' { me } @@ -33,7 +33,7 @@ public function itCanSetNamespaces(): void ], ]); - $this->query(' + $this->graphQL(' { you } @@ -55,7 +55,7 @@ public function itCanSetMiddleware(): void } '; - $this->query(' + $this->graphQL(' { me } @@ -83,7 +83,7 @@ public function itCanOverrideGroupMiddlewareInField(): void } '; - $this->query(' + $this->graphQL(' { withFoo withNothing diff --git a/tests/Unit/Schema/Directives/InjectDirectiveTest.php b/tests/Unit/Schema/Directives/InjectDirectiveTest.php index 3444b21dc3..89470eecbf 100644 --- a/tests/Unit/Schema/Directives/InjectDirectiveTest.php +++ b/tests/Unit/Schema/Directives/InjectDirectiveTest.php @@ -27,7 +27,7 @@ public function itCanInjectDataFromContextIntoArgs(): void } '; - $this->query(' + $this->graphQL(' { me { id diff --git a/tests/Unit/Schema/Directives/MethodDirectiveTest.php b/tests/Unit/Schema/Directives/MethodDirectiveTest.php index aa01037c8b..90a105efc9 100644 --- a/tests/Unit/Schema/Directives/MethodDirectiveTest.php +++ b/tests/Unit/Schema/Directives/MethodDirectiveTest.php @@ -22,7 +22,7 @@ class MethodDirectiveTest extends TestCase */ public function itWillCallAMethodToResolveField(): void { - $this->query(' + $this->graphQL(' { foo { bar @@ -42,7 +42,7 @@ public function itWillCallAMethodToResolveField(): void */ public function itWillCallAMethodWithArgsToResolveField(): void { - $this->query(' + $this->graphQL(' { foo { bar(baz: "asdf") diff --git a/tests/Unit/Schema/Directives/MiddlewareDirectiveTest.php b/tests/Unit/Schema/Directives/MiddlewareDirectiveTest.php index ea97f5d653..353330da44 100644 --- a/tests/Unit/Schema/Directives/MiddlewareDirectiveTest.php +++ b/tests/Unit/Schema/Directives/MiddlewareDirectiveTest.php @@ -29,7 +29,7 @@ public function itCallsFooMiddleware(string $query): void } '; - $this->query($query)->assertJson([ + $this->graphQL($query)->assertJson([ 'data' => [ 'foo' => 1, ], @@ -70,7 +70,7 @@ public function itWrapsExceptionFromMiddlewareInResponse(): void } '; - $this->query(' + $this->graphQL(' { foo } @@ -100,7 +100,7 @@ public function itRunsAliasedMiddleware(): void } '; - $this->query(' + $this->graphQL(' { foo } @@ -127,7 +127,7 @@ public function itRunsMiddlewareGroup(): void } '; - $this->query(' + $this->graphQL(' { foo } @@ -155,7 +155,7 @@ public function itPassesOneFieldButThrowsInAnother(): void } '; - $this->query(' + $this->graphQL(' { foo pass diff --git a/tests/Unit/Schema/Directives/OrderByDirectiveTest.php b/tests/Unit/Schema/Directives/OrderByDirectiveTest.php index e695f58680..ba8909f713 100644 --- a/tests/Unit/Schema/Directives/OrderByDirectiveTest.php +++ b/tests/Unit/Schema/Directives/OrderByDirectiveTest.php @@ -27,7 +27,7 @@ public function itCanOrderByTheGivenFieldAndSortOrderASC(): void factory(User::class)->create(['name' => 'B']); factory(User::class)->create(['name' => 'A']); - $this->query(' + $this->graphQL(' { users( orderBy: [ @@ -62,7 +62,7 @@ public function itCanOrderByTheGivenFieldAndSortOrderDESC(): void factory(User::class)->create(['name' => 'B']); factory(User::class)->create(['name' => 'A']); - $this->query(' + $this->graphQL(' { users( orderBy: [ @@ -98,7 +98,7 @@ public function itCanOrderByMultipleFields(): void factory(User::class)->create(['name' => 'A', 'team_id' => 5]); factory(User::class)->create(['name' => 'C', 'team_id' => 2]); - $this->query(' + $this->graphQL(' { users( orderBy: [ diff --git a/tests/Unit/Schema/Directives/RenameDirectiveTest.php b/tests/Unit/Schema/Directives/RenameDirectiveTest.php index cf8cfd6687..c5884c458c 100644 --- a/tests/Unit/Schema/Directives/RenameDirectiveTest.php +++ b/tests/Unit/Schema/Directives/RenameDirectiveTest.php @@ -22,7 +22,7 @@ public function itCanRenameAField(): void } "; - $this->query(' + $this->graphQL(' { bar { bar @@ -55,7 +55,7 @@ public function itThrowsAnExceptionIfNoAttributeDefined(): void } '; - $this->query(' + $this->graphQL(' { fooBar } diff --git a/tests/Unit/Schema/Directives/RulesDirectiveTest.php b/tests/Unit/Schema/Directives/RulesDirectiveTest.php index bdedf7dae2..7d9199a92d 100644 --- a/tests/Unit/Schema/Directives/RulesDirectiveTest.php +++ b/tests/Unit/Schema/Directives/RulesDirectiveTest.php @@ -78,7 +78,7 @@ protected function setUp(): void */ public function itCanValidateQueryRootFieldArguments(): void { - $this->query(' + $this->graphQL(' { foo { first_name @@ -109,7 +109,7 @@ public function itCanValidateQueryRootFieldArguments(): void 'foo' => null, ], ])->assertJson( - $this->query(' + $this->graphQL(' mutation { foo { first_name @@ -124,7 +124,7 @@ public function itCanValidateQueryRootFieldArguments(): void */ public function itCanReturnValidFieldsAndErrorMessagesForInvalidFields(): void { - $this->query(' + $this->graphQL(' { foo(bar: "foo") { first_name @@ -154,7 +154,7 @@ public function itCanReturnValidFieldsAndErrorMessagesForInvalidFields(): void ], ], ])->assertJson( - $this->query(' + $this->graphQL(' mutation { foo(bar: "foo") { first_name @@ -171,7 +171,7 @@ public function itCanReturnValidFieldsAndErrorMessagesForInvalidFields(): void */ public function itCanValidateRootMutationFieldArgs(): void { - $this->query(' + $this->graphQL(' mutation { foo { first_name @@ -185,7 +185,7 @@ public function itCanValidateRootMutationFieldArgs(): void ], ])->assertJsonCount(1, 'errors') ->assertJson( - $this->query(' + $this->graphQL(' { foo { first_name @@ -202,7 +202,7 @@ public function itCanValidateRootMutationFieldArgs(): void */ public function itCanValidateArrayType(): void { - $this->query(' + $this->graphQL(' { foo(bar: "got it") { input_object( @@ -266,7 +266,7 @@ public function itCanValidateArrayType(): void */ public function itCanReturnCorrectValidationForInputObjects(): void { - $this->query(' + $this->graphQL(' { foo(bar: "got it") { input_object( @@ -318,7 +318,7 @@ public function itCanReturnCorrectValidationForInputObjects(): void */ public function itUsesCustomRuleClass(): void { - $this->query(' + $this->graphQL(' mutation { withCustomRuleClass( rules: "baz" diff --git a/tests/Unit/Schema/Directives/SpreadDirectiveTest.php b/tests/Unit/Schema/Directives/SpreadDirectiveTest.php index 65571568c2..213063ed6f 100644 --- a/tests/Unit/Schema/Directives/SpreadDirectiveTest.php +++ b/tests/Unit/Schema/Directives/SpreadDirectiveTest.php @@ -28,7 +28,7 @@ public function itSpreadsTheInputIntoTheQuery(): void } '; - $this->query(' + $this->graphQL(' { user(input: { id: 2 @@ -66,7 +66,7 @@ public function itIgnoresSpreadedInputIfNotGiven(): void } '; - $this->query(' + $this->graphQL(' { user{ id diff --git a/tests/Unit/Schema/Execution/ContextFactoryTest.php b/tests/Unit/Schema/Execution/ContextFactoryTest.php index 4ca79dcf6f..036aa26eb2 100644 --- a/tests/Unit/Schema/Execution/ContextFactoryTest.php +++ b/tests/Unit/Schema/Execution/ContextFactoryTest.php @@ -59,7 +59,7 @@ public function itCanGenerateCustomContext(): void } "; - $this->query(' + $this->graphQL(' { context } diff --git a/tests/Unit/Schema/SecurityTest.php b/tests/Unit/Schema/SecurityTest.php index 505cff2dc3..92a7bbe68d 100644 --- a/tests/Unit/Schema/SecurityTest.php +++ b/tests/Unit/Schema/SecurityTest.php @@ -64,7 +64,7 @@ public function itCanDisableIntrospectionThroughConfig(): void protected function assertMaxQueryComplexityIs1(): void { - $result = $this->query(' + $result = $this->graphQL(' { user { name @@ -80,7 +80,7 @@ protected function assertMaxQueryComplexityIs1(): void protected function assertMaxQueryDepthIs1(): void { - $result = $this->query(' + $result = $this->graphQL(' { user { user { @@ -100,7 +100,7 @@ protected function assertMaxQueryDepthIs1(): void protected function assertIntrospectionIsDisabled(): void { - $result = $this->query(' + $result = $this->graphQL(' { __schema { queryType { diff --git a/tests/Unit/Schema/Types/LaravelEnumTypeTest.php b/tests/Unit/Schema/Types/LaravelEnumTypeTest.php index 6d2bad2c65..d6f8af8a77 100644 --- a/tests/Unit/Schema/Types/LaravelEnumTypeTest.php +++ b/tests/Unit/Schema/Types/LaravelEnumTypeTest.php @@ -45,7 +45,7 @@ public function testUseLaravelEnumType() 'type' => 'Administrator', ]; - $this->query(' + $this->graphQL(' mutation { createUser(type: Administrator) { type @@ -53,7 +53,7 @@ public function testUseLaravelEnumType() } ')->assertJsonFragment($typeAdmistrator); - $this->query(' + $this->graphQL(' { user(type: Administrator) { type