Using GraphQL to query custom objects and fields

Creating and mapping your custom objects and fields makes them available through GraphQL. For more information about GraphQL, see the GraphQL chapter, or to find out about how to fetch data for a connected page using GraphQL, see the Connected Pages API Services chapter.

The queries provided in this section use the GroupEvent custom object example that we created in the previous sections.

Prerequisite

Custom objects and fields must be mapped in the Skedulo web application so that you can generate GraphQL queries and mutations. Ensure all custom objects and fields created using the Skedulo managed package on Salesforce have been mapped in the web application before attempting to create GraphQL queries. For more information, see Map custom objects and fields in the Skedulo web application.

Create GroupEvent using a GraphQL mutation query

Create a GroupEvent for a Job using the following GraphQL mutation:

mutation createGroupEvent($createInput: NewGroupEvent!) {
  schema {
    insertGroupEvent(input: $createInput)
  }
}

This mutation uses a createInput variable, which adds a group event with a Name field for the name of the event and includes the JobId for which the GroupEvent is being scheduled.

For example, running the above code with the following variable input adds a new group event to the job with the UID 0014e354-2404-43fc-b087-6412c16df369:

"createInput": {
      "Name": "New Group Event",
      "JobId": "0014e354-2404-43fc-b087-6412c16df369"
  },

The Name and JobId fields are the only fields that we mapped in the previous sections. You can add other fields to this query, such as Description or Resource fields, by mapping a new custom field to the GroupEvent custom object.

Custom objects created and mapped with custom fields in Salesforce are given a default number in the Name field based on the incrementing field that has been set in Salesforce, such as GE-0001.

The Skedulo web application does not currently support incrementing numbers for custom fields, therefore running the GraphQL createInput mutation on a custom object creates an object with whatever information you have provided in the Name field.

For a GroupEvent created and mapped using only Skedulo, the mutation query above creates a group event with the name New Group Event. We can see this by running a fetchGroupEvents query, which returns the following response:

{
  "data": {
    "groupEvent": {
      "edges": [
        {
          "node": {
            "UID": "03e858f2-f7c2-44c6-bff8-26e355284289",
            "Name": "New Group Event",
            "Job": {
              "Name": "JOB-0009",
              "Start": null,
              "End": null,
              "Address": null,
              "Contact": null
            }
          }
        }
      ]
    }
  }
}

Query GroupEvents using GraphQL

You can use the fetchGroupEvents GraphQL query to return a list of group events that you have created, including the Job information for each job that includes a group event:

query fetchGroupEvents {
  groupEvent {
    totalCount
    edges {
      node {
        UID
        Name
        Job {
          Name
          UID
        }
      }
    }
  }
}

This query returns the following JSON response for group events created with a Skedulo managed package:

{
  "data": {
    "groupEvent": {
      "edges": [
        {
          "node": {
            "UID": "a0i2v00000SJEg0AAH",
            "Name": "GE-0000",
            "Job": {
              "Name": "JOB-0009",
              "UID": "a0G2v00002ZEOZkEAP"
            }
          }
        },
        {
          "node": {
            "UID": "a0i2v00000SJEg5AAH",
            "Name": "GE-0001",
            "Job": {
              "Name": "JOB-0007",
              "UID": "a0G2v00002ZEQCoEAP"
            }
          }
        }
      ]
    }
  }
}

Add an Attendee to a GroupEvent

Use the following GraphQL mutation to add an Attendee to a GroupEvent:

mutation createAttendee($createInput: NewAttendee!) {
  schema {
    insertAttendee(input: $createInput)
  }
}

This uses the following $createInput variable:

"createInput": {
  "Name": "Attendee",
  "GroupEventId": "a0i2v00000SJEg0AAH"
},

The successful response confirms the new attendee’s UID:

{
  "data": {
    "schema": {
      "insertAttendee": "a0e2v00000aRmpdAAC"
    }
  }
}

Create a query that returns all Attendees, including which group events they are attending:

query fetchAttendee {
  attendee {
    edges {
      node {
        UID
        Name
        GroupEventId
        GroupEvent {
          Name
          UID
          Job {
            Name
            UID
          }
        }
      }
    }
  }
}