Add Resource tags to Jobs using GraphQL

Using GraphQL to create a job with tags for resource skill requirements.

You can create a job and add tags to it using GraphQL aliases.

GraphQL aliases allow you to perform multiple actions in a single GraphQL request.

The Skedulo schema includes idAlias, which operates as a substitute field for UID values that are created in the same request.

Creating a job with tags involves multiple actions:

  • Creating a job
  • Creating a tag (if the required tag does not yet exist in the schema)
  • Adding the tag to the job

For more information about using GraphQL aliases, see GraphQL aliases for multiple actions.

Create a new job and assign resource tags

The following mutation creates a new job, a new skills tag, and makes the skill tag a requirement for the new job:

mutation createNewJobWithSkillTag {
  schema {
    _j0: insertJobs(input: {
      RegionId: "0003035f-366a-4d18-8c2d-1b9c99cf27bd"
      Start: "2019-10-31T09:00:00+10:00"
      End: "2019-10-31T10:00:00+10:00"
      Duration: 60
      Address: "1/47 Warner Street, Fortitude Valley QLD 4006"
      Description: "A new job with a skill tag"
    }, idAlias: "NEW_JOB_ID")
    _nt0: insertTags(input: {
      Name: "Registered Nurse"
      Classification: "Human"
      Type: "Skill"
    }, idAlias: "NEW_TAG_ID")
    _jt0: insertJobTags(input: {
      JobId: "NEW_JOB_ID"
      Required: true
      TagId: "NEW_TAG_ID"
    })
  }
}

New job with skill tag

Create a new job, assign resource tags, and assign a resource

You can expand this GraphQL request further to also create a new resource and assign them to the job using aliases:

mutation createNewJobWithSkillTag {
  schema {
    _j0: insertJobs(input: {
      RegionId: "0003035f-366a-4d18-8c2d-1b9c99cf27bd"
      Start: "2019-10-31T11:00:00+10:00"
      End: "2019-10-31T12:00:00+10:00"
      Duration: 60
      Address: "1/47 Warner Street, Fortitude Valley QLD 4006"
      Description: "A New Job with a New Resource with Tags"
    }, idAlias: "NEW_JOB_ID")
    _nt0: insertTags(input: {
      Name: "Nurse"
      Classification: "Human"
      Type: "Skill"
    }, idAlias: "NEW_TAG_ID")
    _jt0: insertJobTags(input: {
      JobId: "NEW_JOB_ID"
      Required: true
      TagId: "NEW_TAG_ID"
    })
    _res0: insertResources(input: {
      Name: "Florence Nightingale"
      HomeAddress:"123 New Street, New Farm QLD 4006"
      MobilePhone: "+61400123456"
      NotificationType: "sms"
      EmploymentType: "Full-time" 
      Category: "Customer Service"
      IsActive: true
      PrimaryRegionId: "0003035f-366a-4d18-8c2d-1b9c99cf27bd"
    }, idAlias: "NEW_RESOURCE_ID")
    _ja0: insertJobAllocations(input: {
      JobId: "NEW_JOB_ID"
      ResourceId: "NEW_RESOURCE_ID"
    })
  }
}

The following JSON response shows that all parts of the GraphQL request completed successfully:

{
  "data": {
    "schema": {
      "_j0": "0014fc5a-3497-474a-ae5b-9a00e7154c7c",
      "_nt0": "000f8670-08ce-444a-94cd-caf4703756d7",
      "_jt0": "001553bc-13e3-471c-af25-6603f248975b",
      "_res0": "00057eca-fe6e-40d5-be05-d95b81063465",
      "_ja0": "0018c649-c5a5-46bd-a8c7-4cd0d345abae"
    }
  }
}

The web application shows the job has been created with the resource assigned:

New job with new resource allocated