Skip to main content

Query template instances

Deprecation

Templates is being superseded with the released data modeling capabilities. See Data modeling for more information.

You can query the template instances by using GraphQL. A query has these key sections:

  • A query intent (query MyQueryName {, or just { as a shorthand.
  • The query to run. For templates this is usually <type>Query, for example countryQuery with an optional alias, myAlias: countryQuery)
  • The query parameters. For example, filter: {...} or limit: 1000.
  • The fields to return at a specified depth.

GraphQL example

query myQuery {
countryQuery {
items {
name
demographics {
populationSize
growthRate
}
deaths {
datapoints(limit: 100) {
timestamp
value
}
}
}
nextCursor
}
demographicsQuery(
filter: {
_and: [{ populationSize: { gte: 2 } }, { populationSize: { lte: 10 } }]
}
) {
items {
populationSize
growthRate
metadata {
key
value
}
}
}
}

Where:

  • myQuery declares the query intent.
  • The queries to run are countryQuery and demographicsQuery.
  • The parameters are Country:100 for the death time series data points, and the Demographics: filter of populationSize between 2 and 10.
  • The fields to return, for Country: items -> name, demographic -> populationSize, growthRate, etc.

For more information, see the GraphQL documentation.

Fields and parameters for queries

For <type>Query you can use these fields and parameters:

  • Fields

    • items - the actual items to be returned.
    • nextCursor - the next set of items that can be returned. You specify this for the next query.
  • Parameters

    • filter - the filter you want to provide based on the fields in your data model.
    • cursor - the nextCursor from the previous query.
    • limit - the maximum number of items to return. To fetch more items, use a anew query using the nextCursor parameter (Default: 1000).

Filter types

FieldFilterHow to use
Top level filtersAny_and{_and: [{...},{...}]}
_or{_or: [{...},{...}]}
PrimitivesStringeq{eq: "..."}
anyOfTerms{anyOfTerms: ["..."]}
Long/Int/Floateq{eq: ...}
lt{lt: ...} = less than
gt{gt: ...} = greater than
lte{lte: ...} = less than or equals
gte{gte: ...} = greater than or equals
BooleanN/AN/A
CDF resourcesAssetN/AN/A
TimeSeriesN/AN/A
SyntheticTimeSeriesN/AN/A
SequenceN/AN/A
FileN/AN/A
EventN/AN/A

Query fields for CDF types

The sections below, describe the fields you can specify under type when querying built-in CDF types.

For example, Asset -> MetadataItem has the key and value fields that you can specify in your query:

# ...
asset {
metadata{
key
value
}
}
# ...

Common for all resource types

type MetadataItem {
key: String
value: String
}

Time series

type DatapointString implements Datapoint {
timestamp: Long!
value: Float
stringValue: String
}

type DatapointFloat implements Datapoint {
timestamp: Long!
value: Float
}

type DatapointInt {
timestamp: Long!
value: Int
}

type AggregationResult {
average: [DatapointFloat]
max: [DatapointFloat]
min: [DatapointFloat]
count: [DatapointInt]
sum: [DatapointFloat]
interpolation: [DatapointFloat]
stepInterpolation: [DatapointFloat]
continuousVariance: [DatapointFloat]
discreteVariance: [DatapointFloat]
totalVariation: [DatapointFloat]
}

type TimeSeries {
id: Long
name: String
metadata: [MetadataItem]
description: String
externalId: String
isString: Boolean
isStep: Boolean
unit: String
datapoints(start: Long, end: Long, limit: Int! = 100): [Datapoint]
aggregatedDatapoints(
start: Long
end: Long
limit: Int! = 100
granularity: String!
): AggregationResult
latestDatapoint: Datapoint
}

Synthetic time series

type SyntheticTimeSeries {
name: String
metadata: [MetadataItem]
description: String
isStep: Boolean
unit: String
datapointsWithGranularity(
start: Long
end: Long
limit: Int! = 100
granularity: String
): [Datapoint]
datapoints(start: Long, end: Long, limit: Int! = 100): [Datapoint]
}

Assets

type Asset {
id: Long!
externalId: String
name: String!
description: String
root: Asset
parent: Asset
source: String
metadata: [MetadataItem]
}

Files

type File {
id: Long!
externalId: String
name: String!
directory: String
mimeType: String
source: String
metadata: [MetadataItem]
dataSetId: Long
assets: [Asset]
sourceCreatedTime: Long
sourceModifiedTime: Long
uploaded: Boolean!
uploadedTime: Long
createdTime: Long!
lastUpdatedTime: Long!
downloadUrl: String
}

Sequences

type Sequence {
id: Long!
name: String
description: String
assetId: String
externalId: String
metadata: [MetadataItem]
dataSetId: Long
createdTime: Long!
lastUpdatedTime: Long!
}

SDK documentation