Skip to content

Commit

Permalink
feat(snippet): add example for @dbquery with SQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
aswanyaugustine1992 committed Oct 15, 2024
1 parent ac58f16 commit 6ce966e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dbquery/custom-query/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @dbquery Example Snippet
# @dbquery SQL query Snippet

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

Expand Down
9 changes: 9 additions & 0 deletions dbquery/custom-query/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ query SearchCustomersByName {
email
}
}

# Query to get all customers
query GetAllCustomers {
getAllCustomers {
id
name
email
}
}
40 changes: 28 additions & 12 deletions dbquery/custom-query/tests/Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,40 @@ const requestsFile = path.join(path.dirname(__dirname), "operations.graphql");
const requests = fs.readFileSync(requestsFile, "utf8").toString();

describe(testDescription, function () {

const tests = [
{
label: "fetch all customers",
query: requests,
operationName: "GetAllCustomers",
variables: {},
expected: {
getAllCustomers: [
{ id: "1", name: "Lucas Bill ", email: "lucas.bill@example.com " },
{ id: "2", name: "Mandy Jones ", email: "mandy.jones@example.com " },
{ id: "3", name: "Salim Ali ", email: "salim.ali@example.com " },
{ id: "4", name: "Jane Xiu ", email: "jane.xiu@example.com " },
{ id: "5", name: "John Doe ", email: "john.doe@example.com " },
{ id: "6", name: "Jane Smith ", email: "jane.smith@example.com " },
{ id: "7", name: "Sandeep Bhushan ", email: "sandeep.bhushan@example.com " },
{ id: "8", name: "George Han ", email: "george.han@example.com " },
{ id: "9", name: "Asha Kumari ", email: "asha.kumari@example.com " },
{ id: "10", name: "Salma Khan ", email: "salma.khan@example.com " }
]
},
},
{
label: "fetch customer by ID",
query: requests,
operationName: "GetCustomerById",
variables: {
id: 1
id: 1
},
expected: {
getCustomerById: {
id: "1",
name: "Lucas Bill",
email: "lucas@example.com"
name: "Lucas Bill ",
email: "lucas.bill@example.com "
}
},
},
Expand All @@ -38,21 +59,16 @@ describe(testDescription, function () {
},
expected: {
searchCustomersByName: [
{
id: "2",
name: "John Doe",
email: "john@example.com"
},
{
{
id: "5",
name: "Johnny Smith",
email: "johnny@example.com"
email: "john.doe@example.com ",
name: "John Doe "
}
]
},
},
];

// Run the tests against the deployed schema
return deployAndRun(__dirname, tests, stepzen.admin);
});

0 comments on commit 6ce966e

Please sign in to comment.