Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.2.15",
"version": "1.2.16",
"main": "index.ts",
"license": "BUSL-1.1",
"scripts": {
Expand Down
11 changes: 8 additions & 3 deletions src/resolvers/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ module.exports = {
* @param factories - factories for working with models
* @return {Promise<UserModel[]> | null}
*/
async visitedBy({ visitedBy, projectId }, _args, { factories, user }) {
async visitedBy({ visitedBy, projectId, workspaceId }, _args, { factories, user }) {
/**
* Crutch for Demo Workspace
* Prefer workspaceId from parent if present to avoid extra project lookup
*/
const project = await factories.projectsFactory.findById(projectId);
const resolvedWorkspaceId = workspaceId || (await (async () => {
const project = await factories.projectsFactory.findById(projectId);

return project ? project.workspaceId.toString() : undefined;
})());

if (project.workspaceId.toString() === '6213b6a01e6281087467cc7a') {
if (resolvedWorkspaceId === '6213b6a01e6281087467cc7a') {
return [ await factories.usersFactory.findById(user.id) ];
}

Expand Down
14 changes: 14 additions & 0 deletions src/resolvers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,20 @@ module.exports = {

const dailyEventsPortion = await factory.findDailyEventsPortion(limit, nextCursor, sort, filters, search);

/**
* Pass workspaceId down to events so nested resolvers (like Event.visitedBy)
* can avoid extra project lookups.
*/
if (dailyEventsPortion && Array.isArray(dailyEventsPortion.dailyEvents)) {
dailyEventsPortion.dailyEvents = dailyEventsPortion.dailyEvents.map((item) => ({
...item,
event: {
...item.event,
workspaceId: project.workspaceId && project.workspaceId.toString ? project.workspaceId.toString() : project.workspaceId,
},
}));
}

return dailyEventsPortion;
},

Expand Down