-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from meetsmore/fmy/includeRelationFields-option
- Loading branch information
Showing
6 changed files
with
150 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import transformDMMF from '../generator/transformDMMF'; | ||
//@ts-ignore | ||
import { getDMMF } from '@prisma/sdk'; | ||
|
||
describe('transformDMMF', () => { | ||
it('show relation fields when includeRelationFields = true', async () => { | ||
const datamodelString = /* Prisma */ ` | ||
model User { | ||
id String @default(cuid()) @id | ||
name String | ||
otherField Int | ||
posts Post[] | ||
} | ||
model Post { | ||
id String @id @default(cuid()) | ||
title String? | ||
userId String | ||
user User @relation(fields:[userId], references:[id]) | ||
} | ||
`; | ||
|
||
const dmmf = await getDMMF({ datamodel: datamodelString }); | ||
const transformedDmmf = transformDMMF(dmmf, { | ||
includeRelationFields: true, | ||
}); | ||
|
||
expect(transformedDmmf).toMatchObject({ | ||
datamodel: { | ||
models: [ | ||
{ | ||
name: 'User', | ||
fields: [ | ||
{ name: 'id' }, | ||
{ name: 'name' }, | ||
{ name: 'otherField' }, | ||
{ name: 'posts' }, | ||
], | ||
}, | ||
{ | ||
name: 'Post', | ||
fields: [ | ||
{ name: 'id' }, | ||
{ name: 'title' }, | ||
{ name: 'userId' }, | ||
{ name: 'user' }, | ||
], | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
it('hide relation fields when includeRelationFields = false', async () => { | ||
const datamodelString = /* Prisma */ ` | ||
model User { | ||
id String @default(cuid()) @id | ||
name String | ||
otherField Int | ||
posts Post[] | ||
} | ||
model Post { | ||
id String @id @default(cuid()) | ||
title String? | ||
userId String | ||
user User @relation(fields:[userId], references:[id]) | ||
} | ||
`; | ||
|
||
const dmmf = await getDMMF({ datamodel: datamodelString }); | ||
const transformedDmmf = transformDMMF(dmmf, { | ||
includeRelationFields: false, | ||
}); | ||
|
||
expect(transformedDmmf).toMatchObject({ | ||
datamodel: { | ||
models: [ | ||
{ | ||
name: 'User', | ||
fields: [ | ||
{ name: 'id' }, | ||
{ name: 'name' }, | ||
{ name: 'otherField' }, | ||
], | ||
}, | ||
{ | ||
name: 'Post', | ||
fields: [ | ||
{ name: 'id' }, | ||
{ name: 'title' }, | ||
{ name: 'userId' }, | ||
], | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
}); |