fahchen
Hi everyone! I’d like to share Grephql, a compile-time GraphQL client for Elixir.
Motivation
Most existing Elixir GraphQL clients are runtime-only — queries are parsed and sent as plain strings, with responses decoded into plain maps. This means typos, schema mismatches, and type errors only surface at runtime.
Grephql takes a different approach: it parses and validates your GraphQL queries at compile time against your schema, and generates typed Ecto embedded schemas for both responses and variables.
Features
- Compile-time validation — syntax errors and schema mismatches are caught by
mix compile, with line:column positions pointing into your source - Deprecation warnings —
@deprecatedfields/arguments/enum values emit compile-time warnings - Typed responses — auto-generated Ecto embedded schemas, so
result.data.user.nameinstead ofresult["data"]["user"]["name"] - Typed variables — input validation via Ecto changesets
- Zero runtime parsing — all GraphQL parsing happens at compile time
- Req integration — full access to Req’s middleware/plugin system, including
Req.Testfor testing ~GQLsigil + formatter plugin —mix formatauto-formats your GraphQL strings- Fragments, unions, interfaces, aliases — all supported
Quick example
defmodule MyApp.GitHub do
use Grephql,
otp_app: :my_app,
source: "priv/schemas/github.json",
endpoint: "https://api.github.com/graphql"
defgql :get_user, ~GQL"""
query GetUser($login: String!) {
user(login: $login) {
name
bio
}
}
"""
end
# Typed access — no more map key typos
{:ok, result} = MyApp.GitHub.get_user(%{login: "octocat"})
result.data.user.name #=> "The Octocat"
# Invalid variables are caught before the HTTP call
{:error, %Ecto.Changeset{}} = MyApp.GitHub.get_user(%{})
Testing with Req.Test
# config/test.exs
config :my_app, MyApp.GitHub,
req_options: [plug: {Req.Test, MyApp.GitHub}]
# In your test
Req.Test.stub(MyApp.GitHub, fn conn ->
Req.Test.json(conn, %{
"data" => %{"user" => %{"name" => "Alice", "bio" => "Elixirist"}}
})
end)
assert {:ok, result} = MyApp.GitHub.get_user(%{login: "alice"})
assert result.data.user.name == "Alice"
Real-world examples
For more real-world examples — including a GitHub API client (5.9MB schema, nested connections, mutations, input objects) and a Shopify Admin API client (10MB schema, products, orders, customers) — see the examples/ directory.
Links
https://github.com/fahchen/grephql
Would love to hear any feedback or questions!
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
gtcode
Nice I’ll check it out tomorrow
in the meantime check out prismatic:
Https://github.com/nshkrdotcom/prismatic
Shipped linear sdk with it:
https://github.com/nshkrdotcom/linear_sdk
Glad to see the ecosystem expanding!