Skip to content

Commit

Permalink
feat: add gql user query (#356) (#357)
Browse files Browse the repository at this point in the history
* feat: gql user

* feat: move user query to a separate file
  • Loading branch information
ruslan-sh-r authored May 30, 2024
1 parent 083edbf commit cb65530
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/gql/heart-monitor/heart-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import {
QueryStakingArgs,
defaultStakingHistoryItem,
GQLValidatorOrder,
GQLQueryGqlUserArgs,
} from ".."

const checkNoFields = <T>(objects: T[], fields: string[]) => {
Expand Down Expand Up @@ -987,6 +988,30 @@ test("wasm", async () => {
)
})

const testUser = async (args: GQLQueryGqlUserArgs, fields: GQLUser) => {
const resp = await heartMonitor.user(args, fields)
expect(resp).toHaveProperty("user")

const fieldsToCheck = ["address", "balances", "created_block", "is_blocked"]
fieldsToCheck.forEach((field: string) => {
expect(resp.user).toHaveProperty(field)
})
}

test("user", async () => {
await testUser(
{
where: {
address: "nibi14garegtvsx3zcku4esd30xd2pze7ck44ysxeg3",
},
},
{
...defaultUser,
is_blocked: true,
}
)
})

const testUsers = async (args: GQLQueryGqlUsersArgs, fields: GQLUser) => {
const resp = await heartMonitor.users(args, fields)

Expand Down
11 changes: 11 additions & 0 deletions src/gql/heart-monitor/heart-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ import {
GqlOutStaking,
QueryStakingArgs,
staking,
GQLQueryGqlUserArgs,
user,
GqlOutUser,
} from ".."

/** IHeartMonitor is an interface for a Heart Monitor GraphQL API.
Expand Down Expand Up @@ -220,6 +223,11 @@ export interface IHeartMonitor {
fields: DeepPartial<GQLStatsFields>
) => Promise<GqlOutStats>

readonly user: (
args: GQLQueryGqlUserArgs,
fields: DeepPartial<GQLUser>
) => Promise<GqlOutUser>

readonly users: (
args: GQLQueryGqlUsersArgs,
fields: DeepPartial<GQLUser>
Expand Down Expand Up @@ -361,6 +369,9 @@ export class HeartMonitor implements IHeartMonitor {
stats = async (args: QueryStatsArgs, fields: DeepPartial<GQLStatsFields>) =>
stats(args, this.gqlEndpt, fields)

user = async (args: GQLQueryGqlUserArgs, fields: DeepPartial<GQLUser>) =>
user(args, this.gqlEndpt, fields)

users = async (args: GQLQueryGqlUsersArgs, fields: DeepPartial<GQLUser>) =>
users(args, this.gqlEndpt, fields)

Expand Down
3 changes: 2 additions & 1 deletion src/gql/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export * from "./spotLpPositions"
export * from "./spotPoolCreated"
export * from "./spotPoolExited"
export * from "./spotPoolJoined"
export * from "./spotPoolSwap"
export * from "./spotPools"
export * from "./spotPoolSwap"
export * from "./staking"
export * from "./stats"
export * from "./user"
export * from "./users"
export * from "./wasm"
33 changes: 33 additions & 0 deletions src/gql/query/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
convertObjectToPropertiesString,
doGqlQuery,
gqlQuery,
GQLQuery,
GQLUser,
DeepPartial,
GQLQueryGqlUserArgs,
} from ".."

export interface GqlOutUser {
user?: GQLQuery["user"]
}

export const userQueryString = (
args: GQLQueryGqlUserArgs,
excludeParentObject: boolean,
fields: DeepPartial<GQLUser>
) => {
return gqlQuery(
"user",
args,
convertObjectToPropertiesString(fields),
excludeParentObject
)
}

export const user = async (
args: GQLQueryGqlUserArgs,
endpt: string,
fields: DeepPartial<GQLUser>
): Promise<GqlOutUser> =>
doGqlQuery(userQueryString(args, false, fields), endpt)

0 comments on commit cb65530

Please sign in to comment.