Skip to content

Commit 7d4630f

Browse files
authored
Merge pull request #61 from zerochae/fix/nestjs-graphql-decorator-parsing
fix: resolve NestJS GraphQL decorator parsing issue
2 parents 82ea51e + 5a30721 commit 7d4630f

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

lua/endpoint/parser/nestjs_parser.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ function NestJsParser:_looks_like_incomplete_decorator(content)
412412
end
413413
end
414414

415+
-- Special case for GraphQL decorators: @Query(() => Type) or @Mutation(() => Type)
416+
-- These need extended content to find the function name
417+
if self:_is_graphql_decorator(content) and content:match "^%s*@%w+%s*%(.-%)%s*$" then
418+
return true
419+
end
420+
415421
-- Special case for decorators that don't close properly
416422
-- Count parentheses to see if they're balanced
417423
local open_count = 0

tests/spec/nestjs_spec.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ async createNewUser(
179179
assert.equals("createUser", result.endpoint_path)
180180
end
181181
end)
182+
183+
it("should parse @Query without options on same line", function()
184+
local content = '@Query(() => [SomeDto])\n async getSomething(): Promise<SomeDto[]> {'
185+
local result = parser:parse_content(content, "users.resolver.ts", 1, 1)
186+
187+
if result then
188+
assert.equals("QUERY", result.method)
189+
assert.equals("getSomething", result.endpoint_path)
190+
end
191+
end)
192+
193+
it("should parse @Query with options starting on same line", function()
194+
local content = '@Query(() => [SomeDto], {\n nullable: true,\n })\n async getSomething(): Promise<SomeDto[]> {'
195+
local result = parser:parse_content(content, "users.resolver.ts", 1, 1)
196+
197+
if result then
198+
assert.equals("QUERY", result.method)
199+
assert.equals("getSomething", result.endpoint_path)
200+
end
201+
end)
182202
end)
183203

184204
describe("Search Command Generation", function()

0 commit comments

Comments
 (0)