Could not find argument id for type

prisma

#1

I’m having an error that says “Could not find argument id for type convertion”. I don’t understand the error and maybe I’m querying prisma client wrong but I have no idea what else to try. Below is my code.

I have a schema like this

type Query {
  info: String!
  users: [User!]!
  conversations: [Conversation!]!
  conversation(id: String!): Conversation!
}

type Mutation {
  createUser(name: String!): User!
  createConversation(user1: ID!, user2: ID!): Conversation!
}

type User {
  id: ID!
  name: String!
  conversations: [Conversation!]!
}

type Conversation {
  id: ID!
  messages: [Message!]!
  users: [User!]!
}

type Message {
  id: ID!
  content: String!
  createdAt: String!
  userId: ID!
  conversation: Conversation!
}

And I have my resolvers implemented as such:

const resolvers = {
  Query: {
    info: (root, args, context) =>
      `This is the API of chatt app for Packt course`,
    users: (root, args, context) => context.prisma.users(),
    conversations: (root, args, context) => context.prisma.conversations(),
    conversation: (root, args, context) =>
      context.prisma.conversations({ id: args.id })
  },
  Mutation: {
    createUser: (root, args, context) => {
      return context.prisma.createUser({
        name: args.name
      });
    },
    createConversation: (root, args, context) => {
      return context.prisma.createConversation({
        users: {
          connect: [{ id: args.user1 }, { id: args.user2 }]
        }
      });
    }
  },
  Conversation: {
    users: (parent, args, context) => {
      console.log("calling users");
      return context.prisma.conversations({ id: parent.id }).users();
    },
    id: (parent, args, context) => parent.id
  },

  User: {
    conversations: (parent, args, context) => {
      return context.prisma.users({ id: parent.id }).conversations();
    }
  }
};

When I call the query

query {
  conversation (id: "cjta0oy64ocr60b79pevff0lw"){
    id,
    users {
      name
    }
  }
}

I get an error that says

{
  "data": null,
  "errors": [
    {
      "message": "Could not find argument id for type Conversation",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "conversation"
      ]
    }
  ]
}

I don’t know what that means and I’ve tried adding ID to the resolver. Maybe I’m querying prisma client wrong but I can’t find any other info


#2

Change this to:

 Conversation: {
    users: (parent, args, context) => {
      console.log("calling users");
      return context.prisma.conversation({ id: parent.id }).users();
    },
    id: (parent, args, context) => parent.id
  },

Do not use the plural, you need to specifically filter it here.


#3

@pantharshit00

That seems to work for me, but I don’t understand why it needs to be done, does it have anything to do with User type?

I didn’t have to do this for any other object in my schema other than the User object.