fahchen

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@deprecated fields/arguments/enum values emit compile-time warnings
  • Typed responses — auto-generated Ecto embedded schemas, so result.data.user.name instead of result["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.Test for testing
  • ~GQL sigil + formatter pluginmix format auto-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!

Showing Posts 1 to 1

gtcode

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!

— All posts loaded —

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews