Edit in GitHubLog an issue

graphql handlers

The graphql handler allows you to connect to a GraphQL endpoint.

Copied to your clipboard
{
"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:

Copied to your clipboard
{
"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.

Copied to your clipboard
{
"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.
}
}
}
}
]
}

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:

Copied to your clipboard
{
"meshConfig": {
"sources": [
{
"name": "test_automation",
"handler": {
"graphql": {
"endpoint": "https://venia.magento.com/graphql",
"source": "https://<domain>/myFile.graphql"
}
}
}
]
}
}
Copied to your clipboard
{
"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 or .ts.
  • source (type: String) - Path to the introspection file
  • schemaHeaders (type: Any) - JSON object for adding headers to API calls for runtime schema introspection
  • operationHeaders (type: JSON) - JSON object for adding headers to API calls for runtime operation execution
  • useGETForQueries (type: Boolean) - An HTTP GET method for query operations
  • method (type: String (GET | POST)) - An HTTP method for GraphQL operations
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.