0.4.5 • Published 16 days ago
@graphql-recodegen/cli v0.4.5
Recodegen
Faster GraphQL codegen for TypeScript projects
Installation
Binary
- you can download binaries from Releases page
NPM
Globally via NPM
npm install -g @graphql-recodegen/cli
- to run
recodegen -config=recodegen.json
Locally via NPM
npm install --save-dev @graphql-recodegen/cli
- to run
./node_modules/.bin/recodegen -config=recodegen.json
Build from Source
git clone git@github.com:poul-kg/recodegen.git
cd recodegen
cd cmd/recodegen
go build
- you'll see a binary file createdgo install
- to installrecodegen
and be able to run it from any directory. For this to work make sure yourPATH
contains output fromgo env GOPATH
command
Usage
./recodegen
- readsrecodegen.json
and tries to generate types./recodegen -config=codegen.json
- can specify custom JSON file
Configuration
- the idea was to re-use existing Apollo
@graphql-codegen/cli
JSON config format plugins: ['typescript']
- will generate schema typesplugins: ['typescript-operations']
- will generate operations- only two plugins supported:
plugins: ['typescript', 'typescript-operations']
- you can't use
documents:
likedocuments: "dir/*.ts"
it should bedocuments: ["dir/*.ts"]
- basically two config examples you see below are the only supported options for now, everything else will be ignored or will throw an error
Config 1 - separate files for generated schema and operations
The following config will:
- read GraphQL schema from
schema/backend.graphql
file - generate
generated/schema.generated.ts
file with all schema types - scan all
*.ts
files in./backend
directory and try to extract GraphQL queries, which should be defined as
// backend/my-service.ts
const query = gql`
query findUser($id: uuid!) {
first_name
last_name
}
`;
- Writes operations into
generated/operations.ts
operations.ts
will import schema types likeimport * as Types from "./schema.generated";
recodegen.json
{
"overwrite": true,
"schema": "schema/backend.graphql",
"generates": {
"generated/schema.generated.ts": {
"plugins": [
"typescript"
]
},
"generated/operations.ts": {
"preset": "import-types",
"presetConfig": {
"typesPath": "./schema.generated"
},
"plugins": [
"typescript-operations"
],
"documents": ["backend/**/*.ts"]
}
}
}
Config 2 - single file for generated schema and operations
recodegen.json
{
"overwrite": true,
"schema": "schema/backend.graphql",
"generates": {
"generated/schema.generated.ts": {
"plugins": [
"typescript", "typescript-operations"
],
"documents": ["backend/**/*.ts"]
}
}
}
./recodegen
- to build schema file and operations file
Known Issues
- some output is not properly formatted
- types in the generated output may change order on every new generation
- generated files are overwritten even if there is no change
- No Interface support
- No Union support
- no unit tests
- GraphQL fragment support is limited but something is supported
- some type names might differ a bit from what is generated by
@graphql-codegen/cli
- it's pretty raw right now, was done pretty quickly to avoid constant disappointment with slow codegen
0.4.5
16 days ago
0.4.4
3 months ago
0.4.1
11 months ago
0.4.3
11 months ago
0.4.2
11 months ago
0.4.0
11 months ago
0.3.0
11 months ago
0.2.1
11 months ago
0.1.4
11 months ago
0.2.2
11 months ago
0.1.3
11 months ago
0.1.2
11 months ago
0.1.1
11 months ago
0.1.0
11 months ago
0.0.18
11 months ago
0.0.17
11 months ago
0.0.16
11 months ago
0.0.15
11 months ago
0.0.14
11 months ago
0.0.13
11 months ago
0.0.12
11 months ago
0.0.11
11 months ago
0.0.10
11 months ago
0.0.9
12 months ago
0.0.8
12 months ago
0.0.7
12 months ago
0.0.6
12 months ago
0.0.5
12 months ago
0.0.4
12 months ago
0.0.3
12 months ago