Skip to content

Commit 12ed847

Browse files
committed
address comments
Signed-off-by: asararatnakar <[email protected]>
1 parent a3e0f07 commit 12ed847

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

transforms/setters/api.graphql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# This example demonstartes mapping a JSON response to the fields of the GraphQL.
1+
# This example illustrates how to map a JSON response to the fields of a GraphQL object.
22

33
type Customer {
4-
cId: ID
5-
cName: String
6-
cAddress: Address
4+
id: ID
5+
name: String
6+
address: Address
77
}
88

99
type Address {
@@ -25,17 +25,17 @@ type Query {
2525
function transformREST() {
2626
var id = get('id')
2727
if (id==1)
28-
return ({"address":{"city":"Raleigh","country":"USA","postalCode":"54321","state":"NC","street":"101 Main St"},"id":"12345","name":"John Doe"})
28+
return ({"location":{"address":{"city":"Raleigh","country":"USA","postalCode":"54321","state":"NC","street":"101 Main St"}},"customerId":"12345","customerName":"John Doe"})
2929
else
30-
return ({"address":{"city":"Hyderabad","country":"India","postalCode":"654231","state":"TS","street":"J.N.T.U Colony"},"id":"21345","name":"Siddarth A"})
30+
return ({"location":{"address":{"city":"Hyderabad","country":"India","postalCode":"654231","state":"TS","street":"J.N.T.U Colony"}},"customerId":"21345","customerName":"Siddarth A"})
3131
}
3232
"""
3333

3434
# mapping from JSON response values to the fields of the GraphQL result.
3535
setters: [
36-
{ field: "cId", path: "id" } # JSON response field 'id' is mapped to GraphQL 'cId'
37-
{ field: "cName", path: "name" } # JSON response field 'name' is mapped to GraphQL 'cName'
38-
{ field: "cAddress", path: "address" } # JSON response field 'address' mapped to GraphQL 'cAddress'
36+
{ field: "id", path: "customerId" } # JSON response field 'customerId' is mapped to GraphQL 'id'
37+
{ field: "name", path: "customerName" } # JSON response field 'customerName' is mapped to GraphQL 'name'
38+
{ field: "address", path: "location.address" } # JSON response nested field 'location.address' mapped to GraphQL 'address'
3939
]
4040
)
4141
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# maps some of JSON response values to the fields of the GraphQL result.
22
query CustomerByID($id: ID!) {
33
customerByID(id: $id) {
4-
cAddress {
4+
address {
55
city
66
state
77
country
88
}
9-
cId
10-
cName
9+
id
10+
name
1111
}
1212
}

transforms/setters/tests/Test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ describe(testDescription, function () {
2020
variables: { id: 1 },
2121
expected: {
2222
customerByID: {
23-
cAddress: {
23+
address: {
2424
city: "Raleigh",
2525
country: "USA",
2626
state: "NC",
2727
},
28-
cId: "12345",
29-
cName: "John Doe",
28+
id: "12345",
29+
name: "John Doe",
3030
},
3131
},
3232
},
@@ -37,13 +37,13 @@ describe(testDescription, function () {
3737
variables: { id: 100 },
3838
expected: {
3939
customerByID: {
40-
cAddress: {
40+
address: {
4141
city: "Hyderabad",
4242
country: "India",
4343
state: "TS",
4444
},
45-
cId: "21345",
46-
cName: "Siddarth A",
45+
id: "21345",
46+
name: "Siddarth A",
4747
},
4848
},
4949
},

0 commit comments

Comments
 (0)