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