From 5cdb87aef0b4c2e593cb1de927063db597967811 Mon Sep 17 00:00:00 2001 From: Constantin Bosneaga Date: Sun, 5 Feb 2023 11:56:16 +0100 Subject: [PATCH] New failing test case with external type --- .../Controllers/ProductController.php | 10 ++++ .../Models/ProductExternalType.php | 50 +++++++++++++++++++ tests/Integration/EndToEndTest.php | 37 ++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 tests/Fixtures/Integration/Models/ProductExternalType.php diff --git a/tests/Fixtures/Integration/Controllers/ProductController.php b/tests/Fixtures/Integration/Controllers/ProductController.php index 75779b10ca..20cce82403 100644 --- a/tests/Fixtures/Integration/Controllers/ProductController.php +++ b/tests/Fixtures/Integration/Controllers/ProductController.php @@ -12,6 +12,7 @@ use TheCodingMachine\GraphQLite\Annotations\UseInputType; use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Contact; use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Product; +use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\ProductInternal; use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\ProductTypeEnum; use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\SpecialProduct; use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\TrickyProduct; @@ -29,6 +30,15 @@ public function getProducts(): ArrayResult ]); } + /** + * @Query() + * @return ProductInternal + */ + public function getProductsExternalType() + { + return new ProductInternal(); + } + /** * This is supposed to return an array of products... but it returns an array of array of Products. * Useful to test error messages. diff --git a/tests/Fixtures/Integration/Models/ProductExternalType.php b/tests/Fixtures/Integration/Models/ProductExternalType.php new file mode 100644 index 0000000000..2909336946 --- /dev/null +++ b/tests/Fixtures/Integration/Models/ProductExternalType.php @@ -0,0 +1,50 @@ +getMargin(); + } + + /** + * @Field() + */ + public function getMarginOk(ProductInternal $product): float + { + return $product->getMargin(); + } + + public function canAccess(): bool + { + return false; + } + +} diff --git a/tests/Integration/EndToEndTest.php b/tests/Integration/EndToEndTest.php index 00d0483a9c..633d393b69 100644 --- a/tests/Integration/EndToEndTest.php +++ b/tests/Integration/EndToEndTest.php @@ -1556,6 +1556,43 @@ public function testEndToEndSecurityInField(): void $this->assertSame('Access denied.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); } + public function testEndToEndSecurityInFieldExternalType(): void + { + $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); + + $queryString = ' + query { + productsExternalType { + marginOk + } + } + '; + + $result = GraphQL::executeQuery( + $schema, + $queryString, + ); + $data = $this->getSuccessResult($result); + $this->assertSame(12.0, $data['productsExternalType']['marginOk']); + + + $queryString = ' + query { + productsExternalType { + marginFails + } + } + '; + + $result = GraphQL::executeQuery( + $schema, + $queryString, + ); + $data = $this->getSuccessResult($result); + $this->assertSame(12.0, $data['productsExternalType']['marginOk']); + } + public function testEndToEndUnions(): void { $schema = $this->mainContainer->get(Schema::class);