Julia Code Generation With GraphQL
Laurium Labs is pleased to publish open source software that assists Julia clients that are consuming GraphQL apis.
GraphQL is a "query language for your API" that is aimed to be a replacement for REST.
A GraphQL client requests exactly which data to get back, unlike REST, where a "hope-and-pray" paradigm is employed. The beauty of GraphQL queries is that the resulting JSON of a request comes back in a predictable format. This allows for generating native types (TypeScript, Julia, Swift, Java etc.) that automatically are populated from the response JSON.
I built Waldo using this technique extensively, with >100 GraphQL queries and their associated auto-genned types. It works fantastically well and almost feels like cheating.
Without further ado, let's get into the code!
- https://github.com/laurium-labs/GraphQLCodegen.jl has tools for labeling GraphQL queries and for parsing GraphQL response JSON to Julia Named Tuples
- https://github.com/laurium-labs/GithubGraphQLExample.jl is a working example of how to use the above 2 tools to query the GitHub GraphQL API. Here is a video walkthrough: https://vimeo.com/530875067
I recommend starting at the GithubGraphQLExample to understand how the tools work together. It's not a minor endeavor, but if you're going to be writing many GraphQL queries in Julia, it's worth it.
As consumers of much open source software, Laurium Labs is happy to contribute back to the Julia and GraphQL communities.
If you are endeavoring on a project using GraphQL and Julia, we'd love to hear about it!