From 6ce966ec3857259373de4437f34252b32ae3a2bf Mon Sep 17 00:00:00 2001 From: Aswany Augustine Date: Tue, 15 Oct 2024 14:08:59 +0530 Subject: [PATCH] feat(snippet): add example for @dbquery with SQL queries --- dbquery/custom-query/README.md | 2 +- dbquery/custom-query/operations.graphql | 9 ++++++ dbquery/custom-query/tests/Test.js | 40 +++++++++++++++++-------- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/dbquery/custom-query/README.md b/dbquery/custom-query/README.md index 1d09b0b..2b92990 100644 --- a/dbquery/custom-query/README.md +++ b/dbquery/custom-query/README.md @@ -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. diff --git a/dbquery/custom-query/operations.graphql b/dbquery/custom-query/operations.graphql index 1b6077c..bc4bbc6 100644 --- a/dbquery/custom-query/operations.graphql +++ b/dbquery/custom-query/operations.graphql @@ -15,3 +15,12 @@ query SearchCustomersByName { email } } + +# Query to get all customers +query GetAllCustomers { + getAllCustomers { + id + name + email + } +} diff --git a/dbquery/custom-query/tests/Test.js b/dbquery/custom-query/tests/Test.js index 25f19c9..e4dad77 100644 --- a/dbquery/custom-query/tests/Test.js +++ b/dbquery/custom-query/tests/Test.js @@ -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 " } }, }, @@ -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); });