Skip to content

josef-bolt/elixir_graphql_test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphqlTest

Minimal test application for the Neuron GraphQL client. Uses the public StarWars API.

Installation

Clone it; navigate to it.

$ git clone git@github.com:josef-bolt/elixir_graphql_test.git && cd elixir_graphql_test

Get dependencies.

$ mix deps.get

Usage

This is a demo tool intended to be used via iex.

$ iex -S mix
iex> GraphqlTest.StarwarsApi.fetch_planets()
{:ok,
 %Neuron.Response{
   body: %{
     "data" => %{
       "allPlanets" => %{
         "planets" => [
           %{
             "climates" => ["arid"],
             "id" => "cGxhbmV0czox",
             "name" => "Tatooine",
             "population" => 200000,
             "terrains" => ["desert"]
           },
           ...
        ]
      }
    }
  },
  headers: [
       {"access-control-allow-origin", "*"},
       {"cache-control", "no-cache"},
       {"content-length", "7818"},
       {"content-type", "application/json; charset=utf-8"},
       {"date", "Mon, 31 Jan 2022 14:20:31 GMT"},
       {"etag", "W/\"1e8a-b+q1kp1whzJvD32BuvoS6GMjEvk\""},
       {"server", "Netlify"},
       {"x-nf-request-id", "01FTR84EDA6RTNB89NH0ZJK4MA"},
       {"age", "0"},
       {"x-powered-by", "Express"}
     ],
     status_code: 200
   }}

iex> GraphqlTest.StarwarsApi.fetch_planet("cGxhbmV0czox")
{:ok,
 %Neuron.Response{
   body: %{
     "data" => %{
       "planet" => %{
         "id" => "cGxhbmV0czox",
         "name" => "Tatooine",
         "population" => 200000
       }
     }
   },
   headers: [
     {"access-control-allow-origin", "*"},
     {"cache-control", "no-cache"},
     {"content-length", "79"},
     {"content-type", "application/json; charset=utf-8"},
     {"date", "Mon, 31 Jan 2022 14:25:55 GMT"},
     {"etag", "W/\"4f-EFDg6CNzNZhGLm+HShmcdE/8+l0\""},
     {"server", "Netlify"},
     {"x-nf-request-id", "01FTR8EAFTJQ9BFGE0ZH5G2TEE"},
     {"age", "0"},
     {"x-powered-by", "Express"}
   ],
   status_code: 200
 }

The magic is split between three modules.

  1. GraphqlTest.Client defines a GraphQL client behaviour making it easier to swap out implementations and to test using a robust mocking library like Mox which allows for safe async mocking in tests.
  2. GraphqlTest.Neuron implements GraphqlTest.Client using the Neuron library.
  3. GraphqlTest.StarwarsApi implements the logic specific for hitting the StarWars API.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages