This is a fork of gqlgenc. We have made custom changes to
- Handle BigFloat
- Handle nested types
- Allow injecting custom GraphQL client
The changes we made can be viewed here
Run go get github.com/TripleMint/gqlgenc
to install the executable and update your go.mod
and go.sum
files.
To prevent go mod tidy
from removing this library, add a tools.go
file with the following code:
// +build tools
package tools
import (
_ "github.com/TripleMint/gqlgenc"
)
Add a .gqlgenc.yml
configuration file in the directory where queries are stored.
Then run GRAPHQL_HOST=$HOST gqlgenc
. You should see files generated in the directories you have specified in the configuration file.
The rest of this doc is from the original repo.
This is a fork of gqlgenc. We have made custom changes to
- Handle BigFloat
- Handle nested types
- Allow injecting custom GraphQL client
The changes we made can be viewed here or as diff.
The rest of this doc is from the original repo.
This is Go library for building GraphQL client with gqlgen
Now, if you build GraphQL api client for Go, have choice:
These libraries are very simple and easy to handle. However, as I work with gqlgen and graphql-code-generator every day, I find out the beauty of automatic generation. So I want to automatically generate types.
go get -u github.com/TripleMint/gqlgenc
gqlgenc base is gqlgen with plugins. So the setting is yaml in each format.
gqlgenc can be configured using a .gqlgenc.yml
file
Load a schema from a remote server:
model:
package: generated
filename: ./models_gen.go # https://github.com/99designs/gqlgen/tree/master/plugin/modelgen
client:
package: generated
filename: ./client.go # Where should any generated client go?
models:
Int:
model: github.com/99designs/gqlgen/graphql.Int64
Date:
model: github.com/99designs/gqlgen/graphql.Time
endpoint:
url: https://api.annict.com/graphql # Where do you want to send your request?
headers: # If you need header for getting introspection query, set it
Authorization: "Bearer ${ANNICT_KEY}" # support environment variables
query:
- "./query/*.graphql" # Where are all the query files located?
Load a schema from a local file:
model:
package: generated
filename: ./models_gen.go # https://github.com/99designs/gqlgen/tree/master/plugin/modelgen
client:
package: generated
filename: ./client.go # Where should any generated client go?
models:
Int:
model: github.com/99designs/gqlgen/graphql.Int64
Date:
model: github.com/99designs/gqlgen/graphql.Time
schema:
- "schema/**/*.graphql" # Where are all the schema files located?
query:
- "./query/*.graphql" # Where are all the query files located?
Execute the following command on same directory for .gqlgenc.yml
gqlgenc
Do this when creating a server and client for Go. You create your own entrypoint for gqlgen. This use case is very useful for testing your server.
package main
import (
"fmt"
"os"
"github.com/TripleMint/gqlgenc/clientgen"
"github.com/99designs/gqlgen/api"
"github.com/99designs/gqlgen/codegen/config"
)
func main() {
cfg, err := config.LoadConfigFromDefaultLocations()
if err != nil {
fmt.Fprintln(os.Stderr, "failed to load config", err.Error())
os.Exit(2)
}
queries := []string{"client.query", "fragemt.query"}
clientPackage := config.PackageConfig{
Filename: "./client.go",
Package: "gen",
}
clientPlugin := clientgen.New(queries, clientPackage)
err = api.Generate(cfg,
api.AddPlugin(clientPlugin),
)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(3)
}
}
These codes have Japanese comments. Replace with English.
This client does not support subscription. If you need a subscription, please create an issue or pull request.
clientgen is created based on modelgen. So if you don't have a modelgen, it may be a mysterious move.