This module defines helper macros to work with Graphql and Guardian
Summary
Functions
Call this macro in the module you wish to load your GQL document from a file.
Call this macro in the module you wish to load your GQL document from a query string.
Execute a GraphQL query or mutation against the configured endpoint.
Functions
Call this macro in the module you wish to load your GQL document from a file.
It takes one argument, the path to a GQL file that contains a GraphQL query or mutation.
For example:
defmodule MyApp do
load_gql_file "assets/js/queries/MyQuery.gql"
# ...
end
Call this macro in the module you wish to load your GQL document from a query string.
It takes one argument, a string containing a GraphQL query or mutation.
For example:
defmodule MyApp do
load_gql_string """
query {
hello
}
"""
# ...
end
Execute a GraphQL query or mutation against the configured endpoint.
The query is resolved from two sources, in priority order:
- The
query:option (runtime) — used if provided - The
@_gql_querymodule attribute — fallback (set viaload_gql_fileorload_gql_string)
If neither is present, raises SetupError.
Whether a document was loaded is decided when query_gql/1 is expanded, so
load_gql_file/1 or load_gql_string/1 must appear before the functions
that call query_gql/1.
Options
query- a GraphQL query string (optional ifload_gql_file/load_gql_stringwas used)variables- a map of GraphQL variables (default:%{})current_user- a user map for JWT authentication (optional)headers- a list of{key, value}header tuples (optional)
Examples
# Per-call inline query
query_gql(query: "query { hello }", variables: %{})
# Using module-level query (legacy)
load_gql_file "queries/Hello.gql"
query_gql(variables: %{})