View Source Bonfire.API.GraphQL.QueryHelper (Bonfire v0.9.10-classic-beta.169)

Helpful functions for preparing to query or test Absinthe applications.

These functions make it trivially easy to generate very large, comprehensive queries for our types in Absinthe that will resolve every field in that type (and any number of subtypes as well to a given level of depth)

Adapted from https://github.com/devonestes/assertions (MIT license)

Summary

Functions

Link to this function

apply_overrides(fields, override_fun)

View Source
Link to this function

do_format_fields(type, arg2, schema)

View Source
Link to this function

document_for(schema, type, nesting \\ 1, override_fun \\ nil)

View Source
@spec document_for(module(), atom(), non_neg_integer(), Keyword.t()) :: String.t()

Returns a document containing the fields in a type and any sub-types down to a limited depth of nesting (default 3).

This is helpful for generating a document to use for testing your GraphQL API. This function will always return all fields in the given type, ensuring that there aren't any accidental fields with resolver functions that aren't tested in at least some fashion.

Example

iex> document_for(:user, 2)

```
name
age
posts {
  title
  subtitle
}
comments {
  body
}
```
Link to this function

fields_for(schema, type, nesting)

View Source
@spec fields_for(module(), atom(), non_neg_integer()) :: [fields] | atom()
when fields: atom() | {atom(), [fields]}

Returns all fields in a type and any sub-types down to a limited depth of nesting (default 3).

This is helpful for converting a struct or map into an expected response that is a bare map and which can be used in some of the other assertions below.

Link to this function

format_fields(fields, type, left_pad, schema)

View Source
Link to this function

get_fields(type, schema, nesting)

View Source
Link to this function

maybe_debug_api(q, obj, debug, msg \\ "The below GraphQL query had some errors in the response")

View Source
Link to this function

query_with_id(schema, type, nesting \\ 1, override_fun \\ nil)

View Source
@spec query_with_id(module(), atom(), non_neg_integer(), Keyword.t()) :: String.t()
Link to this function

run_query_id(id, schema, type, nesting \\ 1, override_fun \\ nil, debug \\ nil)

View Source
@spec run_query_id(
  any(),
  module(),
  atom(),
  non_neg_integer(),
  Keyword.t(),
  boolean()
) :: String.t()