Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,20 @@ jobs:
go-version: '1.23.1'

- name: Unit tests
run: go test ./...
run: go test ./...

format-check:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: "Set up Go"
uses: actions/setup-go@v5
with:
go-version: '1.23.1'

- name: Check formatting
id: check_formatting
run: test -z $(gofmt -l .)
11 changes: 4 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Release
name: Release

on:
push:
Expand All @@ -18,11 +18,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install just
run: |
mkdir -p "$HOME/.local/bin"
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to "$HOME/.local/bin"
echo "$HOME/.local/bin" >> $GITHUB_PATH
- uses: extractions/setup-just@v1

- name: "Set up Go"
uses: actions/setup-go@v5
Expand All @@ -44,4 +40,5 @@ jobs:
with:
files: build/fgc-*
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
name: ${{ github.ref_name }}
generate_release_notes: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Simon Sorensen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[![Build and Release](https://github.com/simse/faster-graphql-codegen/actions/workflows/release.yml/badge.svg)](https://github.com/simse/faster-graphql-codegen/actions/workflows/release.yml)
# 🚀 faster-graphql-codegen 🚀
A reimplementation of graphql-codegen designed to be (much) faster than the original. It aims to be drop-in compatible where possible.

![GitHub Release](https://img.shields.io/github/v/release/simse/faster-graphql-codegen)
[![Build and Release](https://github.com/simse/faster-graphql-codegen/actions/workflows/release.yml/badge.svg)](https://github.com/simse/faster-graphql-codegen/actions/workflows/release.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/simse/faster-graphql-codegen)](https://goreportcard.com/report/github.com/simse/faster-graphql-codegen)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

[Docs](https://faster-graphql-codegen.simse.io/) | [Quick Start](https://faster-graphql-codegen.simse.io/quick-start)

## Current functionality
Expand Down
28 changes: 26 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,44 @@ export default defineConfig({
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: 'Home', link: '/' },
{ text: 'Examples', link: '/markdown-examples' }
{ text: 'Reference', link: '/reference' }
],

sidebar: [
{
text: 'Get Started',
items: [
{ text: 'Quick Start', link: '/quick-start' },
{ text: 'Installation', link: '/install' },
]
},
{
text: 'Configuration',
items: [
{ text: 'Config File', link: '/config' },
]
},
{
text: 'Plugins',
items: [
{ text: 'Overview', link: '/plugins' },
]
},
{
text: 'Reference',
items: [
{ text: 'codegen.ts', link: '/reference/config' },
],
collapsed: true,
}
],

socialLinks: [
{ icon: 'github', link: 'https://github.com/simse/faster-graphql-codegen' }
]
],

search: {
provider: 'local'
}
}
})
135 changes: 135 additions & 0 deletions docs/src/config/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Configuration

::: danger faster-graphql-codegen is in alpha
Config documentation may be incorrect, incomplete or out of date.
:::

Since `faster-graphql-codegen` is a drop-in replacement for `graphql-codegen`, it uses the same config format.

However, there are still some slight differences to be aware of, and these are documented here.

## `codegen.ts` format

Here's a basic `codegen.ts` file:
```ts
import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
schema: 'schema.graphql',
documents: null,
generates: {
'__generated__/baseTypes.ts': {
plugins: ['typescript']
}
}
}

export default config
```

### `schema`
**Required.** Must be a string or an array of strings. Must point to a local file.

::: code-group

```ts [Single schema]
import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
schema: 'schema.graphql', // [!code focus]
documents: null,
generates: {
'__generated__/baseTypes.ts': {
plugins: ['typescript']
}
}
}

export default config
```

```ts [Multiple schemas]
import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
schema: [ // [!code focus]
'base.graphql', // [!code focus]
'search.graphql', // [!code focus]
], // [!code focus]
documents: null,
generates: {
'__generated__/baseTypes.ts': {
plugins: ['typescript']
}
}
}

export default config
```

:::

### `generates`
An object containg outputs and their configurations. The object key is the name of the output file.

```ts
import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
schema: 'schema.graphql',
documents: null,
generates: { // [!code focus]
'__generated__/baseTypes.ts': { // [!code focus]
plugins: ['typescript'] // [!code focus]
} // [!code focus]
} // [!code focus]
}

export default config
```

#### `plugins`
A `generates` config must contain a list of plugins. For available plugins please see the [plugin page](/plugins).

## Other formats
`faster-graphql-codegen` can also read this configuration from a `.yaml` or `.json` file.

::: code-group

```yaml [codegen.yml]
schema: ["schema.graphql"]
documents: []
overwrite: true
generates:
'baseTypes.ts':
plugins: [typescript]
```

```ts [codegen.ts]
import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
schema: 'schema.graphql',
documents: [],
overwrite: true,
generates: {
'__generated__/baseTypes.ts': {
plugins: ['typescript']
}
}
}

export default config
```

:::

## A note on performance

::: warning STATIC FILES LOAD FASTER
JSON and YAML config files are faster to load.
:::

Dynamic config files (JS and TS) are supported for compatibility purposes, but they are slower to load, because they have to be interpreted first.

If you are not using any Javascript features, please consider using a static format such as JSON or YAML.
3 changes: 3 additions & 0 deletions docs/src/install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Installation

`faster-graphql-codegen` is unreleased and does not have any installers. However, if you're eager, you can download the latest binary from [Github](https://github.com/simse/faster-graphql-codegen/releases/latest).
85 changes: 0 additions & 85 deletions docs/src/markdown-examples.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/src/plugins/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Plugins
1 change: 1 addition & 0 deletions docs/src/reference/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# `codegen.ts` reference
1 change: 1 addition & 0 deletions docs/src/reference/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Reference
2 changes: 2 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
__generated__
1 change: 1 addition & 0 deletions examples/projects/monorepo-with-dynamic-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { CodegenConfig } from '@graphql-codegen/cli'

const createConfig = (): CodegenConfig => ({
schema: ['../../apps/graphql-server/schema.graphql'],
documents: null,
generates: {
'__generated__/baseTypes.ts': {
plugins: ['typescript'],
preset: 'client',
}
}
})

export default createConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import createConfig from '../codegen-config/codegen-config';

export default createConfig()
Loading