Field Filtering
Field filtering provides powerful control over field visibility, allowing you to:
- Hide sensitive fields from specific types
- Create read-only or write-only fields
- Version your API by selectively exposing fields
- Use
@gqlIgnoreAllfor opt-in field inclusion
Quick Reference
| Tag | Behavior | Example |
|---|---|---|
ro | Read-only (types only, excluded from inputs) | gql:"createdAt,ro" |
wo | Write-only (inputs only, excluded from types) | gql:"password,wo" |
rw | Read-write (included everywhere) | gql:"name,rw" |
include | Include in specific types/inputs | gql:"email,include:UserV2" |
omit / ignore | Exclude from specific types/inputs | gql:"internal,omit:PublicUser" |
Read-Only Fields (ro)
Fields marked with ro appear only in types, not in inputs:
Generated:
Use case: Timestamps, IDs, computed fields
Write-Only Fields (wo)
Fields marked with wo appear only in inputs, not in types:
Generated:
Use case: Passwords, secrets, confirmation codes
Read-Write Fields (rw)
Fields marked with rw are included everywhere:
All fields appear in both User type and UserInput.
Use case: Explicit inclusion, overriding @gqlIgnoreAll
Field-Specific Filtering with include and omit
Include Field in Specific Types
Use include: to include a field only in specific types:
Generated:
Omit Field from Specific Types
Use omit: or ignore: to exclude a field from specific types:
Generated:
Note: omit and ignore are aliases (identical behavior)
Multiple Type Filtering
Apply filtering rules to multiple types using comma-separated lists:
Syntax rules:
- Multiple types: Use quotes with commas:
"Type1,Type2,Type3" - No spaces:
"AdminView,UserView"not"AdminView, UserView" - Single type: Quotes optional:
include:AdminVieworinclude:"AdminView"
Type-Specific Read/Write Rules
Combine ro/wo with type lists for fine-grained control:
Result:
secretfield:- ✓ In
AdminViewtype - ✗ Not in
UserView,AdminInput,UserInput
- ✓ In
balancefield:- ✓ In
AdminViewandUserViewtypes - ✗ Not in
AdminInputorUserInput
- ✓ In
passwordfield:- ✓ In
AdminInputandUserInput - ✗ Not in
AdminVieworUserView
- ✓ In
The @gqlIgnoreAll Directive
Use @gqlIgnoreAll to ignore all fields by default, then selectively include fields:
Generated:
Use case: Security-first approach, expose only explicitly included fields
Wildcard Usage
Use * to apply a rule to all types/inputs:
Equivalents:
include:*=include=rw:*=rw
API Versioning Example
Create multiple versions of the same type with different field sets:
Generated:
Rules and Precedence
@gqlIgnoreAllignores all fields by default- Explicit
include,rwoverrides@gqlIgnoreAll omit,ignoretakes precedence over default inclusion- Type-specific rules override global rules (
ro,wo,rw) - Wildcard
*applies to all types/inputs
Best Practices
- Use
rofor timestamps and IDs: Prevents modification in inputs - Use
wofor passwords: Keeps secrets out of type schemas - Use
@gqlIgnoreAllfor security: Opt-in approach for sensitive data - Version with
include: Incrementally expose fields across API versions - Document filtering logic: Make field visibility rules clear in comments
Once you've configured field filtering, run:
$ gqlschemagen generateto generate schemas with precise field control.