Skip to content

Commit

Permalink
Optimize formatting and data loading in resolvers
Browse files Browse the repository at this point in the history
The primary action taken in this commit was the optimization of GraphQL resolvers. This was done by including a the 'formatUserForGraphql' function in issues, projects, and issue comments resolvers which helped streamline the process of formatting users for GraphQL. In addition, the DataLoader was primed with 'findIssueComment', improving data loading efficiency. Lastly, code related to GraphQL after file write hooks and mappers were revised in 'codegen.ts'.
  • Loading branch information
claygorman committed Jan 13, 2024
1 parent 6b67d38 commit 0e41a54
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
13 changes: 2 additions & 11 deletions backend/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,13 @@ const config: CodegenConfig = {
},
hooks: {
afterOneFileWrite: [
'sed -i \'\' -e \'1s|import { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from "graphql";|import { type GraphQLResolveInfo, GraphQLScalarType, type GraphQLScalarTypeConfig } from "graphql";|\' src/__generated__/resolvers-types.ts',
"sed -i '' 's/import { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from '\\''graphql'\\'';/import type { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from '\\''graphql'\\'';/g' src/__generated__/resolvers-types.ts\n",
"sed -i '' 's/import { ApolloContext } from '\\''..\\/server\\/apollo.js'\\'';/import type { ApolloContext } from '\\''..\\/server\\/apollo.js'\\'';/g' src/__generated__/resolvers-types.ts\n",
],
},
config: {
useIndexSignature: true,
contextType: '../server/apollo.js#ApolloContext',
mappers: {
// Project: '../db/models/types.js#Project as ProjectModel',
// ProjectTag: '../db/models/types.js#ProjectTag as ProjectTagModel',
// CustomField: '../db/models/types.js#ProjectCustomField as ProjectCustomFieldModel',
// User: '../db/models/types.js#User as UserModel',
// Issue: '../db/models/types.js#Issue as IssueModel',
// IssueComment: '../db/models/types.js#IssueComment as IssueCommentModel',
// Board: '../db/models/types.js#Board as BoardModel',
// IssueStatus: '../db/models/types.js#IssueStatus as IssueStatusModel',
},
},
};

Expand Down
8 changes: 4 additions & 4 deletions backend/src/resolvers/issue-comment/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IssueCommentResolvers, MutationResolvers } from '../../__generated__/resolvers-types.js';
import { formatUserForGraphql } from '../user/helpers.js';

const Mutation: MutationResolvers = {
createIssueComment: async (parent, { input }, { db, user }) => {
Expand Down Expand Up @@ -52,6 +53,8 @@ const Mutation: MutationResolvers = {

await findIssueComment.save();

dataLoaderContext.prime(findIssueComment);

return {
...findIssueComment.toJSON(),
id: `${findIssueComment.id}`,
Expand All @@ -70,10 +73,7 @@ const IssueComment: IssueCommentResolvers = {
[EXPECTED_OPTIONS_KEY]: dataLoaderContext,
});

return {
...dbUser.toJSON(),
id: `${dbUser.id}`,
};
return formatUserForGraphql(dbUser);
},
};

Expand Down
2 changes: 1 addition & 1 deletion backend/src/resolvers/issue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../../__generated__/resolvers-types.js';
import { Issue as IssueModel } from '../../db/models/types.js';
import { websocketBroadcast } from '../../services/ws-server.js';
import { formatUserForGraphql } from '../user/helpers';
import { formatUserForGraphql } from '../user/helpers.js';

const Query: QueryResolvers = {
issues: async (parent, { input: { projectId, id, search, searchOperator } }, { db, dataLoaderContext }) => {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/resolvers/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type Resolvers,
type ViewState,
} from '../../__generated__/resolvers-types.js';
import { formatUserForGraphql } from '../user/helpers';
import { formatUserForGraphql } from '../user/helpers.js';

const Query: QueryResolvers = {
projects: async (parent, args, { db, dataLoaderContext }) => {
Expand Down

0 comments on commit 0e41a54

Please sign in to comment.