nuxt-graphql-client icon indicating copy to clipboard operation
nuxt-graphql-client copied to clipboard

Question: is it possible to run queries from the server?

Open sdegetaus opened this issue 7 months ago • 5 comments

Just like the title says, is it possible to run queries or the composables from an API route? If so, how to achieve it.

sdegetaus avatar May 14 '25 14:05 sdegetaus

Hello! Did you find a solution ?

plcdnl avatar Jul 12 '25 13:07 plcdnl

@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)

Diizzayy avatar Jul 12 '25 13:07 Diizzayy

Oh so fast, thank you. It's perfect!

plcdnl avatar Jul 12 '25 13:07 plcdnl

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.

Saganic avatar Jul 16 '25 07:07 Saganic

Hi @Diizzayy is there any update on this?

Saganic avatar Aug 12 '25 09:08 Saganic