Tomek Poniatowicz
11/2/2021
GraphQL is a new query language for APIs that was developed by Facebook. It's similar to REST but provides clients with more control over what data they get back from the server and how it’s formatted. The main benefit of GraphQL is increased performance: you only fetch the data you need, and not everything. This library will help programmers write type-safe GraphQL queries using Go as it takes advantage of both "languages" being type-safe so there won't be any errors at compile time!
genqlientis a GraphQL client written in Go aiming to provide even more type-safety for your GraphQL APIs. It takes advantage of the fact that both Go & GraphQL are strongly typed and impose a rigorous set of rules thus guaranteeing a certain consistency of results.
So in general what's the difference between genqlient and other GraphQL clients or what it has to offer that others don't? It guarantees no errors at compile-time or risks of executing your queries incorrectly because they can always be checked for validity beforehand.
As mentioned by genqlient's author, most popular Go GraphQL clients will make you write your code more or less like this:
The above code works, but there is definitely space for improvements as:
{"id": true}
and you won't notice until runtime,So what genqlient has to offer that others don't?
Say goodbye to runtime errors as Genqlient provides a compile-time validation of your GraphQL queries making sure you won't ship an invalid GraphQL query again which means no more runtime errors!
To achieve this, Genqlient uses Go's powerful type system to ensure that any invalid query would be caught at compile time.
Genqlient generates the right type for each query, so you know the response will unmarshal correctly. GenQLient takes advantage of Go is a statically-typed language and compiles both GraphQL schema declaration and queries to types which makes it easy for us to generate result type for any query.