Skip to main content

graphql_query

Macro graphql_query 

Source
graphql_query!() { /* proc-macro */ }
Expand description

Validate a GraphQL query or mutation against the embedded Sui schema at compile time and return it as a &'static str.

One or more sources can be supplied. An inline source is a string literal; prefix a path with @ to load it from a UTF-8 file relative to the Rust source file containing the macro invocation. Sources are concatenated in order before the complete document is validated. File sources are terminated with a newline so trailing comments cannot consume the next source; inline literals are concatenated verbatim. This allows operations and fragments to be kept separately:

ⓘ
const QUERY: &str = graphql_query!(
    @"queries/get-chain.graphql",
    @"queries/chain-fragment.graphql",
);

On a syntactically or semantically invalid input (unknown field, wrong argument type, undefined variable, etc.) the macro emits one compile_error! per Bluejay diagnostic, so the offending call site fails to build with the diagnostic text inline.

Inline inputs must be literals. A procedural macro runs before Rust name resolution and therefore cannot read the value behind a path to a Rust string constant while retaining compile-time GraphQL validation.