Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Args not typed on extendConnection resolver #1123

Open
brandaspt opened this issue Jul 31, 2022 · 1 comment
Open

Args not typed on extendConnection resolver #1123

brandaspt opened this issue Jul 31, 2022 · 1 comment

Comments

@brandaspt
Copy link

I have the following code:

export const postQueries = queryField(t => {
	t.connectionField("getAllPublishedPosts", {
		type: PostType,
		cursorFromNode: ({ id }) => id,
		additionalArgs: {
			filter: nullable(stringArg()),
		},
		nodes: async (_, { first, after, filter }, { prisma }) => {
			const posts = await prisma.post.findMany({
				where: {
					AND: [
						{ published: true },
						{
							OR: filter
								? [
										{ content: { contains: filter, mode: "insensitive" } },
										{ title: { contains: filter, mode: "insensitive" } },
								  ]
								: undefined,
						},
					],
				},
				take: first + 1,
				skip: after ? 1 : 0,
				cursor: after ? { id: after } : undefined,
			})
			return posts
		},
		extendConnection: t => {
			t.int("totalCount", {
				resolve: (_, { filter }: { filter?: string }, { prisma }) => // args are not typed here. had to type manually
					prisma.post.count({
						where: {
							AND: [
								{ published: true },
								{
									OR: filter
										? [
												{ content: { contains: filter, mode: "insensitive" } },
												{ title: { contains: filter, mode: "insensitive" } },
										  ]
										: undefined,
								},
							],
						},
					}),
			})
		},
	})
})

I was expecting args to be typed on the extendConnection resolver but typescript keeps complaining that filter has any type. root and ctx are typed though...
Am I missing something?

@moderndegree
Copy link

I am seeing the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants