Type safe queries #1066
Unanswered
marceloverdijk
asked this question in
Q&A
Replies: 1 comment
-
I would imagine the answer is "no" because Nexus is a server framework whereas you're asking for a client feature. Analyzing your query and generating types from those specific queries is something that some frameworks do, for example Relay. But that isn't really the goal of Nexus. Huge disclaimer: I'm not a Nexus maintainer, just a user. When I speak to the "goal" of Nexus, its just my personal impression |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using Nexus with Prisma plugin and it works well but I wonder if I'm using it the best way.
As Nexus generates the
schema.graphql
andnexus-typegen.ts
I'm using the latter in my Next.js project like:This works well as the I then have a typesafe query result that I can use like:
But of course this
Circuit
type has many more properties that I don't query above, but I could refer to without compile issues.So there is a bit of a mismatch between type safety and the actual data present in the objects.
Does Nexus support generating type safe types for concrete queries? That would be awesome.
--
My alternative is to use https://www.graphql-code-generator.com/ in combination with Nexus.
It support generating type safe types for queries in separate files.
This way I could still use Nexus, for mainly setting up the Schema itself and the resolving the actual data with Prisma, and GraphQL codegen to have full safe type queries.
In that case am I correct that I don't need the Nexus generated
schema.graphql
andnexus-typegen.ts
anymore, and could e.g. turn that off by settingshouldGenerateArtifacts
tofalse
?Beta Was this translation helpful? Give feedback.
All reactions