Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New failing test case with external type #554

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/Fixtures/Integration/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
50 changes: 50 additions & 0 deletions tests/Fixtures/Integration/Models/ProductExternalType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php


namespace TheCodingMachine\GraphQLite\Fixtures\Integration\Models;


use DateTimeInterface;
use Psr\Http\Message\UploadedFileInterface;
use TheCodingMachine\GraphQLite\Annotations\Factory;
use TheCodingMachine\GraphQLite\Annotations\FailWith;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Right;
use TheCodingMachine\GraphQLite\Annotations\Security;
use TheCodingMachine\GraphQLite\Annotations\Type;

class ProductInternal
{
public function getMargin(): float
{
return 12.0;
}
}

/**
* @Type(class=ProductInternal::class)
*/
class ProductExternalType {
/**
* @Field()
* @Security("this.canAccess()")
*/
public function getMarginFails(ProductInternal $product): float
{
return $product->getMargin();
}

/**
* @Field()
*/
public function getMarginOk(ProductInternal $product): float
{
return $product->getMargin();
}

public function canAccess(): bool
{
return false;
}

}
37 changes: 37 additions & 0 deletions tests/Integration/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down