Query resolver fails "invalid argument for the where selector"

prisma

#1

I set up prisma with a graphql yoga server and have both GraphQL playgrounds available.

I can’t get this simple resolver to work in the Yoga GraphQL Playground:

const resolvers = {
	Query: {
        conversation(parent: any, { id }: { id: string }, { prisma }: Context) {
            return prisma.conversation( { id } )
        }
	},
	Mutation: mutation
}

I used this query:

query getConversation {
  conversation(where: {
    id: "cjrqzinj4004e0a30ch4pccml"
  }) {
    id
    title    
  }
}

Error message is:

{
  "data": {
    "conversation": null
  },
  "errors": [
    {
      "message": "You provided an invalid argument for the where selector on Conversation.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "conversation"
      ],
      "code": 3040,
      "requestId": "local:cjrsahjoo00ai0a30a5y8mnvp"
    }
  ],
  "extensions": {}
}

The query works in the Prisma GraphQL playground.

Here is my data model:

type User {
  id: ID! @unique
  oauthId: String! @unique
  display: String!
  picture: String!
  likes: [Comment!]! @relation(name: "Likes")
  dislikes: [Comment!]! @relation(name: "Dislikes")
  bookmarks: [Comment!]! @relation(name: "Bookmarks")
  authorOf: [Comment!]! @relation(name: "Author")
  starterOf: [Conversation!]! @relation(name: "Starter")
}

type Attachment {
    id: ID! @unique
    name: String!
    createOn: DateTime!
    mediaType: String!
    comment: Comment! @relation(name: "Attachments")
}

type Comment {
    id: ID! @unique
    author: User! @relation(name: "Author")
    content: String!
    createDate: DateTime!
    parentConversation: Conversation @relation(name: "Conversation")
    parentComment: Comment @relation(name: "Replies")
    comments: [Comment!]! @relation(name: "Replies")
    bookmarkedBy: [User!]! @relation(name: "Bookmarks")
    likedBy: [User!]! @relation(name: "Likes")
    dislikedBy: [User!]! @relation(name: "Dislikes")
    attachments: [Attachment!]! @relation(name: "Attachments")
}

enum ParentType {
    Organization,
    Portfolio,
    Project,
    WbsComponent,
    WorkItem
}

type Parent {
    id: ID! @unique
    parent: String! @unique
    type: ParentType!
    conversations: [Conversation!]! @relation(name: "Parent")
}

type Conversation {
    id: ID! @unique
    parent: Parent! @relation(name: "Parent")
    organization: String!
    title: String!
    author: User! @relation(name: "Starter")
    createdOn: DateTime!
    comments: [Comment!]! @relation(name: "Conversation")
}

#2

Looks like you are destructuring things incorrectly. Try this:

const resolvers = {
	Query: {
        conversation(parent: any, { where: { id } }, { prisma }: Context) {
            return prisma.conversation( { id } )
        }
	},
	Mutation: mutation
}

Also, since you are using TS I will highly recommend to checkout graphqlgen to automatically type your resolvers: https://github.com/prisma/graphqlgen


#3

Thank you so much! You saved me hours of frustration. I’ll have a look at graphqlgen, I really don’t want to spend time typing my resolvers and making mistakes like I did.


#4

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.