View Source Bonfire.API.GraphQL.QueryHelper (Bonfire v0.9.11-social-beta.6)

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

apply_overrides(fields, override_fun)

camelize(type)

do_format_fields(type, arg2, schema)

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

@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
}
```

fields_for(schema, type, nesting)

@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.

format_fields(fields, type, left_pad, schema)

get_fields(type, schema, nesting)

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

padding(left_pad)

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

@spec query_with_id(module(), atom(), non_neg_integer(), Keyword.t()) :: String.t()

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

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