Use GraphQL to query custom objects and fields
Creating custom objects and fields in Skedulo using the web application or the API automatically maps them to your GraphhQL schema. This allows you to interact with the custom object and field data using GraphQL.
Prerequisite for Skedulo for Salesforce customers
All custom objects and fields created using the Skedulo managed package on Salesforce must be mapped in the Skedulo web application before you can generate GraphQL queries and mutations. For more information, see Map custom objects and fields in the Skedulo web application.
For more information about GraphQL, see the GraphQL chapter. To learn more about fetching data for an extension using GraphQL, see the Web extensions API services chapter.
The queries provided in this section use the Vaccine
custom object example that we created in the previous sections (see Creating custom objects).
Create an object record for a specific job using a GraphQL mutation
To create a Vaccine
for a Job
, use the following GraphQL mutation:
mutation {
schema {
insertVaccine(input: {
Name: "New Vaccine",
JobId: "0014e354-2404-43fc-b087-6412c16df369"
})
}
}
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 VAC-0001
, which cannot be overridden.
Skedulo Pulse Platform does not support automatically incrementing values for custom fields, therefore running the GraphQL insertVaccine
mutation on a custom object creates an object with the provided Name
value (in this example, that name is “New Vaccine”).
Query objects using GraphQL
To obtain a list of vaccines, including the Job
information for each job that includes the vaccine, use the following GraphQL query:
{
vaccine {
totalCount
edges {
node {
UID
Name
Job {
Name
UID
}
}
}
}
}
The response that follows would be expected in a Skedulo for Salesforce environment, as the object names have a prefix and incrementing number in the name.
{
"data": {
"vaccine": {
"edges": [
{
"node": {
"UID": "a0i2v00000SJEg0AAH",
"Name": "VAC-0000",
"Job": {
"Name": "JOB-0009",
"UID": "a0G2v00002ZEOZkEAP"
}
}
},
{
"node": {
"UID": "a0i2v00000SJEg5AAH",
"Name": "VAC-0001",
"Job": {
"Name": "JOB-0007",
"UID": "a0G2v00002ZEQCoEAP"
}
}
}
]
}
}
}
In a Skedulo Pulse Platform environment, the response would look more like the following:
{
"data": {
"vaccine": {
"edges": [
{
"node": {
"UID": "03e858f2-f7c2-44c6-bff8-26e355284289",
"Name": "New Vaccine",
"Job": {
"Name": "JOB-0009",
"UID": "0014b000-de45-4128-bb4f-440845c73ab5"
}
}
}
]
}
}
}
Add a field to an object
Using the vaccine and supply example, you can use the following GraphQL mutation to add a supply record to a vaccine:
mutation {
schema {
insertSupply({
Name: "Supply",
VaccineId: "a0i2v00000SJEg0AAH"
})
}
}
The successful response includes the new supply’s UID:
{
"data": {
"schema": {
"insertSupply": "a0e2v00000aRmpdAAC"
}
}
}
Query fields using GraphQL
To query all vaccine supplies, including the vaccine and job they apply to, use the following:
{
supply {
edges {
node {
UID
Name
VaccineId
Vaccine {
Name
UID
Job {
Name
UID
}
}
}
}
}
}
Related links
See the Object and field reference guide for detailed information about the standard objects and fields in Skedulo’s core data model.
Feedback
Was this page helpful?