pub struct QueryMatcher { /* private fields */ }Expand description
Query pattern matcher.
Matches incoming GraphQL queries against the compiled schema to determine which pre-compiled SQL template to execute.
Implementations§
Source§impl QueryMatcher
impl QueryMatcher
Sourcepub fn new(schema: CompiledSchema) -> Self
pub fn new(schema: CompiledSchema) -> Self
Create new query matcher.
Indexes are (re)built at construction time so that match_query
works correctly regardless of whether build_indexes() was called
on the schema before passing it here.
Sourcepub const fn with_max_depth(self, max_depth: u32) -> Self
pub const fn with_max_depth(self, max_depth: u32) -> Self
The same matcher, refusing a selection nested deeper than max_depth.
Sourcepub fn match_query(
&self,
query: &str,
variables: Option<&Value>,
) -> Result<QueryMatch>
pub fn match_query( &self, query: &str, variables: Option<&Value>, ) -> Result<QueryMatch>
Match a GraphQL query to a compiled template.
§Arguments
query- GraphQL query stringvariables- Query variables (optional)
§Returns
QueryMatch with query definition and extracted information
§Errors
Returns error if:
- Query syntax is invalid
- Query references undefined operation
- Query structure doesn’t match schema
- Fragment resolution fails
- Directive evaluation fails
§Example
// Requires: compiled schema.
// See: tests/integration/ for runnable examples.
let matcher = QueryMatcher::new(schema);
let query = "query { users { id name } }";
let matched = matcher.match_query(query, None)?;
assert_eq!(matched.query_def.name, "users");Sourcepub fn match_query_with_operation_name(
&self,
query: &str,
variables: Option<&Value>,
operation_name: Option<&str>,
) -> Result<QueryMatch>
pub fn match_query_with_operation_name( &self, query: &str, variables: Option<&Value>, operation_name: Option<&str>, ) -> Result<QueryMatch>
Match a document against the compiled schema, selecting the operation
named by operation_name (GraphQL § 6.1).
match_query is this with None, which requires
the document to define exactly one operation.
The executor threads the request’s name here as well as into classification: this function re-parses the document, so leaving it to take the first operation would classify one operation and then match a different one.
§Errors
Returns FraiseQLError::Parse if the document does not parse, names
no such operation, or is ambiguous; FraiseQLError::NotFound if the
root field matches no compiled query.
Sourcepub fn extract_arguments(variables: Option<&Value>) -> HashMap<String, Value>
pub fn extract_arguments(variables: Option<&Value>) -> HashMap<String, Value>
Build the variables map exposed on QueryMatch::arguments from the
raw GraphQL variables JSON payload.
This is the public entry point used by tests; internally the
match_query hot path now constructs the same map exactly once
via a private helper.
Sourcepub const fn schema(&self) -> &CompiledSchema
pub const fn schema(&self) -> &CompiledSchema
Get the compiled schema.