Dev guideRecipesAPI ReferenceChangelog
Dev guideRecipesUser GuidesNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Debug GraphQL queries

Use GraphiQL, structured error analysis, and systematic simplification to isolate and fix query issues.

Isolate and fix query issues faster with GraphiQL, structured error analysis, and systematic simplification techniques. For the full error taxonomy and HTTP status code reference, see Error handling and rate limits.

Use GraphiQL for query development

GraphiQL is an interactive GraphQL IDE for building, testing, and debugging queries against your Optimizely Graph instance.

Access GraphiQL: https://cg.optimizely.com/app/graphiql?auth=YOUR_SINGLE_KEY

GraphiQL provides autocomplete (Ctrl+Space), real-time error highlighting, a Documentation Explorer for browsing the schema, query execution, and query history.

Debugging workflow

  1. Start with a minimal query and build incrementally:
# Start minimal
query Test {
  ArticlePage {
    total
  }
}

# Add fields one at a time
query Test {
  ArticlePage {
    total
    items {
      Name
    }
  }
}

# Add filters last
query Test {
  ArticlePage(where: { Name: { eq: "Test" } }) {
    total
    items {
      Name
    }
  }
}
  1. Use query variables for testing dynamic values:
query TestWithVariables($name: String) {
  ArticlePage(where: { Name: { eq: $name } }) {
    items {
      Name
    }
  }
}
{
  "name": "My Article"
}
  1. Check the response for both the errors array and partial data results.

Analyze error messages

GraphQL returns errors in a structured JSON format. Understanding the structure helps you locate the exact problem.

Error response structure

{
  "errors": [
    {
      "message": "Human-readable error description",
      "locations": [{ "line": 4, "column": 7 }],
      "path": ["ContentType", "items", 0, "FieldName"],
      "extensions": {
        "code": "ERROR_CODE"
      }
    }
  ],
  "data": null
}

Key fields

  • message – What went wrong
  • locations – The line and column in your query where the error occurred
  • path – Which field in the result caused the error
  • extensions.code – Error category (for example, GRAPHQL_VALIDATION_FAILED or UNAUTHENTICATED)

Common error codes

CodeMeaningAction
GRAPHQL_VALIDATION_FAILEDInvalid query structureCheck field names and types
GRAPHQL_PARSE_FAILEDSyntax errorFix missing brackets or quotes
UNAUTHENTICATEDAuthentication missing or invalidVerify credentials
FORBIDDENInsufficient permissionsCheck access rights and tokens
INTERNAL_SERVER_ERRORServer-side issueContact support with query details

Simplify complex queries

When a complex query fails, simplify it to isolate the problem. Three approaches work well.

  • Binary search – Comment out half of your query, test, then narrow down which section causes the error.
query Debug {
  ArticlePage {
    items {
      Name
      # TeaserText
      # MainBody {
      #   html
      # }
      # Category {
      #   Name
      # }
    }
  }
}
  • Build incrementally – with the smallest valid query and add one field at a time until the error appears.
# Step 1
{ ArticlePage { total } }

# Step 2
{ ArticlePage { total items { Name } } }

# Step 3
{ ArticlePage { total items { Name TeaserText } } }
  • Test filters separately – Remove all filters first, then add them back one at a time to find the problematic filter.
# Without filters
query Test {
  ArticlePage {
    items { Name }
  }
}

# Add one filter
query Test {
  ArticlePage(where: { Name: { eq: "Test" } }) {
    items { Name }
  }
}

GraphQL query errors

Resolve query validation failures, timeouts, and filter errors. For the full error taxonomy, see Error handling and rate limits.

Field does not exist

Symptoms
Cannot query field 'FIELD_NAME' on type 'CONTENT_TYPE' error, HTTP 400 Bad Request, query validation fails.

Resolution

  1. Open GraphiQL IDE and use autocomplete (Ctrl+Space) to verify available fields.
  2. Check field name spelling and casing. GraphQL is case-sensitive.
  3. Run an introspection query to confirm the field exists:
query CheckFields {
  __type(name: "ArticlePage") {
    fields {
      name
      type {
        name
        kind
      }
    }
  }
}
  1. Ensure the content type has been synchronized to Graph after any schema changes.

For schema details, see the GraphQL schema documentation.

Query timeout

Symptoms
HTTP 504 Gateway Timeout, Query execution timeout error, slow query performance.

Resolution

  1. Reduce query complexity: limit nested relationships, select only needed fields, and add pagination.
  2. Compare an optimized query against the problematic one:
# Optimized: flat structure with pagination
query FastQuery {
  ArticlePage(limit: 20) {
    items {
      Name
      Category {
        Name
      }
    }
  }
}
  1. Use cached templates for repeated query structures.
  2. Implement pagination for large result sets.

For optimization patterns, see GraphQL best practices.

Invalid filter or where clause

Symptoms
Field is not filterable or Invalid filter operator error, HTTP 400 Bad Request, filter does not work as expected.

Resolution

  1. Verify the field is marked as filterable in the content type configuration.
  2. Confirm the correct filter operator:
where: {
  Name: { eq: "Exact Match" }
  StartPublish: { gte: "2024-01-01" }
  Tags: { in: ["tag1", "tag2"] }
  Description: { contains: "keyword" }
}
  1. Test complex filters in GraphiQL before implementing them in code.

For the full list of operators, see Filter content with Optimizely Graph.

Variable type mismatch

Symptoms
Expected type "String", found 123 or Expected type "Int", found "abc" errors.

Resolution
Ensure the variable value matches the declared type in the query definition:

# Declare the type to match the variable value
query GetArticle($id: Int!) {
  ArticlePage(where: { Id: { eq: $id } }) {
    items { Name }
  }
}
{ "id": 123 }

Common mismatches: passing a number where a String is expected, or a quoted number where an Int is required.

Query syntax errors

Symptoms
Syntax Error GraphQL request: Expected Name, found $ error, HTTP 400 Bad Request.

Resolution

  1. Declare all variables in the query definition:
# Declare $name before using it
query GetArticles($name: String!) {
  ArticlePage(where: { Name: { eq: $name } }) {
    items { Name }
  }
}
  1. Check for missing closing brackets (} or )), mismatched quotes, and incorrect field names.
  2. Validate the query in GraphiQL IDE before deploying.
Query complexity limit exceeded

Symptoms
Query complexity of 1500 exceeds maximum of 1000 error.

Resolution

  1. Request only the fields you need.
  2. Remove deeply nested relationships (keep depth to five levels or fewer).
  3. Add pagination with limit to reduce result set size.
  4. Break one complex query into multiple focused queries.

For optimization techniques, see GraphQL best practices.

Performance issues

Optimize query performance and resolve caching problems. For detailed optimization strategies, see GraphQL best practices and Cached templates.

Slow query performance

Symptoms
Queries take longer than expected, inconsistent response times, timeout errors on complex queries.

Resolution

  1. Limit query depth to five levels or fewer.
  2. Select only the fields you need.
  3. Use pagination (limit and skip, or cursor-based) for large result sets.
  4. Use cached templates for repeated query structures.
  5. Use item instead of items when fetching a single result. See Item queries for single entities.
  6. Measure execution time to identify the slowest queries and optimize those first.
Cached template not working as expected

Symptoms
Stale data returned, cache does not update after content changes, performance does not improve with cached templates.

Resolution

  1. Verify the cached template syntax:
query MyCachedQuery @cached(ttl: 300) {
  ArticlePage(limit: 10) {
    items {
      Name
      TeaserText
    }
  }
}
  1. Cached templates have a time-to-live (TTL). Content updates do not reflect until the TTL expires.
  2. Adjust TTL based on content update frequency: lower TTL for frequently updated content, higher TTL for stable content.
  3. Review cache performance in the Graph Portal.

For implementation details, see Cached templates.