GraphQL functional testing
Magento provides API functional tests that can verify extension points in GraphQL. These tests serve as an example for exposing new queries via GraphQL.
Creating a new GraphQL functional test
All GraphQL functional tests should inherit from the generic test case Magento\TestFramework\TestCase\GraphQlAbstract
. It defines the graphQlQuery()
method, which should be used to perform Web API calls from tests.
The following test verifies that the schema returns the correct attribute type, given the attribute_code
and corresponding entity_type
.
Using the default GraphQlQueryTest
The \Magento\GraphQl\TestModule\GraphQlQueryTest.php
test case uses two test modules to determine whether the mechanisms for GraphQL extensibility work as expected. It illustrates best practices for extending an existing GraphQL endpoint.
TestModuleGraphQlQuery
- This bare-bones module defines atestItem
endpoint with the queryable attributesitem_id
andname
. It’s located at<installdir>/dev/tests/api-functional/_files/TestModuleGraphQlQuery
.TestModuleGraphQlQueryExtension
- This module extendsTestModuleGraphQlQuery
, adding theinteger_list
extension attribute. It’s located at<installdir>/dev/tests/api-functional/_files/TestModuleGraphQlQueryExtension
.