init
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Framework;
|
||||
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Tests error handling for GraphQL.
|
||||
*/
|
||||
class ErrorHandlerTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* Test that when not in developer mode, only the first error message is reported.
|
||||
*
|
||||
* This is important for performance optimization, since an infinite number of errors
|
||||
* can be reported for a single query.
|
||||
*/
|
||||
public function testErrorHandlerReportsFirstErrorOnly()
|
||||
{
|
||||
$query = <<<QUERY
|
||||
query {
|
||||
countries {
|
||||
full_name_english @aaaaaa @bbbbbb @cccccc
|
||||
full_name_locale @skip
|
||||
...countryAbbrev
|
||||
}
|
||||
}
|
||||
|
||||
fragment countryAbbrev on Country {
|
||||
two_letter_abbreviation @aaaaa
|
||||
three_letter_abbreviation @aaaaaa
|
||||
}
|
||||
QUERY;
|
||||
try {
|
||||
$this->graphQlQuery($query);
|
||||
} catch (\Exception $e) {
|
||||
$responseData = $e->getResponseData();
|
||||
self::assertCount(1, $responseData['errors']);
|
||||
|
||||
$errorMsg = $responseData['errors'][0]['message'];
|
||||
self::assertMatchesRegularExpression('/Unknown directive \"@aaaaaa\"./', $errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
+477
@@ -0,0 +1,477 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Framework;
|
||||
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Tests query complexity limiter and depth limiter.
|
||||
* Actual for production mode only
|
||||
*/
|
||||
class QueryComplexityLimiterTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function testQueryComplexityIsLimited()
|
||||
{
|
||||
$query
|
||||
= <<<QUERY
|
||||
{
|
||||
category(id: 2) {
|
||||
products {
|
||||
items {
|
||||
name
|
||||
nameAlias: name
|
||||
...configurableFields
|
||||
... on BundleProduct {
|
||||
items {
|
||||
options {
|
||||
uid
|
||||
label
|
||||
}
|
||||
}
|
||||
}
|
||||
categories {
|
||||
id
|
||||
position
|
||||
level
|
||||
url_key
|
||||
url_path
|
||||
product_count
|
||||
breadcrumbs {
|
||||
category_id
|
||||
category_name
|
||||
category_url_key
|
||||
}
|
||||
products {
|
||||
items {
|
||||
media_gallery_entries {
|
||||
file
|
||||
}
|
||||
name
|
||||
special_to_date
|
||||
tier_price
|
||||
manufacturer
|
||||
thumbnail {
|
||||
url
|
||||
label
|
||||
}
|
||||
sku
|
||||
image {
|
||||
url
|
||||
label
|
||||
}
|
||||
canonical_url
|
||||
categories {
|
||||
id
|
||||
position
|
||||
level
|
||||
url_key
|
||||
url_path
|
||||
product_count
|
||||
breadcrumbs {
|
||||
category_id
|
||||
category_name
|
||||
category_url_key
|
||||
}
|
||||
products {
|
||||
items {
|
||||
name
|
||||
special_to_date
|
||||
thumbnail {
|
||||
url
|
||||
label
|
||||
}
|
||||
tier_price
|
||||
manufacturer
|
||||
sku
|
||||
image {
|
||||
url
|
||||
label
|
||||
}
|
||||
canonical_url
|
||||
media_gallery_entries {
|
||||
position
|
||||
id
|
||||
types
|
||||
}
|
||||
categories {
|
||||
id
|
||||
position
|
||||
level
|
||||
url_key
|
||||
url_path
|
||||
product_count
|
||||
breadcrumbs {
|
||||
category_id
|
||||
category_name
|
||||
category_url_key
|
||||
}
|
||||
products {
|
||||
items {
|
||||
name
|
||||
special_to_date
|
||||
tier_price
|
||||
manufacturer
|
||||
thumbnail {
|
||||
url
|
||||
label
|
||||
}
|
||||
sku
|
||||
image {
|
||||
url
|
||||
label
|
||||
}
|
||||
canonical_url
|
||||
categories {
|
||||
id
|
||||
position
|
||||
level
|
||||
url_key
|
||||
url_path
|
||||
product_count
|
||||
breadcrumbs {
|
||||
category_id
|
||||
category_name
|
||||
category_url_key
|
||||
}
|
||||
products {
|
||||
items {
|
||||
name
|
||||
special_to_date
|
||||
tier_price
|
||||
manufacturer
|
||||
sku
|
||||
image {
|
||||
url
|
||||
label
|
||||
}
|
||||
canonical_url
|
||||
categories {
|
||||
id
|
||||
position
|
||||
level
|
||||
url_key
|
||||
url_path
|
||||
product_count
|
||||
breadcrumbs {
|
||||
category_id
|
||||
category_name
|
||||
category_url_key
|
||||
}
|
||||
products {
|
||||
items {
|
||||
name
|
||||
special_to_date
|
||||
price {
|
||||
minimalPrice {
|
||||
amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
maximalPrice {
|
||||
amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
regularPrice {
|
||||
amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
}
|
||||
tier_price
|
||||
special_price
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_prices {
|
||||
customer_group_id
|
||||
qty
|
||||
percentage_value
|
||||
website_id
|
||||
}
|
||||
tier_price
|
||||
manufacturer
|
||||
sku
|
||||
image {
|
||||
url
|
||||
label
|
||||
}
|
||||
thumbnail {
|
||||
url
|
||||
label
|
||||
}
|
||||
canonical_url
|
||||
categories {
|
||||
id
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
position
|
||||
level
|
||||
url_key
|
||||
url_path
|
||||
product_count
|
||||
default_sort_by
|
||||
breadcrumbs {
|
||||
category_id
|
||||
category_name
|
||||
category_url_key
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment configurableFields on ConfigurableProduct {
|
||||
variants {
|
||||
attributes {
|
||||
uid
|
||||
code
|
||||
label
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
self::expectExceptionMessageMatches('/Max query complexity should be 300 but got 302/');
|
||||
//Use POST request because request uri is too large for some servers
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function testQueryDepthIsLimited()
|
||||
{
|
||||
$query
|
||||
= <<<QUERY
|
||||
{
|
||||
category(id: 2) {
|
||||
products {
|
||||
items {
|
||||
name
|
||||
categories {
|
||||
products {
|
||||
items {
|
||||
media_gallery_entries {
|
||||
file
|
||||
}
|
||||
categories {
|
||||
products {
|
||||
items {
|
||||
categories {
|
||||
products {
|
||||
items {
|
||||
categories {
|
||||
products {
|
||||
items {
|
||||
categories {
|
||||
products {
|
||||
items {
|
||||
categories {
|
||||
products {
|
||||
items {
|
||||
categories {
|
||||
products {
|
||||
items {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
self::expectExceptionMessageMatches('/Max query depth should be 20 but got 23/');
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Framework;
|
||||
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
|
||||
|
||||
/**
|
||||
* Test that required input parameters are properly validated on framework level
|
||||
*/
|
||||
class RequiredInputArgumentTest extends GraphQlAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Test that a simple input value will be treated as required
|
||||
*
|
||||
* We should see error message from framework not the Resolver
|
||||
* urlResolver query has required input arg "url"
|
||||
*/
|
||||
public function testSimpleInputArgumentRequired()
|
||||
{
|
||||
$query = <<<QUERY
|
||||
{
|
||||
testQueryWithTopLevelMandatoryInputArguments{
|
||||
item_id
|
||||
name
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$expectedExceptionsMessage = 'GraphQL response contains errors:'
|
||||
. ' Field "testQueryWithTopLevelMandatoryInputArguments" argument "topLevelArgument"'
|
||||
. ' of type "String!" is required but not provided.';
|
||||
$this->expectException(ResponseContainsErrorsException::class);
|
||||
$this->expectExceptionMessage($expectedExceptionsMessage);
|
||||
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a more complex required argument is handled properly
|
||||
*
|
||||
* testInputQueryWithMandatoryArguments mutation has required parameter input.query_items.query_item_id
|
||||
*/
|
||||
public function testInputObjectArgumentRequired()
|
||||
{
|
||||
$query = <<<QUERY
|
||||
query {
|
||||
testQueryWithNestedMandatoryInputArguments(
|
||||
input: {
|
||||
query_id: "foobar"
|
||||
query_items: [
|
||||
{
|
||||
quantity: 2
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
item_id
|
||||
name
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$expectedExceptionsMessage = 'GraphQL response contains errors:'
|
||||
. ' Field QueryWithMandatoryArgumentsInput.query_item_id of required type Int! was not provided.';
|
||||
$this->expectException(ResponseContainsErrorsException::class);
|
||||
$this->expectExceptionMessage($expectedExceptionsMessage);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user