Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.
This repository has been archived by the owner on May 10, 2018. It is now read-only.

For optional fields, there is no constraint of type "null" #75

Open
@OniVe

Description

Bug Report

Current behavior

There is no possibility of setting the value "null" for arguments because of the restrictions on types

Reproduction

Scheme

type User {
  id: ID! @unique
  name: String!
}

type Post {
  id: ID! @unique
  isPublished: Boolean! @default(value: "false")
  title: String!
  text: String # Not required
  user: User # Not required
}

./generated/prisma.ts

// ...
export interface PostWhereInput {
  AND?: PostWhereInput[] | PostWhereInput
  OR?: PostWhereInput[] | PostWhereInput
  id?: ID_Input
  id_not?: ID_Input
  id_in?: ID_Input[] | ID_Input
  id_not_in?: ID_Input[] | ID_Input
  id_lt?: ID_Input
  id_lte?: ID_Input
  id_gt?: ID_Input
  id_gte?: ID_Input
  id_contains?: ID_Input
  id_not_contains?: ID_Input
  id_starts_with?: ID_Input
  id_not_starts_with?: ID_Input
  id_ends_with?: ID_Input
  id_not_ends_with?: ID_Input
  isPublished?: Boolean
  isPublished_not?: Boolean
  title?: String
  title_not?: String
  title_in?: String[] | String
  title_not_in?: String[] | String
  title_lt?: String
  title_lte?: String
  title_gt?: String
  title_gte?: String
  title_contains?: String
  title_not_contains?: String
  title_starts_with?: String
  title_not_starts_with?: String
  title_ends_with?: String
  title_not_ends_with?: String
  text?: String // Must be: Nullable<String> where: type Nullable<T> = T | null
  text_not?: String // Must be: Nullable<String> where: type Nullable<T> = T | null
  text_in?: String[] | String
  text_not_in?: String[] | String
  text_lt?: String
  text_lte?: String
  text_gt?: String
  text_gte?: String
  text_contains?: String
  text_not_contains?: String
  text_starts_with?: String
  text_not_starts_with?: String
  text_ends_with?: String
  text_not_ends_with?: String
  user?: UserWhereInput // Must be: Nullable<UserWhereInput> where: type Nullable<T> = T | null
}
// ...
export type Query = {
// ...
posts: (args: { where?: PostWhereInput, orderBy?: PostOrderByInput, skip?: Int, after?: String, before?: String, first?: Int, last?: Int }, info?: GraphQLResolveInfo | string) => Promise<Post[]>
// ...
}

Resolver usage

myResolver(parent, args, context, info) {
  return context.db.query.posts(
    { 
      where: {
        isPublished: true,
        user: null // Error: The type "null" can not be assigned for the type "UserWhereInput | undefined".
      }
    },
      info
  );
}

Expected behavior?

No typescript validation errors.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions