data-variant=info
data-slots=text
To create a GraphQL handler for Adobe Commerce as a Cloud Service, see the Adobe Commerce as a Cloud Service best practices.
graphql handlers
The graphql handler allows you to connect to a GraphQL endpoint.
{
"meshConfig": {
"sources": [
{
"name": "PWA",
"handler": {
"graphql": {
"endpoint": "your_Venia_url"
}
}
},
{
"name": "AEM",
"handler": {
"graphql": {
"endpoint": "<your_AEM_url>"
}
}
}
]
},
}
This handler allows you to load remote GraphQL schemas as part of your mesh. The GraphQL handler uses the following format:
{
"sources": [
{
"name": "MyGraphQLApi",
"handler": {
"graphql": {
"endpoint": "https://my-service-url/graphql"
}
}
}
]
}
GraphQL handlers can also use local sources, see Reference local file handlers for more information.
Headers from context
The following example shows how to pass authorization headers to a GraphQL endpoint.
{
"sources": [
{
"name": "MyGraphQLApi",
"handler": {
"graphql": {
"endpoint": "https://your-service/graphql",
"operationHeaders": {
"Authorization": "Bearer {context.headers['x-my-api-token']}"
// Do not use capital letters in header names.
}
}
}
}
]
}
data-variant=info
data-slots=text
Header names are automatically converted to lowercase.
Provide an introspection file
If introspection is disabled in the production environment of your GraphQL source, and you want to provide your schema definition or introspection separately, you can use the source field to provide an online or local introspection file:
{
"meshConfig": {
"sources": [
{
"name": "test_automation",
"handler": {
"graphql": {
"endpoint": "https://venia.magento.com/graphql",
"source": "https://<domain>/myFile.graphql"
}
}
}
]
}
}
{
"meshConfig": {
"sources": [
{
"name": "Adobe_Commerce",
"handler": {
"graphql": {
"endpoint": "https://venia.magento.com/graphql",
"source": "schema.graphql"
}
}
}
],
"files": [
{
"path": "schema.graphql",
"content": "type Query {hello: String}"
}
]
}
}
Local Schemas
We recommend providing a local schema by using the additionalTypeDefs and additionalResolvers configuration options.
Config API reference
endpoint(type:String, required) - URL or file path for your remote GraphQL endpoint- Local file types must be
.js,.ts, or.graphql.
- Local file types must be
source(type:String) - Path to the introspection fileschemaHeaders(type:Any) - JSON object for adding headers to API calls for runtime schema introspectionoperationHeaders(type:JSON) - JSON object for adding headers to API calls for runtime operation executionuseGETForQueries(type:Boolean) - An HTTP GET method for query operationsmethod(type:String (GET | POST)) - An HTTP method for GraphQL operations <!--subscriptionsEndpoint(type:String) - A URL to your endpoint serving all subscription queries for this sourcecustomFetch(type:Any) - Path to a custom W3 Compatible Fetch ImplementationwebSocketImpl(type:String) - Path to a custom W3 Compatible WebSocket Implementationintrospection(type:String) - Path to the introspection You can separately give schema introspectionmultipart(type:Boolean) - Enable multipart/form data in order to support file uploadssubscriptionsProtocol(type:String (SSE | WS | LEGACY_WS)) - SSE - Server Sent Events WS - New graphql-ws LEGACY_WS - Legacy subscriptions-transport-wsretry(type:Int) - Retry attempts if failstimeout(type:Int) - Timeout in millisecondsbatch(type:Boolean) - Enable/Disable automatic query batching -->