diff --git a/examples/graphql_example/graphql/example.graphqls b/examples/graphql_examples/graphql/example.graphqls similarity index 100% rename from examples/graphql_example/graphql/example.graphqls rename to examples/graphql_examples/graphql/example.graphqls diff --git a/examples/graphql_example/graphql/example_extension.base.graphqls b/examples/graphql_examples/graphql/example_extension.base.graphqls similarity index 100% rename from examples/graphql_example/graphql/example_extension.base.graphqls rename to examples/graphql_examples/graphql/example_extension.base.graphqls diff --git a/examples/graphql_example/graphql/example_extension.extension.graphqls b/examples/graphql_examples/graphql/example_extension.extension.graphqls similarity index 100% rename from examples/graphql_example/graphql/example_extension.extension.graphqls rename to examples/graphql_examples/graphql/example_extension.extension.graphqls diff --git a/examples/graphql_example/graphql_examples.info.yml b/examples/graphql_examples/graphql_examples.info.yml similarity index 100% rename from examples/graphql_example/graphql_examples.info.yml rename to examples/graphql_examples/graphql_examples.info.yml diff --git a/examples/graphql_example/src/Plugin/GraphQL/DataProducer/QueryArticles.php b/examples/graphql_examples/src/Plugin/GraphQL/DataProducer/QueryArticles.php similarity index 100% rename from examples/graphql_example/src/Plugin/GraphQL/DataProducer/QueryArticles.php rename to examples/graphql_examples/src/Plugin/GraphQL/DataProducer/QueryArticles.php diff --git a/examples/graphql_example/src/Plugin/GraphQL/Schema/ExampleSchema.php b/examples/graphql_examples/src/Plugin/GraphQL/Schema/ExampleSchema.php similarity index 100% rename from examples/graphql_example/src/Plugin/GraphQL/Schema/ExampleSchema.php rename to examples/graphql_examples/src/Plugin/GraphQL/Schema/ExampleSchema.php diff --git a/examples/graphql_example/src/Plugin/GraphQL/SchemaExtension/ExampleSchemaExtension.php b/examples/graphql_examples/src/Plugin/GraphQL/SchemaExtension/ExampleSchemaExtension.php similarity index 100% rename from examples/graphql_example/src/Plugin/GraphQL/SchemaExtension/ExampleSchemaExtension.php rename to examples/graphql_examples/src/Plugin/GraphQL/SchemaExtension/ExampleSchemaExtension.php diff --git a/examples/graphql_example/src/Wrappers/QueryConnection.php b/examples/graphql_examples/src/Wrappers/QueryConnection.php similarity index 100% rename from examples/graphql_example/src/Wrappers/QueryConnection.php rename to examples/graphql_examples/src/Wrappers/QueryConnection.php diff --git a/examples/graphql_examples/tests/src/Kernel/Schema/ExampleSchemaTest.php b/examples/graphql_examples/tests/src/Kernel/Schema/ExampleSchemaTest.php new file mode 100644 index 000000000..0f260192e --- /dev/null +++ b/examples/graphql_examples/tests/src/Kernel/Schema/ExampleSchemaTest.php @@ -0,0 +1,88 @@ + 'article', + 'name' => 'Article', + ]); + + // Create a test-server that uses the schema plugin defined in this module. + $this->createTestServer('example', '/graphql'); + } + + /** + * Test the example schema for article listing. + */ + public function testExampleSchema() : void { + // Create two authors. + $userA = User::create([ + 'name' => 'A', + ]); + $userA->save(); + + $userB = User::create([ + 'name' => 'B', + ]); + $userB->save(); + + // Create three articles. + Node::create([ + 'type' => 'article', + 'title' => 'One', + 'uid' => $userA->id(), + ])->save(); + + Node::create([ + 'type' => 'article', + 'title' => 'Two', + 'uid' => $userB->id(), + ])->save(); + + Node::create([ + 'type' => 'article', + 'title' => 'Three', + 'uid' => $userA->id(), + ])->save(); + + // Execute the query and run assertions against its response content. + $this->assertResults('{ articles { total, items { title, author } } }', [], [ + 'articles' => [ + 'total' => 3, + 'items' => [ + ['title' => 'ONE', 'author' => 'A'], + ['title' => 'TWO', 'author' => 'B'], + ['title' => 'THREE', 'author' => 'A'], + ], + ], + ], $this->defaultCacheMetaData() + ->addCacheContexts(['user.node_grants:view']) + ->addCacheTags(['node:1', 'node:2', 'node:3', 'node_list', 'user:3', 'user:4']) + ); + } + +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c5fbcb917..c8182d5cd 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -123,10 +123,10 @@ src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php src/Plugin/DataProducerPluginManager.php src/Controller/RequestController.php - examples/graphql_example/src/Wrappers/QueryConnection.php - examples/graphql_example/src/Plugin/GraphQL/DataProducer/QueryArticles.php - examples/graphql_example/src/Plugin/GraphQL/Schema/ExampleSchema.php - examples/graphql_example/src/Plugin/GraphQL/SchemaExtension/ExampleSchemaExtension.php + examples/graphql_examples/src/Wrappers/QueryConnection.php + examples/graphql_examples/src/Plugin/GraphQL/DataProducer/QueryArticles.php + examples/graphql_examples/src/Plugin/GraphQL/Schema/ExampleSchema.php + examples/graphql_examples/src/Plugin/GraphQL/SchemaExtension/ExampleSchemaExtension.php tests/src/Traits/MockingTrait.php tests/src/Traits/DataProducerExecutionTrait.php tests/src/Kernel/ResolverBuilderTest.php @@ -193,8 +193,8 @@ src/Plugin/DataProducerPluginManager.php src/Plugin/DataProducerPluginCachingInterface.php src/Controller/RequestController.php - examples/graphql_example/src/Wrappers/QueryConnection.php - examples/graphql_example/src/Plugin/GraphQL/DataProducer/QueryArticles.php + examples/graphql_examples/src/Wrappers/QueryConnection.php + examples/graphql_examples/src/Plugin/GraphQL/DataProducer/QueryArticles.php tests/src/Traits/DataProducerExecutionTrait.php tests/src/Kernel/ResolverBuilderTest.php tests/src/Kernel/DataProducer/XML/XMLTestBase.php