Use Variables
Always use variables for dynamic values instead of hardcoding.
Anti-Patternβ
# BAD: Hardcoding values
query {
atoms(where: { type: { _eq: Person } }) {
term_id
label
}
}
Best Practiceβ
# GOOD: Using variables
query GetAtomsByType($type: atom_type!) {
atoms(where: { type: { _eq: $type } }) {
term_id
label
}
}
Variables:
{
"type": "Person"
}
Benefitsβ
- Reusability: Same query, different values
- Type safety: GraphQL validates variable types
- Security: Prevents injection attacks
- Caching: Better query plan caching