Skip to content

Conversation

@henkin
Copy link

@henkin henkin commented Nov 1, 2025

This PR adds support for custom operation-level examples for GraphQL queries and mutations in metadata files. Previously, SpectaQL would ignore custom examples provided in metadata and generate auto-examples with placeholder values instead.

Fixes #1048

Key Changes

  • Modified pre-process.js to check for and use custom examples from metadata
  • Updated build-schemas.js to pass original metadata through to preProcess
  • Supports both OBJECT format and top-level queries/mutations format
  • Tests added to support feature
  • Documentation updated in README.md

Supported Formats

  • OBJECT.Query.fields.operationName.documentation.examples (recommended)
  • queries.operationName.examples / mutations.operationName.examples (alternative)

The implementation prioritizes custom examples when available, and falls back to auto-generation when not provided, maintaining backward compatibility.

All tests pass.

- add support for normalizing different example formats in pre-process
- implement getOperationExamples function to extract custom examples
- handle OBJECT and alternative example formats from metadata
- add fallback to auto-generation when no custom examples exist
- modify pre-process to use first custom example or generate automatically
- support multiple examples with first example used for display
- maintain backwards compatibility with existing metadata structures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add possibility to add custom examples for mutations and query arguments

1 participant