Skip to main content

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

First page:
Next page:

Backward Pagination

Pagination Best Practices

  1. Use reasonable page sizes: 10-100 items per page depending on data size
  2. Store cursors, not offsets: Cursors remain valid even when data changes
  3. Check hasNextPage: Don’t assume there’s always a next page
  4. 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

Variables:

Property-Based Filtering

Some queries allow filtering by specific properties:
Variables:

Error Handling

The API uses two error patterns: GraphQL-level errors and mutation-level errors.

GraphQL Errors

GraphQL errors appear in the errors array at the top level:
Common GraphQL error types:
  • 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 the MutationError interface:
Example mutation with errors:
Response with validation error:

Error Handling Pattern

GeoJSON Support

The API has comprehensive GeoJSON support for geospatial data.

GeoJSON Types

Querying Geometry

Response:

GeoJSON Input

Example usage in mutations:

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

Response:

Entity References

Apollo Federation enables cross-subgraph entity resolution.

User References

Query user references:

Asset References

DateTime Handling

All timestamps use ISO-8601 format in UTC.

DateTime Format

Querying with DateTime

Variables:

Relative Time Queries

Some fields support relative time strings:

JSONObject Type

The JSONObject scalar represents arbitrary JSON data.

Querying JSON Properties

Response:

Filtering JSON Properties

Variables:

Correlation IDs

All mutations return a correlationId for tracking and debugging.
Providing your own correlation ID:
Use correlation IDs for:
  • Request tracking across systems
  • Debugging with support teams
  • Audit logging
  • Idempotency (some mutations)

Best Practices

  1. Request only needed fields: GraphQL allows precise field selection - use it to reduce payload size
  2. Use fragments for reusability: Define reusable fragments for common field sets
  3. Batch related queries: Use GraphQL’s ability to query multiple resources in one request
  4. Handle errors at both levels: Check for GraphQL errors AND mutation errors
  5. Store cursors for pagination: Cursors remain stable across data changes
  6. Use correlation IDs: Include them for better debugging and tracking
  7. Respect rate limits: Implement exponential backoff for retries
  8. Cache appropriately: Consider caching strategies based on data volatility

Next Steps