Add Twig CS Fixer rule to auto-format GraphQL blocks#72
Merged
Conversation
Introduces GraphQLFormatterRule which reformats the GraphQL operation
inside `{% graphql %}...{% endgraphql %}` blocks using
webonyx/graphql-php Printer::doPrint, indented to match the block.
Invalid GraphQL is reported as an error and left untouched.
Wired into .twig-cs-fixer.php and applied to the existing fixture
templates so they use the canonical formatting. Covered by a
functional test that runs the real twig-cs-fixer Linter/Fixer
pipeline over fixture templates.
https://claude.ai/code/session_0172zkGgfrZ2KQ8ngMJ1X3zr
Adds an "Auto-Format GraphQL in Twig" section explaining GraphQLFormatterRule and showing the .twig-cs-fixer.php setup (kept in sync via the readme-examples-sync source directive). https://claude.ai/code/session_0172zkGgfrZ2KQ8ngMJ1X3zr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Twig CS Fixer fixer that automatically formats the GraphQL operations inside
{% graphql %}...{% endgraphql %}blocks in Twig templates.src/Twig/GraphQLFormatterRule.php— a fixable Twig CS Fixer rule that reconstructs the raw GraphQL from a block, reformats it viaGraphQL\Language\Printer::doPrint(Parser::parse(...)), and re-indents every line to match the block's own indentation. Unparseable GraphQL is reported as an error and left untouched; blocks that embed Twig (variables/tags/comments) are skipped since they can't be safely round-tripped..twig-cs-fixer.php, and the existing project templates were normalized to the canonical 2-spacewebonyx/graphql-phpformat (README auto-synced to match).vincentlanglet/twig-cs-fixerdev-dependency-in-prod exception incomposer-dependency-analyser.php, mirroring the existingtwig/twigentry..twig-cs-fixer.phpconfig kept in sync via thereadme-examples-syncsource directive.Test plan
tests/GraphQLFormatterRule/GraphQLFormatterRuleTest.php— functional test driving the real twig-cs-fixerLinter/Fixerpipeline over fixture templates:.html.twig.fixtureextension so the pre-committwig-cs-fixer fixhook (globs*.twig) can't mutate the intentionally-malformed inputshttps://claude.ai/code/session_0172zkGgfrZ2KQ8ngMJ1X3zr
Generated by Claude Code