Skip to main content

parse_graphql_document

Function parse_graphql_document 

Source
pub fn parse_graphql_document(
    query: &str,
) -> Result<Document<'_, String>, ComplexityValidationError>
Expand description

Parse a GraphQL query source into a graphql_parser document.

This is the only place in the workspace that calls graphql_parser::parse_query. Every other parse — the validator, the analyzer, the subscription name extractor, the REST validate endpoint — comes through here, because the parser can panic on input a client controls (see below) and a guard is only worth having if nothing can walk around it. tools/check-graphql-parse-sites.sh fails the build if a second call site appears.

Exposed so the server’s HTTP handler can parse the request exactly once and reuse the AST for both complexity validation (via RequestValidator::validate_query_doc) and the downstream execution path — replacing the previous “validate then re-parse” pattern. See F001 in docs/history/IMPROVEMENTS.md.

§Errors

Returns ComplexityValidationError::MalformedQuery when the source fails to parse as a GraphQL query document, when it carries block-string indentation graphql-parser cannot handle (#976), or when the parser panics.