Develop Secure Code
Pagination
Children and Parent Relationships
You can specify a parent or child relationship in your query for the GraphQL wire adapter.
Objects can have children relationships to the same object. For example, a parent account can have a child account. Some objects also have children relationships to other objects. For example, accounts have child relationships to assets, cases, and contacts among other objects.
To query a child relationship, pass in the child relationship name and fields to the parent node. The GraphQL wire adapter only supports one level of child relationships. For example, you can request contacts on an account record, but not any child relationships of those contacts.
The child relationships records in the response are paginated and include cursor and pagination information.
To create a query with children relationships, use the query parameter of the GraphQL wire adapter.
1query operationName {
2 uiapi {
3 query {
4 Account (where: { Name: { eq: "United Oil" }}) {
5 edges {
6 node {
7 Id
8 Name {
9 value
10 }
11 Contacts ( first: 5 ) {
12 edges {
13 node {
14 Name { value }
15 }
16 }
17 totalCount
18 pageInfo {
19 hasNextPage
20 }
21 }
22 }
23 }
24 }
25 }
26 }
27}The response looks like this.
1{
2 "data": {
3 "uiapi": {
4 "query": {
5 "Account": {
6 "edges": [
7 {
8 "node": {
9 "Id": "001RM000005Zcl6YAC",
10 "Name": {
11 "value": "United Oil"
12 },
13 "Contacts": {
14 "edges": [
15 {
16 "node": {
17 "Name": {
18 "value": "Pat Stumuller"
19 }
20 }
21 },
22 {
23 "node": {
24 "Name": {
25 "value": "Stella Pavlova"
26 }
27 }
28 },
29 {
30 "node": {
31 "Name": {
32 "value": "Lauren Boyle"
33 }
34 }
35 },
36 {
37 "node": {
38 "Name": {
39 "value": "Jane Grey"
40 }
41 }
42 },
43 {
44 "node": {
45 "Name": {
46 "value": "Arthur Song"
47 }
48 }
49 }
50 ],
51 "totalCount": 11,
52 "pageInfo": {
53 "hasNextPage": true
54 }
55 }
56 }
57 }
58 ]
59 }
60 }
61 }
62 },
63 "errors": []
64}To query a parent relationship, pass in the parent relationship name and fields to the child node. The GraphQL wire adapter returns one level of parent relationship. Unlike child relationships, you can request multiple levels of parent relationships. For example, request the name of the account owner associated with an opportunity.
To create a query with parent relationships, use the query parameter of the GraphQL wire adapter.
1query operationName {
2 uiapi {
3 query {
4 Opportunity {
5 edges {
6 node {
7 Id
8 Name {
9 value
10 }
11 Account {
12 Name {
13 value
14 }
15 }
16 }
17 }
18 }
19 }
20 }
21}The response looks like this.
1{
2 "data": {
3 "uiapi": {
4 "query": {
5 "Opportunity": {
6 "edges": [
7 {
8 "node": {
9 "Name": {
10 "value": "Edge SLA"
11 },
12 "Account": {
13 "Name": {
14 "value": "Edge Communications"
15 }
16 }
17 }
18 },
19 {
20 "node": {
21 "Name": {
22 "value": "Edge Emergency Generator"
23 },
24 "Account": {
25 "Name": {
26 "value": "Edge Communications"
27 }
28 }
29 }
30 },
31 {
32 "node": {
33 "Name": {
34 "value": "Edge Emergency Generator"
35 },
36 "Account": {
37 "Name": {
38 "value": "Edge Communications"
39 }
40 }
41 }
42 },
43 {
44 "node": {
45 "Name": {
46 "value": "Edge Installation"
47 },
48 "Account": {
49 "Name": {
50 "value": "Edge Communications"
51 }
52 }
53 }
54 },
55 {
56 "node": {
57 "Name": {
58 "value": "Burlington Textiles Weaving Plant Generator"
59 },
60 "Account": {
61 "Name": {
62 "value": "Burlington Textiles Corp of America"
63 }
64 }
65 }
66 }
67 ]
68 }
69 }
70 }
71 },
72 "errors": []
73}Some relationships fields, like Account.OwnerId, are polymorphic fields. To create a query with polymorphic relationships, use the query parameter of the GraphQL wire adapter and annotate the object using the polymorphicParentRelationship field.
In this example, the OwnerId polymorphic field is mapped to the User object.
1query AccountCasesDetail {
2 uiapi {
3 query {
4 Account(where: { Name: { like: "Acme%" } }) {
5 edges {
6 node {
7 Id
8 Name {
9 value
10 displayValue
11 }
12 Cases(
13 where: { IsClosed: { ne: true } }
14 orderBy: { LastModifiedDate: { order: ASC } }
15 ) {
16 edges {
17 node {
18 Id
19 Subject {
20 value
21 displayValue
22 }
23 Owner {
24 ... on User {
25 Name {
26 value
27 }
28 }
29 }
30 CreatedDate {
31 displayValue
32 }
33 Id
34 IsEscalated {
35 value
36 }
37 }
38 }
39 }
40 }
41 }
42 }
43 }
44 }
45}The response looks like this.
1{
2 "data": {
3 "uiapi": {
4 "query": {
5 "Account": {
6 "edges": [
7 {
8 "node": {
9 "Name": {
10 "value": "Acme Corp.",
11 "displayValue": null
12 },
13 "Cases": {
14 "edges": [
15 {
16 "node": {
17 "Subject": {
18 "value": "Starting generator after electrical failure"
19 },
20 "Owner": {
21 "Name": {
22 "value": "Amy Taylor"
23 }
24 },
25 "CreatedDate": {
26 "displayValue": "10/28/2022, 3:44 PM"
27 },
28 "IsEscalated": {
29 "value": false
30 }
31 }
32 },
33 {
34 "node": {
35 "Subject": {
36 "value": "Cannot start generator after electrical failure"
37 },
38 "Owner": {
39 "Name": {
40 "value": "John Kingsley"
41 }
42 },
43 "CreatedDate": {
44 "displayValue": "10/28/2022, 3:44 PM"
45 },
46 "IsEscalated": {
47 "value": false
48 }
49 }
50 },
51 ]
52 }
53 }
54 }
55 ]
56 }
57 }
58 }
59 },
60 "errors": []
61}For more information, see Use GraphQL API with Lightning Web Components.
Tip
See Also