Planning
Query for All Plans
This example queries for all plans in the Aerie database's plan
table with some common columns. It also demonstrates the order_by query filter, and using an alias to rename plan
to plans
since the query returns a list of plans.
query GetPlans {
plans: plan(order_by: { id: desc }) {
duration
id
model_id
name
revision
start_time
}
}
Query a Single Plan
query GetPlan($id: Int!) {
plan_by_pk(id: $id) {
duration
id
model_id
name
start_time
}
}
Create a Single Plan
Here is a mutation that creates a single plan and returns the id
of the new plan:
mutation CreatePlan($plan: plan_insert_input!) {
insert_plan_one(object: $plan) {
id
}
}
Here is an example query variable for the mutation above that creates a 24-hour long plan called "New Plan" starting on January 1st, 2030. It is for a model with ID 1:
{
"plan": {
"duration": "24:00:00",
"model_id": 1,
"name": "New Plan",
"start_time": "2030-001T00:00:00"
}
}
Notice the duration
is a Postgres interval of the format hh:mm:ss
.
The start_time
is in the day-of-year format YYYY-DDDThh:mm:ss
.
If you want to run scheduling against your plan you need to create an associated scheduling specification.
Query for All Activity Directives for a Plan
Notice how in this query we get the same plan
data as the previous query, but also the nested activity_directives
. If you are familiar with relational databases you can think of this as a join query between the plan
table and activity_directive
table (in Hasura these joins are made via relationships). This is the secret sauce behind GraphQL. It allows us to query for deeply-nested data across the Aerie system in a single unified way.
query GetActivityDirectivesForPlan($id: Int!) {
plan_by_pk(id: $id) {
activity_directives {
arguments
created_at
id
last_modified_arguments_at
last_modified_at
metadata
name
plan_id
source_scheduling_goal_id
start_offset
tags
type
}
duration
id
model_id
name
start_time
}
}
Query the Mission Model of a Plan
query GetMissionModelForPlan($id: Int!) {
plan_by_pk(id: $id) {
mission_model {
id
mission
name
owner
version
}
name
}
}
Query for All Activity Types within a Mission Model of a Plan
This query is using the relationship between the plan
table, the mission_model
table, and the activity_type
table to return one object with the activity type properties requested.
query GetActivityTypesForPlan($id: Int!) {
plan_by_pk(id: $id) {
mission_model {
activity_types {
computed_attributes_value_schema
name
parameters
required_parameters
}
}
}
}
Create Activity Directive
TODO: Finish
mutation CreateDirectives($directives: [activity_directive_insert_input!]! ) {
insert_activity_directive(objects: $directives) {
returning {
id
start_offset
}
}
}
The query variable directives
is a list of activity directives.
Each directive has the following shape:
{
"name": string, // optional
"plan_id": integer,
"type": string,
"start_offset": duration, // format: "HH:MM:SS.sss"
"arguments": jsonb
}
Query for Activity Effective Arguments
This query returns a set of effective arguments given a set of required (and overridden) arguments.
query GetEffectiveArgs($modelId: Int!, $activityType: String!, $arguments: ActivityArguments!) {
getActivityEffectiveArguments(
missionModelId: $modelId
activityTypeName: $activityType
activityArguments: $arguments
) {
arguments
errors
success
}
}
For example, running the query with the arguments of:
{
"modelId": 1,
"activityType": "BakeBananaBread",
"arguments": { "tbSugar": 1, "glutenFree": false }
}
Results in:
{
"data": {
"getActivityEffectiveArguments": {
"arguments": {
"glutenFree": false,
"tbSugar": 1,
"temperature": 350
},
"success": true
}
}
}
When a required argument is not provided, the returned JSON will indicate which argument is missing.
With examples/banananation
's BakeBananaBread
, where only the temperature
parameter has a default value:
{
"modelId": 1,
"activityType": "BakeBananaBread",
"arguments": {}
}
Results in:
{
"data": {
"getActivityEffectiveArguments": {
"arguments": {
"temperature": 350
},
"errors": {
"tbSugar": {
"schema": {"type": "int"} ,
"message": "Required argument for activity \"BakeBananaBread\" not provided: \"tbSugar\" of type ValueSchema.INT"
},
"glutenFree": {
"schema": {"type": "boolean"},
"message": "Required argument for activity \"BakeBananaBread\" not provided: \"glutenFree\" of type ValueSchema.BOOLEAN"
}
},
"success": false
}
}
}