Skip to content

Commit

Permalink
add operationName to some zeus queries (#3378)
Browse files Browse the repository at this point in the history
  • Loading branch information
wentokay authored Mar 16, 2023
1 parent 9b3aff1 commit 8297bf5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 36 deletions.
5 changes: 4 additions & 1 deletion backend/native/backend-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
"build": "esbuild ./src/index.js --bundle --platform=node --outfile=dist/index.js",
"start": "npm run build && node dist/index.js",
"zeus-ws": "npx graphql-zeus http://localhost:8113/v1/graphql ./src --header=x-hasura-admin-secret:myadminsecretkey --header=x-hasura-role:chat --subscriptions graphql-ws",
"zeus": "npx graphql-zeus http://localhost:8113/v1/graphql ./src --header=x-hasura-admin-secret:myadminsecretkey --header=x-hasura-role:chat --subscriptions"
"zeus": "npx graphql-zeus http://localhost:8113/v1/graphql ./src --header=x-hasura-admin-secret:myadminsecretkey --header=x-hasura-role:chat --subscriptions",
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx --cache",
"lint:fix": "yarn run lint --fix"
},
"devDependencies": {
"eslint-config-custom": "*",
"esbuild": "^0.17.11"
}
}
28 changes: 17 additions & 11 deletions backend/native/backend-ws/src/db/users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Chain } from "@coral-xyz/zeus";

import { AUTH_HASURA_URL, AUTH_JWT } from "../config";

const chain = Chain(AUTH_HASURA_URL, {
Expand All @@ -10,16 +11,21 @@ const chain = Chain(AUTH_HASURA_URL, {
export const getUsers = async (
userIds: string[]
): Promise<{ id: string; username: string }[]> => {
const response = await chain("query")({
auth_users: [
{
where: { id: { _in: userIds } },
},
{
id: true,
username: true,
},
],
});
const response = await chain("query")(
{
auth_users: [
{
where: { id: { _in: userIds } },
},
{
id: true,
username: true,
},
],
},
{
operationName: "getUsers",
}
);
return response.auth_users || [];
};
3 changes: 1 addition & 2 deletions backend/native/backend-ws/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
"noImplicitAny": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
"files": ["src/index.ts"]
}
}
27 changes: 16 additions & 11 deletions backend/native/backpack-api/src/db/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ export const getUsersMetadata = async (
id: unknown;
}[]
> => {
const response = await chain("query")({
auth_users: [
{
where: { id: { _in: userIds } },
},
{
id: true,
username: true,
},
],
});
const response = await chain("query")(
{
auth_users: [
{
where: { id: { _in: userIds } },
},
{
id: true,
username: true,
},
],
},
{
operationName: "getUsersMetadata",
}
);
return response.auth_users.map((x) => ({
username: x.username,
id: x.id,
Expand Down
25 changes: 14 additions & 11 deletions backend/native/notifications-worker/src/db/collection_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ const chain = Chain(AUTH_HASURA_URL, {
});

export const getLatestReadMessage = async (uuid: string, room: string) => {
const response = await chain("query")({
auth_collection_messages_by_pk: [
{
collection_id: room,
uuid: uuid,
},
{
last_read_message_id: true,
},
],
});
const response = await chain("query")(
{
auth_collection_messages_by_pk: [
{
collection_id: room,
uuid: uuid,
},
{
last_read_message_id: true,
},
],
},
{ operationName: "getLatestReadMessage" }
);
return response.auth_collection_messages_by_pk.last_read_message_id;
};

1 comment on commit 8297bf5

@vercel
Copy link

@vercel vercel bot commented on 8297bf5 Mar 16, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.