Skip to content

Commit

Permalink
feat: gql user
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslan-sh-r committed May 28, 2024
1 parent 5990369 commit 5227075
Show file tree
Hide file tree
Showing 4 changed files with 61 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
2 changes: 1 addition & 1 deletion src/gql/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ 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 "./users"
Expand Down
24 changes: 24 additions & 0 deletions src/gql/query/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@ import {
GQLUser,
GQLUserOrder,
DeepPartial,
GQLQueryGqlUserArgs,
} from ".."

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

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

export const usersQueryString = (
args: GQLQueryGqlUsersArgs,
excludeParentObject: boolean,
Expand All @@ -30,6 +47,13 @@ export const usersQueryString = (
)
}

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

export const users = async (
args: GQLQueryGqlUsersArgs,
endpt: string,
Expand Down

0 comments on commit 5227075

Please sign in to comment.