Node Interface
The standard GraphQL Relay Node interface for global entity identification.- Global Object Identification (Relay specification)
- Type-safe entity references using Global IDs
- Automatic node query field generation
- Cross-module entity references
Node interface when:
- Your schema implements types that extend
Node - You use the
@idOfdirective anywhere in your schema
node query to automatically route to the correct resolver.
Node Query Fields
Viaduct automatically provides root query fields for node resolution when your schema uses theNode interface.
- Decode the Global ID to extract type and internal ID
- Route to the appropriate type’s node resolver
- Return the resolved entity
node
Fetches a single entity by its Global ID.Global ID of the entity to fetch
Node - The entity, or null if not found
Example Query:
nodes
Fetches multiple entities by their Global IDs (batch operation).List of Global IDs to fetch
[Node]! - List of entities (nulls for not found)
Example Query:
Implementing Node Resolvers
When a type implementsNode, you must provide a node resolver:
The Global ID being resolved. Extract the internal ID with
ctx.id.internalIDDeployment-specific request context (auth, tracing, etc.)
PageInfo Type
Standard type for pagination metadata in Relay-style connections.@connection directive.
Fields:
Whether more items exist after the current page
Whether more items exist before the current page
Cursor of the first item in this page (null if page is empty)
Cursor of the last item in this page (null if page is empty)
Connection Types
Connection types follow the Relay Connection specification for cursor-based pagination. Pattern:Number of items to fetch from the start (forward pagination)
Cursor after which to start fetching (forward pagination)
Number of items to fetch from the end (backward pagination)
Cursor before which to start fetching (backward pagination)
Root Types
Viaduct intelligently manages root types based on your schema.Query
Always created. Required by the GraphQL specification. Usage:extend type Query, never define type Query directly. Viaduct creates the base Query type automatically.
Mutation
Created only when mutation extensions exist. Viaduct automatically creates theMutation root type when it detects extend type Mutation in your schema.
Usage:
Subscription
Created only when subscription extensions exist. Similar to Mutation, Viaduct creates this type when needed. Usage:Type Summary
| Type | Purpose | Auto-Included When |
|---|---|---|
Node | Global object identification interface | Types implement Node or @idOf is used |
Query.node | Fetch entity by Global ID | Node interface is included |
Query.nodes | Batch fetch entities by Global IDs | Node interface is included |
PageInfo | Pagination metadata | Connection types are defined |
Query | Root query type | Always (required by spec) |
Mutation | Root mutation type | extend type Mutation exists in schema |
Subscription | Root subscription type | extend type Subscription exists in schema |
Best Practices
Do
- Implement Node for entities - Use for globally identifiable objects
- Use Global IDs for references - Leverage
@idOffor type safety - Follow connection patterns - Use standard Relay pagination with
@connectionand@edge - Always extend root types - Use
extend type Query, nottype Query - Provide node resolvers - Implement efficient node resolution for all Node types
Don’t
- Don’t manually define Node interface - It’s added automatically when used
- Don’t manually implement node queries - They’re provided automatically
- Don’t redefine root types - Viaduct creates them automatically
- Don’t use Node for non-entities - Reserve for objects with stable identifiers
- Don’t expose internal IDs directly - Use Global IDs for public API
See Also
- Directives -
@resolver,@idOf,@connection,@edge - Scalars - Custom scalar types
- Tenant API - Implementing node resolvers