0
# Validation
1
2
Query validation tools for implementing security measures like query cost analysis and introspection control.
3
4
## Capabilities
5
6
### Query Cost Analysis
7
8
```python { .api }
9
cost_directive: SchemaDirectiveVisitor
10
"""Directive for annotating field costs in schema."""
11
12
cost_validator: Callable
13
"""Validator function for enforcing query cost limits."""
14
```
15
16
## Usage Examples
17
18
```python
19
from ariadne.validation import cost_directive, cost_validator
20
21
type_defs = """
22
directive @cost(complexity: Int, multipliers: [String!]) on FIELD_DEFINITION
23
24
type Query {
25
users: [User!]! @cost(complexity: 10)
26
user(id: ID!): User @cost(complexity: 1)
27
}
28
"""
29
30
schema = make_executable_schema(
31
type_defs,
32
query,
33
directives={"cost": cost_directive}
34
)
35
36
# Use cost validator
37
result = await graphql(
38
schema,
39
query_data,
40
validation_rules=[cost_validator(maximum_cost=100)]
41
)
42
```