Skip to content

Commit

Permalink
Fix many issues (#309)
Browse files Browse the repository at this point in the history
* [schema][fix] generate typescript for null able fields

* [admin] improve the modal width

* Generator:SDL: fix typescript generator make null for not null fields

* upadte snapshots
  • Loading branch information
AhmedElywa authored Aug 20, 2023
1 parent 7eb75b3 commit 5e768a5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion packages/admin/src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Modal: React.FC<ModalProps> = ({ children, on, toggle }) => {
className="justify-center items-center flex overflow-x-hidden overflow-y-auto fixed inset-0 outline-none focus:outline-none"
>
<div className="absolute inset-0 w-full h-full bg-black bg-opacity-25" onClick={toggle} />
<div className="relative w-auto my-6 mx-auto md:max-w-5xl max-w-full">{children}</div>
<div className="relative w-full my-6 mx-auto lg:w-10/12 max-w-full">{children}</div>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/src/sdl/GenerateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class GenerateTypes {
const inputType = getInputType(arg, this.options);
args.push(
`${arg.name}${arg.isRequired ? '' : '?'}: ${this.getOutputType(inputType, true)}${
field.isNullable ? ' | null' : ''
arg.isNullable ? ' | null' : ''
}`,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,34 +419,34 @@ export type PostMaxAggregateOutputType = {
}
export interface UserPostsArgs {
where?: PostWhereInput | null
orderBy?: PostOrderByWithRelationInput[] | null
cursor?: PostWhereUniqueInput | null
take?: number | null
skip?: number | null
distinct?: PostScalarFieldEnum[] | null
where?: PostWhereInput
orderBy?: PostOrderByWithRelationInput[]
cursor?: PostWhereUniqueInput
take?: number
skip?: number
distinct?: PostScalarFieldEnum[]
}
export interface PostAuthorArgs {
where?: UserWhereInput | null
where?: UserWhereInput
}
export interface FindFirstUserArgs {
where?: UserWhereInput | null
orderBy?: UserOrderByWithRelationInput[] | null
cursor?: UserWhereUniqueInput | null
take?: number | null
skip?: number | null
distinct?: UserScalarFieldEnum[] | null
where?: UserWhereInput
orderBy?: UserOrderByWithRelationInput[]
cursor?: UserWhereUniqueInput
take?: number
skip?: number
distinct?: UserScalarFieldEnum[]
}
export interface FindFirstUserOrThrowArgs {
where?: UserWhereInput | null
orderBy?: UserOrderByWithRelationInput[] | null
cursor?: UserWhereUniqueInput | null
take?: number | null
skip?: number | null
distinct?: UserScalarFieldEnum[] | null
where?: UserWhereInput
orderBy?: UserOrderByWithRelationInput[]
cursor?: UserWhereUniqueInput
take?: number
skip?: number
distinct?: UserScalarFieldEnum[]
}
export interface FindManyUserArgs {
Expand Down Expand Up @@ -481,29 +481,29 @@ export interface GroupByUserArgs {
}
export interface FindUniqueUserArgs {
where: UserWhereUniqueInput | null
where: UserWhereUniqueInput
}
export interface FindUniqueUserOrThrowArgs {
where: UserWhereUniqueInput | null
where: UserWhereUniqueInput
}
export interface FindFirstPostArgs {
where?: PostWhereInput | null
orderBy?: PostOrderByWithRelationInput[] | null
cursor?: PostWhereUniqueInput | null
take?: number | null
skip?: number | null
distinct?: PostScalarFieldEnum[] | null
where?: PostWhereInput
orderBy?: PostOrderByWithRelationInput[]
cursor?: PostWhereUniqueInput
take?: number
skip?: number
distinct?: PostScalarFieldEnum[]
}
export interface FindFirstPostOrThrowArgs {
where?: PostWhereInput | null
orderBy?: PostOrderByWithRelationInput[] | null
cursor?: PostWhereUniqueInput | null
take?: number | null
skip?: number | null
distinct?: PostScalarFieldEnum[] | null
where?: PostWhereInput
orderBy?: PostOrderByWithRelationInput[]
cursor?: PostWhereUniqueInput
take?: number
skip?: number
distinct?: PostScalarFieldEnum[]
}
export interface FindManyPostArgs {
Expand Down Expand Up @@ -538,11 +538,11 @@ export interface GroupByPostArgs {
}
export interface FindUniquePostArgs {
where: PostWhereUniqueInput | null
where: PostWhereUniqueInput
}
export interface FindUniquePostOrThrowArgs {
where: PostWhereUniqueInput | null
where: PostWhereUniqueInput
}
export interface CreateOneUserArgs {
Expand All @@ -561,12 +561,12 @@ export interface CreateManyUserArgs {
}
export interface DeleteOneUserArgs {
where: UserWhereUniqueInput | null
where: UserWhereUniqueInput
}
export interface UpdateOneUserArgs {
data: UserUpdateInput | null
where: UserWhereUniqueInput | null
data: UserUpdateInput
where: UserWhereUniqueInput
}
export interface UpdateManyUserArgs {
Expand Down Expand Up @@ -594,12 +594,12 @@ export interface CreateManyPostArgs {
}
export interface DeleteOnePostArgs {
where: PostWhereUniqueInput | null
where: PostWhereUniqueInput
}
export interface UpdateOnePostArgs {
data: PostUpdateInput | null
where: PostWhereUniqueInput | null
data: PostUpdateInput
where: PostWhereUniqueInput
}
export interface UpdateManyPostArgs {
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class GenerateTypeScript {
this.schema.models.forEach((model) => {
const fields: string[] = [`export interface ${model.name} {`];
model.fields.forEach((field) => {
fields.push(`${field.name}${field.required ? '' : '?'}: ${this.getType(field)}`);
fields.push(`${field.name}: ${this.getType(field)}${field.required ? '' : ' | null'}`);
});
fields.push('}');
models.push(fields.join('\n'));
Expand Down
8 changes: 4 additions & 4 deletions packages/schema/tests/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ test('generate typescript types from prisma schema', () => {
id: number
createdAt: Date
email: string
name?: string
name: string | null
password: string
permissions: any
posts?: Post[]
posts: Post[] | null
}
export interface Post {
id: number
published: boolean
title: string
author?: User
authorId?: number
author: User | null
authorId: number | null
createdAt: Date
updatedAt: Date
}
Expand Down

0 comments on commit 5e768a5

Please sign in to comment.