Skip to content

Commit

Permalink
chore: gql when args fix (#299)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
CalicoNino and ruslan-sh-r authored Jan 24, 2024
1 parent ee18f23 commit 10776c2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/pr-title-lint.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,5 @@ typings/
# End of https://www.gitignore.io/api/node,intellij+all,visualstudiocode
.yarn
.DS_Store

nibiru/
26 changes: 22 additions & 4 deletions src/indexer-nibi/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""

Expand Down
4 changes: 4 additions & 0 deletions src/indexer-nibi/heart-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})
Expand Down

1 comment on commit 10776c2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 96%
96.82% (6036/6234) 98.13% (683/696) 85% (187/220)

Please sign in to comment.