From cb6553004cff98c7925aaa7cd1dbcad5f5fbc50b Mon Sep 17 00:00:00 2001 From: Ruslan Shakirov Date: Thu, 30 May 2024 16:44:58 +0200 Subject: [PATCH] feat: add gql user query (#356) (#357) * feat: gql user * feat: move user query to a separate file --- src/gql/heart-monitor/heart-monitor.test.ts | 25 ++++++++++++++++ src/gql/heart-monitor/heart-monitor.ts | 11 +++++++ src/gql/query/index.ts | 3 +- src/gql/query/user.ts | 33 +++++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/gql/query/user.ts diff --git a/src/gql/heart-monitor/heart-monitor.test.ts b/src/gql/heart-monitor/heart-monitor.test.ts index 4665753c..30e97374 100644 --- a/src/gql/heart-monitor/heart-monitor.test.ts +++ b/src/gql/heart-monitor/heart-monitor.test.ts @@ -90,6 +90,7 @@ import { QueryStakingArgs, defaultStakingHistoryItem, GQLValidatorOrder, + GQLQueryGqlUserArgs, } from ".." const checkNoFields = (objects: T[], fields: string[]) => { @@ -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) diff --git a/src/gql/heart-monitor/heart-monitor.ts b/src/gql/heart-monitor/heart-monitor.ts index 8da52db0..7a7d3030 100644 --- a/src/gql/heart-monitor/heart-monitor.ts +++ b/src/gql/heart-monitor/heart-monitor.ts @@ -95,6 +95,9 @@ import { GqlOutStaking, QueryStakingArgs, staking, + GQLQueryGqlUserArgs, + user, + GqlOutUser, } from ".." /** IHeartMonitor is an interface for a Heart Monitor GraphQL API. @@ -220,6 +223,11 @@ export interface IHeartMonitor { fields: DeepPartial ) => Promise + readonly user: ( + args: GQLQueryGqlUserArgs, + fields: DeepPartial + ) => Promise + readonly users: ( args: GQLQueryGqlUsersArgs, fields: DeepPartial @@ -361,6 +369,9 @@ export class HeartMonitor implements IHeartMonitor { stats = async (args: QueryStatsArgs, fields: DeepPartial) => stats(args, this.gqlEndpt, fields) + user = async (args: GQLQueryGqlUserArgs, fields: DeepPartial) => + user(args, this.gqlEndpt, fields) + users = async (args: GQLQueryGqlUsersArgs, fields: DeepPartial) => users(args, this.gqlEndpt, fields) diff --git a/src/gql/query/index.ts b/src/gql/query/index.ts index 1c5fbeb7..0724566e 100644 --- a/src/gql/query/index.ts +++ b/src/gql/query/index.ts @@ -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" diff --git a/src/gql/query/user.ts b/src/gql/query/user.ts new file mode 100644 index 00000000..237893e4 --- /dev/null +++ b/src/gql/query/user.ts @@ -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 +) => { + return gqlQuery( + "user", + args, + convertObjectToPropertiesString(fields), + excludeParentObject + ) +} + +export const user = async ( + args: GQLQueryGqlUserArgs, + endpt: string, + fields: DeepPartial +): Promise => + doGqlQuery(userQueryString(args, false, fields), endpt)