From 10776c28e08e41446e11365da9277fc42a249b1c Mon Sep 17 00:00:00 2001 From: Karim El Shenawy <54007257+elshenak@users.noreply.github.com> Date: Wed, 24 Jan 2024 10:08:00 -0500 Subject: [PATCH] chore: gql when args fix (#299) * fix: gql where args (#298) * fix: gql where obj to gql string * fix: review comments * chore: pr title lint workflow (#293) --------- Co-authored-by: Ruslan Shakirov --- .github/workflows/pr-title-lint.yaml | 18 ++++++++++++++++++ .gitignore | 2 ++ src/indexer-nibi/gql.ts | 26 ++++++++++++++++++++++---- src/indexer-nibi/heart-monitor.test.ts | 4 ++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/pr-title-lint.yaml diff --git a/.github/workflows/pr-title-lint.yaml b/.github/workflows/pr-title-lint.yaml new file mode 100644 index 00000000..eabd87c0 --- /dev/null +++ b/.github/workflows/pr-title-lint.yaml @@ -0,0 +1,18 @@ +name: Pull Request Title Lint + +on: + pull_request: + types: [opened, reopened, synchronize, edited] + +jobs: + pr-title-lint: + runs-on: ubuntu-latest + steps: + - uses: seferov/pr-lint-action@v1.2.0 + with: + # taken from https://gist.github.com/marcojahn/482410b728c31b221b70ea6d2c433f0c + title-regex: '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)' + # title-regex-flags (Optional) + title-regex-flags: "g" + # error-message (Optional) + error-message: "Please follow conventional commit style: https://www.conventionalcommits.org/en/v1.0.0/" diff --git a/.gitignore b/.gitignore index ee84c8d2..920124e2 100644 --- a/.gitignore +++ b/.gitignore @@ -203,3 +203,5 @@ typings/ # End of https://www.gitignore.io/api/node,intellij+all,visualstudiocode .yarn .DS_Store + +nibiru/ diff --git a/src/indexer-nibi/gql.ts b/src/indexer-nibi/gql.ts index b18286d2..45cc67b7 100644 --- a/src/indexer-nibi/gql.ts +++ b/src/indexer-nibi/gql.ts @@ -9,13 +9,31 @@ export const arg = (name: string, value: any, ignoreQuotes?: boolean) => { return `${name}: ${isString}${value}${isString}` } -export const getWhereArgArr = (whereArgs: any) => - `where: { - ${Object.keys(whereArgs) - .map((key) => arg(key, whereArgs[key])) +export const objToGql = (obj: any): string | number => { + // Make sure we don't alter integers. + if (typeof obj === "number") { + return obj + } + + // Stringify everything other than objects and arrays. + if (typeof obj !== "object" || Array.isArray(obj)) { + return JSON.stringify(obj) + } + + // Iterate through object keys to convert into a string + // to be interpolated into the query. + const res = `{ + ${Object.keys(obj) + .map((key) => `${key}:${objToGql(obj[key])}`) .join(", ")} }` + return res +} + +export const getWhereArgArr = (whereArgs: any) => + `where: ${objToGql(whereArgs)}` + export const convertObjectToPropertiesString = (obj: any) => { let result = "" diff --git a/src/indexer-nibi/heart-monitor.test.ts b/src/indexer-nibi/heart-monitor.test.ts index bedd92d0..20fb1a72 100644 --- a/src/indexer-nibi/heart-monitor.test.ts +++ b/src/indexer-nibi/heart-monitor.test.ts @@ -1016,6 +1016,10 @@ const testWasm = async (args: QueryWasmArgs, fields?: GqlWasmFields) => { test("wasm", async () => { await testWasm({ userContracts: { + where: { + contractAddress: { like: "123" }, + userAddress: { eq: "456" }, + }, limit: 1, }, })