Skip to content

Commit 6ce966e

Browse files
feat(snippet): add example for @dbquery with SQL queries
1 parent ac58f16 commit 6ce966e

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

dbquery/custom-query/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @dbquery Example Snippet
1+
# @dbquery SQL query Snippet
22

33
This example demonstrates how to use the `@dbquery` directive with custom SQL queries for `Customer` data in StepZen.
44

dbquery/custom-query/operations.graphql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ query SearchCustomersByName {
1515
email
1616
}
1717
}
18+
19+
# Query to get all customers
20+
query GetAllCustomers {
21+
getAllCustomers {
22+
id
23+
name
24+
email
25+
}
26+
}

dbquery/custom-query/tests/Test.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,40 @@ const requestsFile = path.join(path.dirname(__dirname), "operations.graphql");
1313
const requests = fs.readFileSync(requestsFile, "utf8").toString();
1414

1515
describe(testDescription, function () {
16+
1617
const tests = [
18+
{
19+
label: "fetch all customers",
20+
query: requests,
21+
operationName: "GetAllCustomers",
22+
variables: {},
23+
expected: {
24+
getAllCustomers: [
25+
{ id: "1", name: "Lucas Bill ", email: "[email protected] " },
26+
{ id: "2", name: "Mandy Jones ", email: "[email protected] " },
27+
{ id: "3", name: "Salim Ali ", email: "[email protected] " },
28+
{ id: "4", name: "Jane Xiu ", email: "[email protected] " },
29+
{ id: "5", name: "John Doe ", email: "[email protected] " },
30+
{ id: "6", name: "Jane Smith ", email: "[email protected] " },
31+
{ id: "7", name: "Sandeep Bhushan ", email: "[email protected] " },
32+
{ id: "8", name: "George Han ", email: "[email protected] " },
33+
{ id: "9", name: "Asha Kumari ", email: "[email protected] " },
34+
{ id: "10", name: "Salma Khan ", email: "[email protected] " }
35+
]
36+
},
37+
},
1738
{
1839
label: "fetch customer by ID",
1940
query: requests,
2041
operationName: "GetCustomerById",
2142
variables: {
22-
id: 1
43+
id: 1
2344
},
2445
expected: {
2546
getCustomerById: {
2647
id: "1",
27-
name: "Lucas Bill",
28-
48+
name: "Lucas Bill ",
49+
email: "lucas.bill@example.com "
2950
}
3051
},
3152
},
@@ -38,21 +59,16 @@ describe(testDescription, function () {
3859
},
3960
expected: {
4061
searchCustomersByName: [
41-
{
42-
id: "2",
43-
name: "John Doe",
44-
45-
},
46-
{
62+
{
4763
id: "5",
48-
name: "Johnny Smith",
49-
64+
email: "[email protected] ",
65+
name: "John Doe "
5066
}
5167
]
5268
},
5369
},
5470
];
55-
71+
5672
// Run the tests against the deployed schema
5773
return deployAndRun(__dirname, tests, stepzen.admin);
5874
});

0 commit comments

Comments
 (0)