Closed hexdecimal16 closed 1 week ago
What do you mean by "flag" and could you elaborate a bit more and even share some examples?
Example: schema
type User {
id: String!
username: String!
balance: Float!
amountAdded: Float!
}
type Query {
"""Returns all users"""
user(): [User]
}
query
const GET_USERS = gql`query User {
user {
username
}
}`
Now suppose I rename username to name on my backend. How will frontend know that this query is wrong now? There should be some flag that can warn or throw error while building/compilation.
Ideally, there should be an option to pass my schema that can be used to resolve query/mutations while compilation. This will help to catch errors ahead of time. This option could be enabled on development.
I use apollo-server-express for my backend and they have an option to automatically generate schema whenever server gets started. @kamilkisiela
There are tools for that, like GraphQL Inspector to validate documents against the schema or GraphQL Code Generator to generate TypeScript types and interfaces. https://www.the-guild.dev/blog/graphql-with-typescript-done-right
There are tools for that, like GraphQL Inspector to validate documents against the schema or GraphQL Code Generator to generate TypeScript types and interfaces. https://www.the-guild.dev/blog/graphql-with-typescript-done-right
I think it will be more beneficial if we have it in the client instead of adding more 3rd party dependency in the project
The modern solution is to use https://the-guild.dev/graphql/codegen
Thanks @PowerKiKi will look into this
How can I flag incorrect queries and mutations during compilation?
Since query and mutation are essentially strings how safe are they to use, because and change in schema can't be refected clearly on those queries.