goliteql simplifies GraphQL server creation in Go by generating code from schema files. With a schema-first approach, it offers a lightweight solution with minimal dependencies while supporting essential GraphQL features. Ideal for developers seeking to streamline their GraphQL implementations without the overhead of full-featured servers.
goliteql is a lightweight, schema-first GraphQL code generator tailored for Go (Golang). It streamlines the process of generating GraphQL server code based on the http.Handler interface and schema files, making it an efficient choice for developers looking to implement GraphQL functionality without the overhead of additional dependencies.
As of the October 2021 Edition of the GraphQL specification, goliteql supports the following features:
| Feature | Status | Note |
|---|---|---|
| Query | ✅ | - |
| Mutation | ✅ | - |
| Subscription | ❌ | Parser supported, execution not implemented |
| Interface | ⚙️ | Parser supported, execution is beta |
| Union | ⚙️ | Parser supported, execution is beta |
| Enum | ⚙️ | Parser supported, execution is beta |
| Input | ✅ | - |
| Scalar | ❌ | Parser supported (custom scalars unsupported) |
| Directive | ❌ | Parser supported, directive execution not implemented |
| Fragment | ⚙️ | Parser supported, execution is beta |
| Type | ✅ | Object type definitions supported |
| Extend | ❌ | Parser supported, merging not yet implemented |
| Federation | ❌ | Not supported |
| Introspection | ❌ | Not supported |
| Validation | ❌ | Parser structures exist, runtime validation WIP |
goliteql does not aim to function as a fully-featured GraphQL server. For those requiring comprehensive GraphQL capabilities, alternatives like gqlgen may be more suitable.
To demonstrate how to set up goliteql, consider the following example:
main.go with the following content:package main
import (
"net/http"
"<your-module-name>/graphql/resolver"
)
func main() {
r := resolver.NewResolver()
http.ListenAndServe(":8080", r)
}
resolver/query.resolver.go:package resolver
import (
"context"
"github.com/n9te9/goliteql/internal/generated/graphql/model"
)
type QueryResolver interface {
Posts(ctx context.Context) ([]model.Node, error)
Post(ctx context.Context, id string) (model.Post, error)
Users(ctx context.Context) ([]model.User, error)
}
func (r *resolver) Posts(ctx context.Context) ([]model.Node, error) {
// Example implementation of the Posts resolver
}
$ go run main.go
When evaluated against other GraphQL code generators like gqlgen, goliteql shows significant performance advantages. The benchmarking results indicate that goliteql can generate ten posts at a remarkable speed of 19096 ns/op compared to gqlgen's 58628 ns/op:
$ go test -benchmem -v -bench .
For those interested in using goliteql solely as a parser, it can be easily integrated as follows:
package main
import (
"github.com/n9te9/goliteql/schema"
)
func main() {
lexer := schema.NewLexer()
parser := schema.NewParser(lexer)
ast, err := parser.Parse([]byte(`${Your schema}`))
if err != nil {
panic(err)
}
// ast is the abstract syntax tree of the schema
}
Contributions to goliteql are welcomed. Interested contributors are encouraged to fork the repository and submit pull requests. Before adding new features, it is advisable to create an issue to facilitate discussion. Bugs should also be reported through issues for swift resolution.
No comments yet.
Sign in to be the first to comment.