Grapher v0.7.1 Grapher.GraphQL.Formatter View Source

The GraphQL Formatter module is responsible for handling translation from GraphQL’s camelCase to Elixir snake_case and vice versa.

Link to this section Summary

Functions

Converts the keys in a given map to snake_case. This is useful when dealing with a raw GraphQL request so your eyes don’t start to bleed

Converts keys in a given map to camelCase mostly because JavaScript hates readability in general and specifically with variable names

Link to this section Functions

Link to this function to_elixir(response) View Source
to_elixir(map()) :: map()

Converts the keys in a given map to snake_case. This is useful when dealing with a raw GraphQL request so your eyes don’t start to bleed.

Parameters

  • map: The map which sould have it’s keys converted

Examples

iex> Formatter.to_elixir(%{"userId" => "bob", "name" => "Uncle Bob"})
%{user_id: "bob", name: "Uncle Bob"}

iex> Formatter.to_elixir(%{"userId" => "bob", "profile" => %{"personalSummary" => "Buy my crap"}})
%{user_id: "bob", profile: %{personal_summary: "Buy my crap"}}
Link to this function to_graph_ql(payload) View Source
to_graph_ql(nil | map()) :: map()

Converts keys in a given map to camelCase mostly because JavaScript hates readability in general and specifically with variable names.

Parameters

  • map: the map which should have it’s keys converted

Examples

iex> Formatter.to_graph_ql(%{user_id: "bob", name: "Uncle Bob"})
%{"userId" => "bob", "name" => "Uncle Bob"}

iex> Formatter.to_graph_ql(%{user_id: "bob", profile: %{personal_summary: "Buy my crap"}})
%{"userId" => "bob", "profile" => %{"personalSummary" => "Buy my crap"}}