@soda-gql/formatter 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @soda-gql/formatter
|
|
2
|
+
|
|
3
|
+
GraphQL document formatter for soda-gql. This package formats generated GraphQL documents for better readability.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Consistent formatting** - Produces clean, readable GraphQL output
|
|
8
|
+
- **SWC-based parsing** - Fast parsing using SWC
|
|
9
|
+
- **Optional integration** - Used by CLI when available
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @soda-gql/formatter
|
|
15
|
+
# or
|
|
16
|
+
bun add @soda-gql/formatter
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
The formatter is typically used through the CLI:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
soda-gql codegen --format
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Programmatic Usage
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { format, needsFormat } from "@soda-gql/formatter";
|
|
31
|
+
|
|
32
|
+
// Format a source file
|
|
33
|
+
const result = format({
|
|
34
|
+
sourceCode: source,
|
|
35
|
+
filePath: "/path/to/file.ts", // optional, used for TSX detection
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (result.isOk()) {
|
|
39
|
+
const { modified, sourceCode } = result.value;
|
|
40
|
+
if (modified) {
|
|
41
|
+
// Source was formatted
|
|
42
|
+
console.log(sourceCode);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Check if formatting is needed (useful for pre-commit hooks)
|
|
47
|
+
const needsFormatting = needsFormat({ sourceCode: source });
|
|
48
|
+
if (needsFormatting.isOk() && needsFormatting.value) {
|
|
49
|
+
console.log("File needs formatting");
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Requirements
|
|
54
|
+
|
|
55
|
+
- Node.js >= 18
|
|
56
|
+
- `@swc/core` >= 1.0.0 (peer dependency)
|
|
57
|
+
|
|
58
|
+
## Related Packages
|
|
59
|
+
|
|
60
|
+
- [@soda-gql/cli](../cli) - Command-line interface
|
|
61
|
+
- [@soda-gql/codegen](../codegen) - Code generation
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@soda-gql/formatter",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "GraphQL document formatter for soda-gql",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Shota Hatada",
|
|
13
|
+
"email": "shota.hatada@whatasoda.me",
|
|
14
|
+
"url": "https://github.com/whatasoda"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"graphql",
|
|
18
|
+
"codegen",
|
|
19
|
+
"zero-runtime",
|
|
20
|
+
"typescript",
|
|
21
|
+
"formatter"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/whatasoda/soda-gql.git",
|
|
26
|
+
"directory": "packages/formatter"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/whatasoda/soda-gql#readme",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/whatasoda/soda-gql/issues"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.mjs",
|
|
36
|
+
"module": "./dist/index.mjs",
|
|
37
|
+
"types": "./dist/index.d.mts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"@soda-gql": "./@x-index.ts",
|
|
41
|
+
"types": "./dist/index.d.mts",
|
|
42
|
+
"import": "./dist/index.mjs",
|
|
43
|
+
"require": "./dist/index.cjs",
|
|
44
|
+
"default": "./dist/index.mjs"
|
|
45
|
+
},
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"neverthrow": "^8.1.1"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@swc/types": "^0.1.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@swc/core": "^1.0.0"
|
|
56
|
+
}
|
|
57
|
+
}
|