Skip to content

Commit 5cb4311

Browse files
committed
fix(hide field): Self relation field
close: unlight#103
1 parent 994acf3 commit 5cb4311

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

src/handlers/input-type.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ export function inputType(
151151
if (
152152
graphqlImport.specifier &&
153153
!importDeclarations.has(graphqlImport.name) &&
154-
((graphqlImport.name !== inputType.name && !shouldHideField) ||
155-
(shouldHideField && referenceName === graphqlImport.name))
154+
graphqlImport.name !== inputType.name
155+
// ((graphqlImport.name !== inputType.name && !shouldHideField) ||
156+
// (shouldHideField && referenceName === graphqlImport.name))
156157
) {
157158
importDeclarations.set(graphqlImport.name, {
158159
namedImports: [{ name: graphqlImport.name }],

src/test/helpers.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ export function getPropertyStructure(sourceFile: SourceFile, name: string) {
2828

2929
export function testSourceFile(args: {
3030
project: Project;
31-
file: string;
31+
file?: string;
32+
class?: string;
3233
property?: string;
3334
}) {
34-
const { project, file, property } = args;
35-
const sourceFile = project.getSourceFileOrThrow(s =>
36-
s.getFilePath().endsWith(file),
37-
);
35+
const { project, file, property, class: className } = args;
36+
let sourceFile: SourceFile;
37+
if (file) {
38+
sourceFile = project.getSourceFileOrThrow(s => s.getFilePath().endsWith(file));
39+
} else if (className) {
40+
sourceFile = project.getSourceFileOrThrow(s => Boolean(s.getClass(className)));
41+
} else {
42+
throw new TypeError('file or class must be provided');
43+
}
44+
3845
const importDeclarations = sourceFile
3946
.getImportDeclarations()
4047
.map(d => d.getStructure());

src/test/hide-field.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,36 @@ describe.skip('hide enum', () => {
323323
}
324324
});
325325
});
326+
327+
describe('hide with self reference', () => {
328+
before(async () => {
329+
({ project } = await testGenerate({
330+
schema: `model User {
331+
id Int @id
332+
parentId Int
333+
/// @HideField({ output: false, input: true })
334+
parent User @relation("UserToUser", fields: [parentId], references: [id])
335+
/// @HideField({ output: false, input: true })
336+
user User[] @relation("UserToUser")
337+
}`,
338+
}));
339+
});
340+
341+
it('smoke', () => {
342+
const files = project.getSourceFiles().map(s => s.getBaseName());
343+
expect(files).toBeTruthy();
344+
});
345+
346+
it('order by with relation self import', () => {
347+
const s = testSourceFile({
348+
project,
349+
class: 'UserOrderByWithRelationAndSearchRelevanceInput',
350+
});
351+
352+
expect(s.namedImports).not.toContainEqual(
353+
expect.objectContaining({
354+
name: 'UserOrderByWithRelationAndSearchRelevanceInput',
355+
}),
356+
);
357+
});
358+
});

0 commit comments

Comments
 (0)