Download the PHP package enjin-forks/graphql-formatter without Composer
On this page you can find all versions of the php package enjin-forks/graphql-formatter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download enjin-forks/graphql-formatter
More information about enjin-forks/graphql-formatter
Files in enjin-forks/graphql-formatter
Package graphql-formatter
Short Description Opinionated formatter for .gql and .graphql files
License MIT
Informations about the package graphql-formatter
graphql-formatter
An opinionated formatter for .gql and .graphql files. Written in PHP, powered by webonyx/graphql-php.
Installation
Usage
Add to your composer.json scripts:
Then run:
Configuration
Publish config (recommended)
Use the built-in publish-config command to copy the example config to your project's config/ directory:
This copies graphql-formatter.php to config/graphql-formatter.php (Laravel convention).
If a config file already exists, you'll get a warning. Use --force to overwrite:
To publish to a custom directory:
Config file location
The formatter looks for config in this order:
config/graphql-formatter.php(preferred — Laravel convention)graphql-formatter.phpin project root (legacy fallback)
If no config file is found, sensible defaults are used.
Config options
Edit the published config/graphql-formatter.php:
| Key | Default | Options | Description |
|---|---|---|---|
paths |
['.'] |
— | Directories to scan |
indent |
'4spaces' |
'2spaces', '4spaces', 'tab' |
Indentation style |
print_width |
80 |
— | Max line width before args expand to multiline |
max_inline_args |
2 |
— | Max args allowed inline (applies to field args and operation variable definitions) |
trailing_newline |
true |
— | Ensure trailing newline at end of file |
Formatting rules
- Each definition separated by a blank line
- Selection sets always indented (4 spaces by default)
- Arguments inline if count ≤
max_inline_argsand total length ≤print_width - Operation variable definitions (
$id: ID!) follow the same inline/multiline rules as field arguments ObjectValuearguments ({ key: value }) always expand to multiline- List values containing objects expand to one item per line
- Inline fragments (
... on Type) always rendered on their own line #import "..."directives preserved at top of file- SDL types (input, type, enum, scalar, interface, union) are formatted with the same indentation rules
- Formatting is idempotent — running twice gives the same result
Supported GraphQL constructs
- Queries, mutations, subscriptions (named and anonymous)
- Fragment definitions and spreads
- Inline fragments (
... on Type { ... }) - Variable definitions with types and default values
- Field aliases (
alias: fieldName) - Directives on fields, operations, and fragments (
@include(if: $val)) #import "..."directives (preserved verbatim)- Schema Definition Language (SDL):
type,input,enum,scalar,interface,uniondefinitionsextend type,extend input,extend enum, etc.schema { query: Query }definitions- Descriptions (block strings
"""..."""and inline"...") - Directives on type definitions
Example
Input:
Output (with max_inline_args: 2, indent: 4spaces):
SDL example
Input:
Output:
Development
See CONTRIBUTING.md for the full contribution guide.
License
MIT