GraphQL document formatter for soda-gql
npm install @soda-gql/formatterGraphQL document formatter for soda-gql. This package formats generated GraphQL documents for better readability.
- Consistent formatting - Produces clean, readable GraphQL output
- SWC-based parsing - Fast parsing using SWC
- Optional integration - Used by CLI when available
``bash`
npm install @soda-gql/formatteror
bun add @soda-gql/formatter
The formatter is typically used through the CLI:
`bash`
soda-gql format
`typescript
import { format, needsFormat } from "@soda-gql/formatter";
// Format a source file
const result = format({
sourceCode: source,
filePath: "/path/to/file.ts", // optional, used for TSX detection
});
if (result.isOk()) {
const { modified, sourceCode } = result.value;
if (modified) {
// Source was formatted
console.log(sourceCode);
}
}
// Check if formatting is needed (useful for pre-commit hooks)
const needsFormatting = needsFormat({ sourceCode: source });
if (needsFormatting.isOk() && needsFormatting.value) {
console.log("File needs formatting");
}
`
- Node.js >= 18
- @swc/core` >= 1.0.0 (peer dependency)
- @soda-gql/cli - Command-line interface
- @soda-gql/codegen - Code generation
MIT