Skip to content
Merged
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
47 changes: 47 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,50 @@ Shared libraries:
- You should always write your code in a way that makes it easy to unit test.
- Comments shouldn't be used unless absolutely necessary. Write readable code that can be understood without comments, and only include comments for unavoidable business logic.
- Variable values should be separated into constants whenever possible. Avoid creating magic numbers.

### NestJS GraphQL Resolver Method Ordering

In NestJS GraphQL resolvers, organize methods by decorator type (not alphabetically across all methods). Within each decorator group, sort methods alphabetically.

**Order**:

1. `constructor`
2. `@Query` methods (alphabetically)
3. `@Mutation` methods (alphabetically)
4. `@ResolveField` methods (alphabetically)

**Rationale**: GraphQL queries, mutations, and field resolvers are fundamentally different operations. Grouping by decorator type maintains logical cohesion while the decorator itself provides visual separation (no comments needed).

**Example**:

```typescript
@Resolver(() => Content)
export class ContentResolver {
constructor(private contentService: ContentService) {}

@Query(() => Content)
async content(@Args("id") id: number) {
return await this.contentService.findContentById(id);
}

@Query(() => [Content])
async contentList(@Args("filter") filter?: ContentListFilter) {
return await this.contentService.findContentList(filter);
}

@Mutation(() => ContentCreateResult)
async contentCreate(@Args("input") input: ContentCreateInput) {
return await this.contentService.createContent(input);
}

@ResolveField(() => ContentCategory)
async contentCategory(@Parent() content: Content) {
return await this.dataLoaderService.contentCategory.findById(content.contentCategoryId);
}

@ResolveField(() => String)
async displayName(@Parent() content: Content) {
return `${content.name}${content.gate ? ` ${content.gate}관문` : ""}`;
}
}
```
89 changes: 88 additions & 1 deletion src/backend/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default [
...tseslint.configs.recommended,
{
files: ["src/**/*.ts", "test/**/*.ts"],
ignores: ["dist", "node_modules"],
ignores: ["dist", "node_modules", "**/*.resolver.ts"],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
Expand Down Expand Up @@ -66,4 +66,91 @@ export default [
],
},
},
{
files: ["**/*.resolver.ts"],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
ecmaVersion: "latest",
project: "./tsconfig.json",
sourceType: "module",
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
"@typescript-eslint": tseslint.plugin,
perfectionist,
},
rules: {
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"perfectionist/sort-classes": [
"error",
{
type: "alphabetical",
order: "asc",
groups: [
"constructor",
"decorated-query-method",
"decorated-mutation-method",
"decorated-resolve-field-method",
"unknown",
],
customGroups: [
{
groupName: "decorated-query-method",
selector: "method",
modifiers: ["decorated"],
decoratorNamePattern: "Query",
},
{
groupName: "decorated-mutation-method",
selector: "method",
modifiers: ["decorated"],
decoratorNamePattern: "Mutation",
},
{
groupName: "decorated-resolve-field-method",
selector: "method",
modifiers: ["decorated"],
decoratorNamePattern: "ResolveField",
},
],
},
],
"perfectionist/sort-interfaces": [
"error",
{
order: "asc",
type: "alphabetical",
},
],
"perfectionist/sort-object-types": [
"error",
{
order: "asc",
type: "alphabetical",
},
],
"perfectionist/sort-objects": [
"error",
{
order: "asc",
partitionByComment: true,
type: "alphabetical",
},
],
},
},
];
5 changes: 3 additions & 2 deletions src/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
"@prisma/client": "5.22.0",
"@quixo3/prisma-session-store": "3.1.13",
"apollo-server-express": "3.13.0",
"class-transformer": "0.5.1",
"class-validator": "0.14.2",
"dataloader": "2.2.3",
"dayjs": "1.11.13",
"discord-webhook-node": "1.1.8",
"es-toolkit": "1.42.0",
"express-session": "1.18.1",
"graphql": "16.9.0",
"lodash": "4.17.21",
"nestjs-cls": "6.1.0",
"passport": "0.7.0",
"passport-discord": "0.1.4",
Expand All @@ -59,7 +61,6 @@
"@types/express": "5.0.0",
"@types/express-session": "1.18.1",
"@types/jest": "29.5.2",
"@types/lodash": "4.17.13",
"@types/node": "20.3.1",
"@types/passport": "1.0.17",
"@types/passport-discord": "0.1.14",
Expand Down
Loading
Loading