All Projects → Khan → genqlient

Khan / genqlient

Licence: MIT license
a truly type-safe Go GraphQL client

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to genqlient

graphql-codegen-apollo-next-ssr
Autogenerate apollo code for nextjs ssr
Stars: ✭ 176 (-66.92%)
Mutual labels:  codegen
TypedocConverter
This is a typedoc json to C# type bindings converter. Can be used as a TypeScript to C# bindings converter.
Stars: ✭ 89 (-83.27%)
Mutual labels:  codegen
go2dts
A simple cli-tools to transform golang `struct` and `const` to typescript `interface` and `type`
Stars: ✭ 44 (-91.73%)
Mutual labels:  codegen
EasyEE-Auto
EasyEE 自动化代码生成器。EasyEE Automated code generator.
Stars: ✭ 39 (-92.67%)
Mutual labels:  codegen
aws-mobile-appsync-sdk-android
Android SDK for AWS AppSync.
Stars: ✭ 101 (-81.02%)
Mutual labels:  codegen
react-native-xaml
A React Native Windows library to use XAML / WinUI controls
Stars: ✭ 55 (-89.66%)
Mutual labels:  codegen
graphql-java-codegen-gradle-plugin
Gradle plugin for graphql-java-codegen
Stars: ✭ 19 (-96.43%)
Mutual labels:  codegen
atbuild
Use JavaScript to generate JavaScript
Stars: ✭ 26 (-95.11%)
Mutual labels:  codegen
codegen
Generator for dart_native bindings. Codegen can transform native SDK to Flutter plugin.
Stars: ✭ 75 (-85.9%)
Mutual labels:  codegen
revgen
Speed up go:generate by auto detecting code changes
Stars: ✭ 20 (-96.24%)
Mutual labels:  codegen
gqty
a GraphQL client built for rapid iteration
Stars: ✭ 420 (-21.05%)
Mutual labels:  codegen
qpmodel
A Relational Optimizer and Executor
Stars: ✭ 54 (-89.85%)
Mutual labels:  codegen
apollo-typed-documents
Get type safety for your apollo documents.
Stars: ✭ 21 (-96.05%)
Mutual labels:  codegen
domainrobot-api
Swagger documentation for different APIs powered by InterNetX GmbH.
Stars: ✭ 14 (-97.37%)
Mutual labels:  codegen
UmaSupporter.WebClient
🏃🏽‍♀️ 우마무스메 육성 도우미 '우마서포터'의 프론트엔드 애플리케이션입니다.
Stars: ✭ 14 (-97.37%)
Mutual labels:  codegen
rosetta
Easy to use Rust i18n library based on code generation
Stars: ✭ 37 (-93.05%)
Mutual labels:  codegen
graphql-java-codegen
Make your GraphQL Java application schema-driven.
Stars: ✭ 167 (-68.61%)
Mutual labels:  codegen
CQRSAzure
CQRS on Windows Azure
Stars: ✭ 25 (-95.3%)
Mutual labels:  codegen
Uno.CodeGen
A set of source generators for equality, immutability, ...
Stars: ✭ 85 (-84.02%)
Mutual labels:  codegen
vertx-codegen
Vert.x code generator for asynchronous polyglot APIs
Stars: ✭ 95 (-82.14%)
Mutual labels:  codegen

generated graphql client ⇒ genqlient

Go Reference Test Status Contributor Covenant GoReportcard

genqlient: a truly type-safe Go GraphQL client

What is genqlient?

genqlient is a Go library to easily generate type-safe code to query a GraphQL API. It takes advantage of the fact that both GraphQL and Go are typed languages to ensure at compile-time that your code is making a valid GraphQL query and using the result correctly, all with a minimum of boilerplate.

genqlient provides:

  • Compile-time validation of GraphQL queries: never ship an invalid GraphQL query again!
  • Type-safe response objects: genqlient generates the right type for each query, so you know the response will unmarshal correctly and never need to use interface{}.
  • Production-readiness: genqlient is used in production at Khan Academy, where it supports millions of learners and teachers around the world.

How do I use genqlient?

You can download and run genqlient the usual way: go run github.com/Khan/genqlient. To set your project up to use genqlient, see the getting started guide, or the example. For more complete documentation, see the docs.

How can I help?

genqlient welcomes contributions! Check out the (Contribution Guidelines), or file an issue on GitHub.

Why another GraphQL client?

Most common Go GraphQL clients have you write code something like this:

query := `query GetUser($id: ID!) { user(id: $id) { name } }`
variables := map[string]interface{}{"id": "123"}
var resp struct {
	Me struct {
		Name graphql.String
	}
}
client.Query(ctx, query, &resp, variables)
fmt.Println(query.Me.Name)
// Output: Luke Skywalker

This code works, but it has a few problems:

  • While the response struct is type-safe at the Go level; there's nothing to check that the schema looks like you expect. Maybe the field is called fullName, not name; or maybe you capitalized it wrong (since Go and GraphQL have different conventions); you won't know until runtime.
  • The GraphQL variables aren't type-safe at all; you could have passed {"id": true} and again you won't know until runtime!
  • You have to write everything twice, or hide the query in complicated struct tags, or give up what type safety you do have and resort to interface{}.

These problems aren't a big deal in a small application, but for serious production-grade tools they're not ideal. And they should be entirely avoidable: GraphQL and Go are both typed languages; and GraphQL servers expose their schema in a standard, machine-readable format. We should be able to simply write a query and have that automatically validated against the schema and turned into a Go struct which we can use in our code. In fact, there's already good prior art to do this sort of thing: 99designs/gqlgen is a popular server library that generates types, and Apollo has a codegen tool to generate similar client-types for several other languages. (See docs/DESIGN.md for more prior art.)

genqlient fills that gap: you just specify the query, and it generates type-safe helpers, validated against the schema, that make the query.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].