Common Patterns
This guide covers common patterns you’ll use throughout the SensorUp GraphQL API.Pagination
The API uses Relay-style cursor-based pagination for all list queries. This provides consistent forward and backward pagination with cursor stability.Connection Structure
Forward Pagination
Backward Pagination
Pagination Best Practices
- Use reasonable page sizes: 10-100 items per page depending on data size
- Store cursors, not offsets: Cursors remain valid even when data changes
- Check hasNextPage: Don’t assume there’s always a next page
- Handle missing cursors: Some connections may not return cursors for every edge
Filtering
Most list queries support filtering through typed input objects.Time-Based Filtering
Property-Based Filtering
Some queries allow filtering by specific properties:Error Handling
The API uses two error patterns: GraphQL-level errors and mutation-level errors.GraphQL Errors
GraphQL errors appear in theerrors array at the top level:
- Validation errors: Invalid query syntax or schema violations
- Authentication errors: Missing or invalid credentials
- Authorization errors: Insufficient permissions
- Internal errors: Server-side issues
Mutation Errors
Mutations return errors in their result type using theMutationError interface:
Error Handling Pattern
GeoJSON Support
The API has comprehensive GeoJSON support for geospatial data.GeoJSON Types
Querying Geometry
GeoJSON Input
Coordinate Systems
- All coordinates use WGS84 (EPSG:4326)
- Coordinate order:
[longitude, latitude](GeoJSON standard) - Elevations can be included as third coordinate:
[lon, lat, elevation]
Audit Trails
Many types include audit information for tracking changes.Audit Type
Querying Audit Information
Entity References
Apollo Federation enables cross-subgraph entity resolution.User References
Asset References
DateTime Handling
All timestamps use ISO-8601 format in UTC.DateTime Format
Querying with DateTime
Relative Time Queries
Some fields support relative time strings:JSONObject Type
TheJSONObject scalar represents arbitrary JSON data.
Querying JSON Properties
Filtering JSON Properties
Correlation IDs
All mutations return acorrelationId for tracking and debugging.
- Request tracking across systems
- Debugging with support teams
- Audit logging
- Idempotency (some mutations)
Best Practices
- Request only needed fields: GraphQL allows precise field selection - use it to reduce payload size
- Use fragments for reusability: Define reusable fragments for common field sets
- Batch related queries: Use GraphQL’s ability to query multiple resources in one request
- Handle errors at both levels: Check for GraphQL errors AND mutation errors
- Store cursors for pagination: Cursors remain stable across data changes
- Use correlation IDs: Include them for better debugging and tracking
- Respect rate limits: Implement exponential backoff for retries
- Cache appropriately: Consider caching strategies based on data volatility
Next Steps
- Domain Guides - Explore specific use cases
- Subgraph Reference - Detailed schema documentation
- Federation Concepts - Understanding entity composition
- Performance - Optimization and best practices