ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - uesteibar/neuron: A GraphQL client for Elixir
A GraphQL client for Elixir. Contribute to uesteibar/neuron development by creating an account on GitHub.
Visit Site

GitHub - uesteibar/neuron: A GraphQL client for Elixir

GitHub - uesteibar/neuron: A GraphQL client for Elixir

Build Status Hex Version

A GraphQL client for Elixir.

Index

Installation

def deps do
  [
    {:neuron, "~> 5.1.0"}
  ]
end

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

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)
  end
end

Then set it up in config:

Neuron.Config.set(connection_module: MyConnection)

Usage

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

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

Clone the repository:

git clone [email protected]:uesteibar/neuron.git

Install dependencies:

cd neuron
mix deps.get

To run the tests:

mix test

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 format
mix credo

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-changelog

Save cz-conventional-changelog as default:

echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc

Instead of git commit, you can now run:

git cz

and follow the instructions to generate the commit message.

Copyright and License

Copyright (c) 2017 Unai Esteibar

This software is released under the Internet Systems Consortium License.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory