Skip to content

Data Schema Code Templates

You are welcome to setup and configure data schemas within the DDK, but you may also want to see more complex schemas. For this reason, we've included some code snippets of schemas that you can use below.

Adding Your Own GraphQL Schema Code

  1. In your new schema, click on the code icon in the center top-right hand of the panel (green box in the screenshot)

  2. Paste in code from below and save

Code icon in DDK

Use Case: Simple Traffic Simulation Example

Industry: Transport

Click here to expand...

Note: This is the same schema you would have made for your sample project in the getting started materials.

graphql
enum MapType {
	SCATTER
	PATH
	POLYGON
}

type SimInput @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	placeName: String!
}

type SimResult @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	dtTimestamp: Int!
	result: String!
}

type MapLayerResult @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	mapLayerName: String!
	result: String!
	dtTimestamp: Int!
	mapType: MapType!
}

Use Case: Agentic Worker

Relevant Industry: Generic

Click here to expand...

This schema is useful for agentic workflows where you want to capture what the agent is doing and the outputs.

graphql
enum LogType {
	INFO
	SUCCESS
}

enum AgentType {
	ONDEMAND
	SCHEDULE
}

type Agent @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	agentId: ID! @constraint(type: "primarykey")
	name: String!
	description: String!
	workflowId: ID!
	configValues: JSON
	runs: [AgentRun] @mapping(type: "one2many", foreignKey: "agentId", foreignKeyReference: "agentId")
	agentType: AgentType!
}

type Workflow @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	workflowId: ID! @constraint(type: "primarykey")
	useCase: String!
	config: JSON
	agents: [Agent] @mapping(type: "one2many", foreignKey: "workflowId", foreignKeyReference: "workflowId")
	name: String!
	description: String
}

type AgentRunLogs @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	runId: ID! @constraint(type: "primarykey")
	dtTimestamp: Int! @constraint(type: "primarykey")
	agentId: ID!
	content: String!
	role: String!
	eventStatus: String!
	logType: String!
}

type AgentRunData @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	runId: ID! @constraint(type: "primarykey")
	dtTimestamp: Int!
	data: String
	taskId: String
	agentId: ID!
}

type AgentRun @required(type: "CREATE, READ, UPDATE, DELETE", table: "true", trigger: "true") {
	runId: ID! @constraint(type: "primarykey")
	agentId: ID!
	dtTimestamp: Int!
	prompt: String!
	completed: Boolean!
	agentRunLogs: [AgentRunLogs] @mapping(type: "one2many", foreignKey: "runId", foreignKeyReference: "runId")
	agentRunData: AgentRunData @mapping(type: "one2one", foreignKey: "runId", foreignKeyReference: "runId")
	runName: String!
	description: String
	workflowId: ID!
	configValues: JSON
}

Use Case: Transport & Logistics

Industry: Fuel Retailer

Click here to expand...

This schema maps out the logistics and transport network for a fuel retailer. Including objects such as terminals, retailers and ports.

graphql
enum PoiTypeEnum {
    TERMINAL
    RETAILER
    CHARGINGSTATION
    PORT
    RIG
}

type Poi @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	"""long lat, 145, -37"""
	coordinates: [Float]!
	name: String
	poiType: PoiTypeEnum!
	geojson: String
	upstreamPoiID: ID
	downstreamPois: [Poi]! @mapping(type: "one2many", foreignKey: "upstreamPoiID", foreignKeyReference: "id")
	vehicle: [Vehicle]! @mapping(type: "one2many", foreignKey: "restingPoiID", foreignKeyReference: "id")
	historic: [PoiHistoric]! @mapping(type: "one2many", foreignKey: "id", foreignKeyReference: "id")
}

type PoiTest @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	poiID: ID! @constraint(type: "primarykey")
	coordinates: [Float]!
	name: String
	poiType: PoiTypeEnum!
	geojson: String
	upstreamPoiID: ID
}

type PoiFuel @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	fuelType: FuelType! @constraint(type: "primarykey")
	capacity: Int!
	demandPerHour: Float
	maintainenceCycle: Int!
}

enum FuelType {
    UNLEADED
    DIESEL
}

type PoiActual @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	fuelType: String
	available: Int
	refillCount: Int
	faultDescription: String
}

type PoiHistoric @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	dtTimestamp: Int! @constraint(type: "primarykey")
	scenarioID: ID! @constraint(type: "primarykey")
	available: Int
	refillCount: Int
	faultDescription: String
	fuelType: String @constraint(type: "default", value: "UNLEADED")
}

"""Static"""
type Vehicle @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	vehicleAttributeID: String!
	restingPoiID: ID!
	poi: Poi @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "restingPoiID")
	artibutes: VehicleAttribute! @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "vehicleAttributeID")
}

enum VehicleType {
    TRUCK
    SHIP
    RAIL
}

type VehicleAttribute @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	capacity: Int
	vehicleType: VehicleType!
	flowInLitresPerHour: Float
	"""Returns JSON string"""
	emissions: String
	operationCostPerHour: Float
	"""Return enum: train/truck/ship/ unique PK"""
	maxVelocity: Float
	vehicles: [Vehicle]! @mapping(type: "one2many", foreignKey: "vehicleAttributeID", foreignKeyReference: "id")
}

type Route @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	routeName: String
	routeArrayLat: [Float]!
	routeArrayLon: [Float]!
	"""Foreign key"""
	vehicleType: VehicleType!
	"""Caching"""
	routeLength: Float
	isTemporary: Boolean
	geojson: String
	"""Nullable"""
	startPoiID: ID
	endPoiID: ID
	startingPoi: Poi @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "startPoiID")
	endingPoi: Poi @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "endPoiID")
	calendars: [Calendar]! @mapping(type: "one2many", foreignKey: "routeID", foreignKeyReference: "id")
}

type RouteActual @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	id: ID!
	performanceMultiplier: Float!
}

type Calendar @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	calendarID: ID! @constraint(type: "primarykey")
	vehicleID: ID! @constraint(type: "primarykey")
	isCustomRoute: Boolean
	routeID: ID!
	route: Route! @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "routeID")
	startTime: Int
	endTime: Int
	transferLoad: Int
	fuelType: String
	scheduleID: String
}

type VehicleActual @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	routeID: String
	calendarID: String
	coordinates: [Float]!
	currentLat: Float
	currentLon: Float
	delayInSeconds: Int
	percentRouteComplete: Float
	faultDescription: String
	available: Int
}

type VehicleHistoric @required(type: "READ, CREATE, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	dtTimestamp: Int! @constraint(type: "primarykey")
	scenarioID: ID! @constraint(type: "primarykey")
	routeID: String
	calendarID: String
	coordinates: [Float]!
	currentLat: Float
	currentLon: Float
	delayInSeconds: Int
	percentRouteComplete: Float
	faultDescription: String
	available: Int
}

type Schedule @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	name: String
	summary: String
	startTimestamp: Int!
	endTimestamp: Int!
	dataKey: String!
	calendars: [Calendar]! @mapping(type: "one2many", foreignKey: "scheduleID", foreignKeyReference: "id")
	totalOperationalCost: Float
	totalBenefitCost: Float
	totalEmissionCost: Float
	totalRisk: Risk
	totalTrucksUsed: Int
	totalShipsUsed: Int
	totalLowPois: Int
	actualStartTime: Int
	status: ScheduleStatus!
}

enum ScheduleStatus {
    APPROVED
    PROPOSED
    OODAPPROVED
    OODPROPOSED
    DISMISSED
}

enum Risk {
    LOW
    MEDIUM
    HIGH
    CRITICAL
}

type ScheduleActual @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	operationalCost: Float
	benefitCost: Float
	emissionCost: Float
	risk: Risk
	"""JSON string"""
	extraAttributes: String
	trucksUsed: Int
	shipsUsed: Int
	lowPois: Int
}

type ScheduleHistoric @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	dtTimestamp: Int! @constraint(type: "primarykey")
	operationalCost: Float
	benefitCost: Float
	emissionCost: Float
	risk: Risk
	"""JSON string"""
	extraAttributes: String
	trucksUsed: Int
	shipsUsed: Int
	lowPois: Int
}

type Alert @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	refType: String! @constraint(type: "primarykey")
	dtTimestamp: Int! @constraint(type: "primarykey")
	message: String!
}

Use Case: Transmission Line Planning

Industry: Energy & Government

Click here to expand...

This schema is for a scenario planning use case for a transmission line upgrade.

graphql
type Project @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	name: String!
	description: String
	proposalType: ProposalType
	projectType: ProjectType
	industry: Industry
	createdAt: Int
	updatedAt: Int
	subject: Subject
	upgradeType: UpgradeType
	regions: [Region]! @mapping(type: "one2many", foreignKey: "projectID", foreignKeyReference: "id")
}

enum ProposalType {
	COMMITTED
	ANTICIPATED
	SCENARIO
}

enum ProjectType {
	GENERATION
	GRID
	STORAGE
}

enum Industry {
	SOLAR
	WIND
	STORAGE
	COAL
	GAS
	EXISTING
	BATTERIES
	TRANSMISSION
}

enum Subject {
	ZONE
	LINE
}

enum UpgradeType {
	VOLTAGE
	CAPACITY
}

type Region @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	projectID: ID @constraint(type: "primarykey")
	name: String
	remoteControlStatus: RemoteControlStatus
	lines: [Line]! @mapping(type: "one2many", foreignKey: "regionID", foreignKeyReference: "id")
	project: Project @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "projectID")
}

enum RemoteControlStatus {
	ENABLED
	DISABLED
}

type Line @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	regionID: ID
	name: String
	linePoints: [LinePoint]! @mapping(type: "one2many", foreignKey: "lineID", foreignKeyReference: "id")
	zones: [Zone]! @mapping(type: "one2many", foreignKey: "lineID", foreignKeyReference: "id")
	region: Region @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "regionID")
}

type LinePoint @required(type: "", table: "true") {
	lineID: ID! @constraint(type: "primarykey")
	sequence: Int! @constraint(type: "primarykey")
	lat: Float
	lon: Float
	line: Line @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "lineID")
}

type Zone @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	lineID: ID @constraint(type: "primarykey")
	name: String
	geojson: String
	simRegion: SimRegion @mapping(type: "one2one", foreignKey: "zoneID", foreignKeyReference: "id")
}

type SimRegion @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	zoneID: String @constraint(type: "unique")
	currentCapacity: Float
	addedCapacity: Float
	addedCapacityComitted: Float
	addedCapacityAnticipated: Float
	economics: SimEconomics @mapping(type: "one2one", foreignKey: "simRegionID", foreignKeyReference: "id")
	simEvents: [SimEvent]! @mapping(type: "one2many", foreignKey: "simRegionID", foreignKeyReference: "id")
	simLines: [SimLine]! @mapping(type: "one2many", foreignKey: "simRegionID", foreignKeyReference: "id")
}

type SimEconomics @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	simRegionID: String @constraint(type: "unique")
	currentAnnualCost: Float
	addedAnnualCost: Float
	simRegion: SimRegion @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "simRegionID")
}

enum EventType {
	CONGESTION
	MAINTENANCE
	TRIP
}

type SimEvent @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	eventType: EventType
	description: String
	timestampStart: Int
	timestampEnd: Int
	simRegionID: ID
	simRegion: SimRegion @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "simRegionID")
}

type SimLine @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	simRegionID: ID
	risk: RiskLevel
	status: LineStatus
	breakerStatus: BreakerStatus
	simRegion: SimRegion @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "simRegionID")
}

enum RiskLevel {
	HIGH
	MEDIUM
	LOW
}

enum LineStatus {
	ONLINE
}

enum BreakerStatus {
	CLOSED
}

type LineRegion @required(type: "", table: "true") {
	LineID: ID! @constraint(type: "primarykey")
	RegionID: ID! @constraint(type: "primarykey")
}

Use Case: Supply Chain Tariff Analysis

Industry: Supply Chain

Click here to expand...

This schema helps support modelling of the impact of tariffs on a supply chain.

graphql
type Companies @required(type:"CREATE,READ,UPDATE,DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	companyName: String
	tiers: [Int]
	country: Countries
}

enum CurrencyCode {
	USD
	EUR
	GBP
	CNY
}

enum Countries {
	MEXICO
	CHINA
	CANADA
	ROW
}

enum Severity {
	LOW
	MEDIUM
	HIGH
}

type Tariff @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	hs_code: String! @constraint(type: "primarykey")
	description: String!
	referenced_unit_price: Float
	currency: CurrencyCode!
	exemption: Boolean!
	tariff_MX: Float
	tariff_CN: Float
	tariff_CA: Float
	tariff_ROW: Float
	begin_effect_date: String
	end_effective_date: String
	createdAt: Int
	updatedAt: Int
}

type Transactions @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	shpGlobalId: ID!
	conGlobalId: ID!
	transactionCount: Int
	transactionCountries: [String]
	hsCode: [String]
	tier: Int
}

type Experiment @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	name: String!
	description: String
	supplier: String
	hsCode: String
	my_spend: Float
	tariff_CN: Float!
	tariff_MX: Float!
	tariff_CA: Float!
	tariff_ROW: Float!
	executedAt: Int
	createdAt: Int!
	experimentOutputCountry: ExperimentOutputCountry! @mapping(type:"one2one",foreignKey:"experimentId",foreignKeyReference:"id")
	experimentOutputSupplier: ExperimentOutputSupplier! @mapping(type:"one2one",foreignKey:"experimentId",foreignKeyReference:"id")
}

type ExperimentOutputCountry @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	experimentId: ID! @constraint(type: "primarykey")
	importCountry: String!
	exportCountry: String!
	transactionVolume: Int!
	impact_byDollar: Int!
	impact_byPercent: Int!
	severity: Severity!
	supplier_number: Int!
	experiment: Experiment! @mapping(type:"backRef",foreignKey:"id",foreignKeyReference:"experimentId")
}

type ExperimentOutputSupplier @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	experimentId: ID! @constraint(type: "primarykey")
	globalId: String!
	companyName: String!
	country: String!
	tiers: [Int]
	severity: Severity!
	supplier_number: Int!
	totalImportPreTariff: Int!
	totalExportPreTariff: Int!
	totalImportPostTariff: Int!
	totalExportPostTariff: Int!
	experiment: Experiment! @mapping(type:"backRef",foreignKey:"id",foreignKeyReference:"experimentId")
}

Use Case: Port Logistics Planning

Industry: Ports & Transport

Click here to expand...

This schema helps support scenario modelling scenarios for port throughput and logistics.

graphql
type Node @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	name: String
	nodeType: String
	position: String
}

type Edge @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	name: String
	edgeType: String
	position: String
}

type Asset @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	name: String
	assetType: String
}

type Simulation @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	landsideOperatingStart: Int!
	landsideOperatingEnd: Int!
	railSchedule: String!
	landsideCongestion: Float!
	simNodes: [SimNode]! @mapping(type: "one2many", foreignKey: "simId", foreignKeyReference: "id")
	simEdges: [SimEdge]! @mapping(type: "one2many", foreignKey: "simId", foreignKeyReference: "id")
	simAgents: [SimAgent]! @mapping(type: "one2many", foreignKey: "simId", foreignKeyReference: "id")
	metrics: PerformanceMetrics @mapping(type: "one2one", foreignKey: "simId", foreignKeyReference: "id")
}

type SimNode @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	nodeId: String!
	time: Int
	status: String
	dwellTime: Float
	simId: String!
	simulation: Simulation! @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "simId")
}

type SimEdge @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	edgeId: String!
	time: Int
	status: String
	flowVolume: Float
	congestion: Float
	simId: String!
	simulation: Simulation! @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "simId")
}

type SimAgent @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	position: String
	time: Int
	simId: String!
	assetId: String
	simulation: Simulation! @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "simId")
}

type PerformanceMetrics @required(type: "CREATE, READ, UPDATE, DELETE", table: "true") {
	id: ID! @constraint(type: "primarykey")
	simId: String! @constraint(type: "unique")
	cost: Float
	emissions: Float
	benefitCostRatio: Float
	dwellTime: Float
	equity: Float
	simulation: Simulation! @mapping(type: "backRef", foreignKey: "id", foreignKeyReference: "simId")
}

User documentation for Optimal Reality