High
High
WWasp
Created by High on 2/1/2025 in #🙋questions
Query with multiple entities
Hey everyone! 👋 I'm trying to work with multiple entities in a Wasp query and running into some TypeScript issues. Here's my query definition:
query getActiveGames {
fn: import { getActiveGames } from "@src/server/queries/game",
entities: [Game, User]
}
query getActiveGames {
fn: import { getActiveGames } from "@src/server/queries/game",
entities: [Game, User]
}
And the implementation:
export const getActiveGames: GetActiveGames<void, Game[]> = async (
_args,
context,
) => {
return context.entities.Game.findMany({
where: { isActive: true },
include: { players: true }
})
}
export const getActiveGames: GetActiveGames<void, Game[]> = async (
_args,
context,
) => {
return context.entities.Game.findMany({
where: { isActive: true },
include: { players: true }
})
}
The query works at runtime, but I'm getting TypeScript errors and missing intellisense. I've specified both Game and User entities in the query definition, but something seems off with the types. Is there a proper way to type queries that work with multiple entities? Thanks in advance! 🙏
10 replies