---
category: [Administration & Integrations, Platform and Product Extensions, Platform and Product Extensions/Integration, Administration & Integrations/Custom Integrations & Apps, Platform and Product Extensions/Workday Extend]
keyword: [Extend, Workday Graph API, Graph API, GraphQL]
nav: wcp_docs
parent_url: /wcp_docs/
title: Sample Graph Query Components in PMDs
layout: subsection
---

## <a id="section_rlt_f32_gxb"></a>Simple Query Without Variables

This sample Graph Query gets the current user and doesn't need variables and parameters.

```
{
   "id": "queryProcessingWorker",
   "query" : "query {
       worker(dataSource: {processingWorker: {}}) {
         data {
           workdayID {
             id
           }
           descriptor
         }
       }
   }"
}
```

Sample PMD inbound endpoint that references the sample `queryProcessingWorker` Graph Query:

```
"endPoints" : [
 {
   "name" : "getCurrentWorker",
   "baseUrlType" : "workday-graph",
   "authType" : "sso",
   "httpMethod" : "POST",
   "failOnStatusCodes" : [ {
     "code" : 400
   } ],
   "graphQuery" : {
     "queryId" : "queryProcessingWorker"
   }
 },
 ...
]
```

Sample `text` that displays the `descriptor` field:

```
{
 "type": "text",
 "label": "Current Worker:",
 "value": "<% getCurrentWorker.data.worker.data[0].descriptor %>"  
}
```

## <a id="section_owr_2h2_fxb"></a>Query with Grid Pagination Parameters

This sample Graph Query uses parameters to send page variables to the query variables.

```
{
   "id": "queryActiveWorkers",
   "parameters": ["isActive", "limit", "offset"],
   "query": "
       query getWorkers ($dataSourceVariables: Worker_DataSources!, $limit: BigInt, $offset: BigInt) {
         worker(dataSource: $dataSourceVariables, limit: $limit, offset: $offset) {
           data {
             descriptor
             workdayID {id}
             businessTitle
           }
           total
         }
       }
   ",
   "variables": {
       "dataSourceVariables": {
           "indexedAllWorkers": {
               "filter": {
                   "indexedAllWorkersFilter": {
                       "isActive": "<% isActive %>"
                   }
               }
           }
       },
       "limit" : "<% limit %>",
       "offset" : "<% offset %>"
   }
}
```

Sample PMD inbound endpoint that references the sample `queryActiveWorkers` Graph Query:

```
"endPoints" : [
 {
   "name" : "getWorkers",
   "baseUrlType" : "workday-graph",
   "httpMethod" : "POST",
   "failOnStatusCodes" : [ {
     "code" : 400
   } ],
   "graphQuery" : {
     "queryId" : "queryActiveWorkers",
     "parameters" : {
       "isActive" : true,
       "limit" : "<% empty pagingVariables.limit ? 50 : pagingVariables.limit.toInt() %>",
       "offset" : "<% empty pagingVariables.offset ? 0 : pagingVariables.offset.toInt() %>"
     }
   },
   "onSend" : "<%
         console.debug('getWorkers: ' + self.data.toJson());
         self.data;
   %>"
 },
 ...
]
```

<b>Note:</b> The sample PMD endpoint includes the `onSend` event for debugging purposes.

This sample paginated `grid` displays the worker data from the Graph API endpoint. Note that `pagingInfo` requires the `total` field from the Graph query.

```
{
 "type" : "grid",
 "label" : "Active Workers Using Graph Query Component",
 "id" : "workersGrid",
 "rows" : "<% getWorkers.data.worker.data %>",
 "rowVariableName" : "thisWorker",
 "pagingInfo" : {
   "endPoint" : "<% endpoints.getWorkers %>",
   "rowCount" : "<% getWorkers.data.worker.total %>",
   "data" : "<% getWorkers.data.worker.data %>"
 },
 "columns" : [ {
   "type" : "column",
   "columnId" : "column1",
   "label" : "Worker",
   "cellTemplate" : {
     "type" : "text",
     "value" : "<% thisWorker.descriptor %>"
   }
 }, {
   "type" : "column",
   "columnId" : "column2",
   "label" : "Business Title",
   "cellTemplate" : {
     "type" : "text",
     "value" : "<% thisWorker.businessTitle %>"
   }
 }
 ]
}
```

## <a id="section_jzp_v4f_gxb"></a>Query with Deferred Endpoint

A deferred Graph API endpoint sends a selected list value as a parameter to this sample Graph Query.

```
{
   "id": "queryWorkersByLocation",
   "parameters": ["locationId"],
   "query" : "query getActiveWorkersByLocation($worker_dataSource: Worker_DataSources!) {
           worker(dataSource: $worker_dataSource, limit: 100, offset: 0) {
             data {
               workdayID{id}
               descriptor
             }
             total
           }
         }
         ",
     "variables" : {
       "worker_dataSource" : {
         "indexedAllWorkers" : {
           "filter" : {
             "indexedAllWorkersFilter" : {
               "location" : {
                 "id" : "<% locationId %>",
                 "type" : "WID"
               }
             }
           }
         }
       }
     }
}
```

Sample deferred inbound endpoint that references the sample `queryWorkersByLocation` Graph Query:

```
"endPoints" : [
 {
   "name" : "getWorkersByLocation",
   "baseUrlType" : "workday-graph",
   "authType" : "sso",
   "deferred" : true,
   "httpMethod" : "POST",
   "graphQuery" : {
     "queryId" : "queryWorkersByLocation",
     "parameters" : {
       "locationId" : "<% locationList.value[0] %>"
     }
   }
 },
 ...
]
```

The `onChange` event on this sample <i>locationList</i> calls the deferred endpoint <i>getWorkersByLocation</i>, and populates <i>workerList</i> with the data from the Graph Query:

```
{
 "type" : "instanceList",
 "label" : "Select a location",
 "id" : "locationList",
 "instanceList" : [ {
   "id" : "be63426899d149f4bb20d2b96512b2c0",
   "descriptor" : "Vancouver"
 }, {
   "id" : "d13a7c46a06443c4a33c09afbdf72c73",
   "descriptor" : "San Francisco"
 } ],
 "onChange" : "<%
 // Call the deferred endpoint getWorkersByLocation,
 // which uses a Graph Query Component.
 var workersFromGraphQuery = getWorkersByLocation.invoke();
 var workerQueryListValues = workersFromGraphQuery.data.worker.data
   .map(worker => {
     {
       'id': worker.workdayID.id,
       'descriptor': worker.descriptor
     }
   });
 workerList.setValues(workerQueryListValues);
 %>"
}, {
 "type" : "instanceList",
 "label" : "Workers by Location (using Graph Query Component)",
 "id" : "workerList",
 "enabled" : true,
 "values" : "<% [ ] %>",
 "valuesOut" : [ {
   "value" : "<% self.value[0] %>",
   "valueOutBinding" : "workerFlowVariable.id"
 }, {
   "value" : "<% self.selectedEntries[0].descriptor %>",
   "valueOutBinding" : "workerFlowVariable.descriptor"
 } ]
}
```

<b>Note:</b> The `valuesOut` attribute of <i>workerList</i> sends the selected `id` and `descriptor` fields to the `workerFlowVariable`. The <i>initiateJobChange</i> PMD endpoint in the next example uses this flow variable.

```
"outboundData" : {
 "outboundEndPoints" : [ {
   "type" : "outboundVariable",
   "name" : "workerFlowVariable",
   "variableScope" : "flow"
 } ]
}
```

## <a id="section_nzq_wkg_gxb"></a>Mutation with Parameters

This sample Graph Query contains a mutation, which uses the parameters for the input variables.

```
{
   "id": "mutationInitiateJobChange",
   "parameters": ["theWorkerID", "effectiveDate", "reasonId"],
   "query" : "mutation initiateJobChangeEvent($input: Staffing_JobChangesStartDetailsPOSTData_CreateInput!, $workerId: ID!) {
         initiateWorkerJobChange(input: $input, workerId: {id: $workerId}) {
           date
           workdayID {
             id
             type
           }
         }
       }",
   "variables" : {
     "input" : {
       "date" : "<% effectiveDate %>",
       "reason" : {
         "id" : {
           "id" : "<% reasonId %>",
           "type" : "WID"
         }
       }
     },
     "workerId" : "<% theWorkerID %>"
   }
}
```

Sample PMD endpoint that references the sample `mutationInitiateJobChange` Graph Query component:

```
"outboundEndPoints" : [ {
 {
   "name" : "initiateJobChange",
   "baseUrlType" : "workday-graph",
   "authType" : "sso",
   "httpMethod" : "POST",
   "graphQuery" : {
     "queryId" : "mutationInitiateJobChange",
     "parameters" : {
       "theWorkerID" : "<% flowVariables.workerFlowVariable.id %>",
       "effectiveDate" : "<% requestDate.value.format('yyyy-MM-dd') %>",
       "reasonId" : "<% pageVariables.reasonId %>"
     }
   },
   "failOnStatusCodes" : [ {
     "code" : 400
   } ],
   "onSend" : "<%
       console.debug('initiateJobChange: ' + self.data.toString() );
       self.data;
   %>"
 },
 ...
]
```

## <a id="section_shj_tpg_gxb"></a>Mutation Without Parameters

There might be cases when it's easier to send input data to the mutation directly from the PMD. In these cases, you can reference the mutation in a Graph Query component but define the `variables` in the PMD endpoint.

Sample mutation without parameters in a Graph Query component:

```
{
   "id": "mutationChangeBusinessTitle",
   "query": "
       mutation updateBusinessTitle($jobChangeId: ID!, $businessTitle: String) {
         updateJobChangeBusinessTitle(
           businessTitleId: {id: $jobChangeId}
           input: {businessTitle: $businessTitle}
           jobChangeId: {id: $jobChangeId}
         ) {
           businessTitle
         }
       }
   "
}
```

Sample PMD endpoint that references the sample <i>mutationChangeBusinessTitle</i> Graph Query component:

```
"outboundEndPoints" : [ {
 {
   "name" : "updateBusinessTitle",
   "baseUrlType" : "workday-graph",
   "authType" : "sso",
   "httpMethod" : "POST",
   "graphQuery" : {
     "queryId" : "mutationChangeBusinessTitle",
     "variables" : {
       "jobChangeId" : "<% initiateJobChange.data.initiateWorkerJobChange.workdayID.id %>",
       "businessTitle" : "<% newTitle.value %>"
     }
   },
   "failOnStatusCodes" : [ {
     "code" : 400
   } ],
   "onSend" : "<%
       console.debug('updateBusinessTitle: ' + self.data.toString() );
       self.data;
   %>"
 },
 ...
]
```

<b>Note:</b> Instead of including `variables` in the Graph Query component, the <i>updateBusinessTitle</i> PMD endpoint specifies `variables`, which include the returned job change ID from the <i>initiateJobChange</i> endpoint and the business title from a `text` widget.

### Related Information

[Graph Query Components](/wcp_docs/rol1682042554209.html)

