Skip to content
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 opened this issue Mar 30, 2018 · 1 comment
Open

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

OniVe opened this issue Mar 30, 2018 · 1 comment

Comments

@OniVe
Copy link

OniVe commented Mar 30, 2018

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.

@danielkcz
Copy link

I tried the quick fix of adding | null here, but it's much more entangled there with all those recursive calls. It would probably require some different approach.

return `${(type as GraphQLNamedType).name}${(type as GraphQLNamedType).name === 'ID' ? '_Input' : ''}`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants