JSPM

  • Created
  • Published
  • Downloads 10455
  • Score
    100M100P100Q143799F
  • License MIT

GraphQL document formatter for soda-gql

Package Exports

  • @soda-gql/formatter
  • @soda-gql/formatter/package.json

Readme

@soda-gql/formatter

GraphQL document formatter for soda-gql. This package formats generated GraphQL documents for better readability.

Features

  • Consistent formatting - Produces clean, readable GraphQL output
  • SWC-based parsing - Fast parsing using SWC
  • Optional integration - Used by CLI when available

Installation

npm install @soda-gql/formatter
# or
bun add @soda-gql/formatter

Usage

The formatter is typically used through the CLI:

soda-gql codegen --format

Programmatic Usage

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");
}

Requirements

  • Node.js >= 18
  • @swc/core >= 1.0.0 (peer dependency)

License

MIT