Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: gql when args fix #299

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading