Question: is it possible to run queries from the server?
Just like the title says, is it possible to run queries or the composables from an API route? If so, how to achieve it.
Hello! Did you find a solution ?
@plcdnl it is.
for example if you have:
./queries/ships.gql:
query ships($limit: Int = 5) {
ships(limit: $limit) {
id
name
}
}
you'll then be able to execute it as seen here (./server/api/demo.get.ts):
export default eventHandler(async () => {
const data = await GqlShips()
return data
})
however, note that there's currently an issue with the types returned on the server side (looking to have it fixed this weekend)
Oh so fast, thank you. It's perfect!
Hey @Diizzayy I'm in need of the server side type safety for a project i'm working on currently. Commenting for visibility for the incoming fix mentioned.
Hi @Diizzayy is there any update on this?