uesteibar/neuron
{ "createdAt": "2017-05-28T12:05:16Z", "defaultBranch": "master", "description": "A GraphQL client for Elixir", "fullName": "uesteibar/neuron", "homepage": "https://hex.pm/packages/neuron", "language": "Elixir", "name": "neuron", "pushedAt": "2023-02-22T09:36:12Z", "stargazersCount": 333, "topics": [ "elixir", "elixir-lang", "elixir-library", "graphql", "graphql-client", "hex" ], "updatedAt": "2025-10-02T15:39:00Z", "url": "https://github.com/uesteibar/neuron"}A GraphQL client for Elixir.
- [Installation]!(#installation)
- [Usage]!(#usage)
- [Running Locally]!(#running-locally)
- [Contributing]!(#contributing)
Installation
Section titled “Installation”def deps do [ {:neuron, "~> 5.1.0"} ]endJSON library
Section titled “JSON library”Neuron defaults to using Jason for JSON encoding and decoding. To use Jason, add it to your deps:
{:jason, "~> 1.1"}It is also possible to customize which JSON library that is used:
Neuron.Config.set(json_library: AnotherJSONLibrary)Connection
Section titled “Connection”Neuron defaults to using HTTP(S) protocol with HTTPoison for Connecting to GraphQL endpoint. You can however customize that behaviour, by providing custom library, which should implement Neuron.Connection behaviour:
defmodule MyConnection do @behaviour Neuron.Connection
@impl Neuron.Connection def call(body, options) do IO.inspect("NEURON CALLED") Neuron.Connection.Http.call(body, options) endendThen set it up in config:
Neuron.Config.set(connection_module: MyConnection)iex> Neuron.Config.set(url: "https://example.com/graph")
iex> Neuron.query(""" { films { count } } """)Response will be:
{:ok, %Neuron.Response{body: %{"data" => %{"films" => %{ "count": 123 }}}, status_code: 200, headers: []}}You can also run mutations:
iex> Neuron.query(""" mutation createUser($name: String!) { createUser(name: $name) { id name } } """, %{name: "uesteibar"} )You can also set url and headers as shown below:
iex> Neuron.query(""" mutation createUser($name: String!) { createUser(name: $name) { id name } } """, %{name: "uesteibar"}, url: "https://example.com/graph", headers: [authorization: "Bearer <token>"] )Overriding HTTP Timeout
Section titled “Overriding HTTP Timeout”HTTPoison default timeout is 5000ms, in case we need to handle longer timeout, using default Neuron.Connection module, we could set connection_opts which will be passed to HTTPoison. So to override timeout to 15000ms, we could do:
iex> Neuron.Config.set(url: "https://example.com/graph", connection_opts: [recv_timeout: 15_000])
iex> Neuron.query(""" { films { count } } """)We can also set the timeout for a single request by passing the connection_opts to Neuron.query/3 instead:
iex> Neuron.query("...", %{}, connection_opts: [recv_timeout: 15_000])More extensive documentation can be found at https://hexdocs.pm/neuron.
Running locally
Section titled “Running locally”Clone the repository:
git clone git@github.com:uesteibar/neuron.gitInstall dependencies:
cd neuronmix deps.getTo run the tests:
mix testStyle guide
Section titled “Style guide”Code is formatted with mix format and mix credo should not show warnings.
To format the code and run static code analysis with credo
mix formatmix credoContributing
Section titled “Contributing”Pull requests are always welcome =)
The project uses standard-changelog to update the Changelog with each commit message and upgrade the package version.
For that reason every contribution should have a title and body that follows the conventional commits standard conventions (e.g. feat(connection): Make it smarter than Jarvis).
To make this process easier, you can do the following:
Install commitizen and cz-conventional-changelog globally:
npm i -g commitizen cz-conventional-changelogSave cz-conventional-changelog as default:
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrcInstead of git commit, you can now run:
git czand follow the instructions to generate the commit message.
Copyright and License
Section titled “Copyright and License”Copyright (c) 2017 Unai Esteibar
This software is released under the [Internet Systems Consortium License]!(./LICENSE.md).