Confused about how Type resolver works

prisma

#1

I am writing a Conversation type resolver, that should return only the comments that don’t have a parentComment:

Conversation: {     
  async comments(parent, args, context) {
    return prisma.conversation({ id: parent.id }).comments( { where: { parentComment: xxxx} } )
  },
}

These are the comments types generated by Prisma:

comments: <T = FragmentableArray<Comment>>(args?: {
    where?: CommentWhereInput;
    orderBy?: CommentOrderByInput;
    skip?: Int;
    after?: String;
    before?: String;
    first?: Int;
    last?: Int;
  }) => T;

I’m not sure what to write in xxxx. I tried to write undefined but it did not have any effect: my query still pulls all the comments whether or not they have a parentComment.

If this helps, here’s my comments query resolver.

export const comments = (parent: any, args: any, { prisma }: Context) => {
	return prisma.comments()
}

data model:

type Comment {
    id: ID! @unique
    parentComment: Comment @relation(name: "Replies")
    comments: [Comment!]! @relation(name: "Replies")
}

type Conversation {
    id: ID! @unique
    comments: [Comment!]! @relation(name: "Conversation")
}

And my query:

query GetConversation($conversationId: ConversationWhereUniqueInput!) {
  conversation(where: $conversationId) {
    id   
    comments(where: { parentComment: null }) {
      id
    }
  }
}

#2

You can use

Conversation: {     
  async comments(parent, args, context) {
    return prisma.conversation({ id: parent.id }).comments( { where: { parentComment: null } } )
  },
}

This returned the comment with no parent for me
image

First one is all, the second one is with the above. It works well.


#3

Hey thanks @pantharshit00 !

I tried that before, but seems that the types don’t accept null. Can either accept undefined or CommentWhereInput, and undefined didn’t work either.

{
	"resource": "/d:/Documents/software-dev/schedio/talk/front/src/main.ts",
	"owner": "typescript",
	"code": "2345",
	"severity": 8,
	"message": "Argument of type '{ where: { parentComment: null; }; }' is not assignable to parameter of type '{ where?: CommentWhereInput | undefined; orderBy?: \"id_ASC\" | \"id_DESC\" | \"content_ASC\" | \"content_DESC\" | \"createDate_ASC\" | \"createDate_DESC\" | \"createdAt_ASC\" | \"createdAt_DESC\" | \"updatedAt_ASC\" | \"updatedAt_DESC\" | undefined; ... 4 more ...; last?: number | undefined; }'.\n  Types of property 'where' are incompatible.\n    Type '{ parentComment: null; }' is not assignable to type 'CommentWhereInput'.\n      Types of property 'parentComment' are incompatible.\n        Type 'null' is not assignable to type 'CommentWhereInput | undefined'.",
	"source": "ts",
	"startLineNumber": 76,
	"startColumn": 63,
"endLineNumber": 76,
"endColumn": 97

}

Here’s CommentWhereInput.

export interface CommentWhereInput {
  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;
  author?: UserWhereInput;
  content?: String;
  content_not?: String;
  content_in?: String[] | String;
  content_not_in?: String[] | String;
  content_lt?: String;
  content_lte?: String;
  content_gt?: String;
  content_gte?: String;
  content_contains?: String;
  content_not_contains?: String;
  content_starts_with?: String;
  content_not_starts_with?: String;
  content_ends_with?: String;
  content_not_ends_with?: String;
  createDate?: DateTimeInput;
  createDate_not?: DateTimeInput;
  createDate_in?: DateTimeInput[] | DateTimeInput;
  createDate_not_in?: DateTimeInput[] | DateTimeInput;
  createDate_lt?: DateTimeInput;
  createDate_lte?: DateTimeInput;
  createDate_gt?: DateTimeInput;
  createDate_gte?: DateTimeInput;
  parentConversation?: ConversationWhereInput;
  parentComment?: CommentWhereInput;
  comments_every?: CommentWhereInput;
  comments_some?: CommentWhereInput;
  comments_none?: CommentWhereInput;
  bookmarkedBy_every?: UserWhereInput;
  bookmarkedBy_some?: UserWhereInput;
  bookmarkedBy_none?: UserWhereInput;
  likedBy_every?: UserWhereInput;
  likedBy_some?: UserWhereInput;
  likedBy_none?: UserWhereInput;
  dislikedBy_every?: UserWhereInput;
  dislikedBy_some?: UserWhereInput;
  dislikedBy_none?: UserWhereInput;
  attachments_every?: AttachmentWhereInput;
  attachments_some?: AttachmentWhereInput;
  attachments_none?: AttachmentWhereInput;
  AND?: CommentWhereInput[] | CommentWhereInput;
  OR?: CommentWhereInput[] | CommentWhereInput;
  NOT?: CommentWhereInput[] | CommentWhereInput;
}

#4

Looks like you are running into https://github.com/prisma/prisma/issues/3774

This will be fixed very soon. You can use ts-ignore till then. Otherwise you can also disable strictNullChecks in your tsconfig


#5

That’s great! Thanks so much, it solved my issue


#6

Awesome!

I will rather consider this a workaround right now so please keep an eye on that issue :slight_smile: