"...must have a selection of subfields. Did you mean..."


#1

Not sure what I’m doing wrong with this resolver.

I have two types:

type Board {
  id: ID! @unique
  name: String!
  user: User!
  boardNodes: [BoardNode]
}

type BoardNode {
  id: ID! @unique
  title: String!
  description: String
  dependencies: [BoardNode]
  board: Board!
}

I’d like to create a BoardNode and attach it to a Board. My resolver looks like:

await context.prisma.mutation.updateBoard(
	{
		data: {
			boardNodes: {
				create: [
					{
						title: title,
						description: description
					}
				]
			}
		},
		where: {
			id: board
		}
	},
	info
);

Meanwhile, the associated, prisma-generated types look like:

type Mutation {
	updateBoard(data: BoardUpdateInput!, where: BoardWhereUniqueInput!): Board
}

input BoardUpdateInput {
	name: String
	user: UserUpdateOneRequiredWithoutBoardsInput
	boardNodes: BoardNodeUpdateManyWithoutBoardInput
}

input BoardNodeUpdateManyWithoutBoardInput {
	create: [BoardNodeCreateWithoutBoardInput!]
	connect: [BoardNodeWhereUniqueInput!]
	disconnect: [BoardNodeWhereUniqueInput!]
	delete: [BoardNodeWhereUniqueInput!]
	update: [BoardNodeUpdateWithWhereUniqueWithoutBoardInput!]
	updateMany: [BoardNodeUpdateManyWithWhereNestedInput!]
	deleteMany: [BoardNodeScalarWhereInput!]
	upsert: [BoardNodeUpsertWithWhereUniqueWithoutBoardInput!]
}

input BoardNodeCreateWithoutBoardInput {
	title: String!
	description: String
	dependencies: BoardNodeCreateManyInput
}
  1. I’m not exactly sure what an upsert is… may I should be upsert-ing instead of creating? (Trying to add to the array / create it if it doesn’t exist).

  2. I keep getting the error [GraphQL error]: Message: Field "boardNodes" of type "[BoardNode!]" must have a selection of subfields. Did you mean "boardNodes { ... }"?, Location: [object Object], Path: undefined. I’m confused by that. Maybe I’m not supposed to pass an array to it even though the graphql type looks like it takes an array?

Very grateful for any help!


#2

The answer for me was to make sure that the mutation I was writing had the right return type in the schema. And not to nest my resolver’s call to create a boardNode in an array. I guess that’s not needed…

const board = await context.prisma.mutation.updateBoard(
	{
		data: {
			boardNodes: {
				create: {
					title,
					description
				}
			}
		},
		where: {
			id
		}
	},
	info
);