"No Node for the model User with value 'id1', 'id2' for id found."


#1

I am working on a GraphQL server build on GraphQL Yoga. I am trying to connect a array of User’s to a members field of Team type.

I’ve managed to get this working within Prisma but now I try to implement it in my GraphQL server but unfortunately I get an error when trying to mutate the mutation, the error: No Node for the model User with value cjp44bp63ynux0a039gk4118k,cjp44bp63ynux0a039gk4118k for id found. See my schema, resolver, datamodel and mutation below.

Schema

addTeam(name: String!, managerId: ID!, isPublic: Boolean = true, members: [ID]!) : Team!

Resolver

    const team = await ctx.db.mutation.createTeam({
        data: {
            name: args.name,
            isPublic: args.isPublic,
            manager: {
                connect: {
                    id: args.managerId,
                },
            },
            members: {
                connect: [
                    { id: args.members },
                ],
            },
        },
    }, info)

Prisma datamodel

type User {
  id: ID! @unique
  name: String!
  email: String! @unique
  username: String!
  password: String!
  resetToken: String
  resetTokenExpiry: Float
  isAdmin: Boolean
  createdAt: DateTime!
  updatedAt: DateTime!
  team: Team @relation(name: "TeamUserRelation")
}

type Team {
  id: ID! @unique
  name: String!
  manager: User! @relation(name: "TeamManagerRelation")
  isPublic: Boolean! @default(value: "true")
  members: [User]! @relation(name: "TeamUserRelation")
}

Mutation

mutation ADD_TEAM_MUTATION {
  addTeam(name: "Falcon 32", managerId: "cjp44bp63ynux0a039gk4118k", isPublic: true, 
    members: ["cjp44bp63ynux0a039gk4118k" "cjp44bp63ynux0a039gk4118k"]) {
    name
    manager {
      name
      email
    }
    members {
      name
      email
    }
  }
}

Anyone out there that can help?

Edit:

I’ve changed the question a bit since I fixed this problem but ran into another one.


#2

When you want to connect multiple items to a particular entity. You should use connect: [{ id: "<entityId>" }] instead of `connect: [""].

Suggestion:

   const team = await ctx.db.mutation.createTeam({
        data: {
            name: args.name,
            isPublic: args.isPublic,
            manager: {
                connect: {
                    id: args.managerId,
                },
            },
            members: {
                connect: [
                  { id: args.members }
                ],
            },
        },
    }, info)

I faced the same issue as you, by doing as I suggest it works for me. Hope that helps.


#3

Thanks for your reply! I updated the resolver. But I can’t add multiple nodes for some reason…

mutation ADD_TEAM_MUTATION {
  addTeam(name: "Falcon 22", managerId: "cjp44bp63ynux0a039gk4118k", isPublic: true, 
    members: ["cjp3ywladwe470a03cridu3gb", "cjp44bp63ynux0a039gk4118k"]) {
    name
    manager {
      name
      email
    }
    members {
      name
      email
    }
  }
}

The mutation is returning: “No Node for the model User with value cjp3ywladwe470a03cridu3gb,cjp44bp63ynux0a039gk4118k for id found.”. Any idea on this? A single node is working, like members: ["cjp3ywladwe470a03cridu3gb"] but it suppose to be possible to add multiple right?


#4

I’ve fixed the problem with a few lines but I don’t think it’s the proper solution for it.

    const members = args.members.map((member) => {
        return {id: member}
    })

    const team = await ctx.db.mutation.createTeam({
        data: {
            name: args.name,
            isPublic: args.isPublic,
            manager: {
                connect: {
                    id: args.managerId,
                },
            },
            members: {
                connect: members,
            },
        },
    }, info)