Why are fields on QueryResolver optional?
See original GitHub issueHello,
I’m generating resolvers using resolvers template
gql-gen --template graphql-codegen-typescript-resolvers-template --config gql-gen.json --out __generated/resolver-types.ts -s src/graph-api/schema.graphql
(using no-namespaces version for babel-typescript)
Here’s my query type:
type Query {
users: [User!]!
}
Here’s my query resolver type:
export interface QueryResolvers<Context = RequestContext, TypeParent = never> {
users?: QueryUsersResolver<User[], TypeParent, Context>;
}
Here’s how I use it:
export const Query: QueryResolvers = {
users: async (_parent, _args, ctx) => ctx.db.users()
};
Why is users
field optional? The result of users
query can’t be null.
Am I missing something? If there’s a reason for it to be optional, can we get an option to make it required?
I’d like to be notified by typescript if I don’t implement a resolver that is required in my schema. Would be very helpful.
Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Resolvers - Apollo GraphQL Docs
A resolver is a function that's responsible for populating the data for a single field in your schema. It can populate that data...
Read more >Resolvers – GraphQL Tools
To respond to queries, a schema needs to have resolvers for all fields. Resolvers are per field functions that are given a parent...
Read more >In GraphQL, how do I implement optional queries?
GraphQL APIs are organized in terms of types and fields, I recommend creating separate queries for User types and Club types, if someone...
Read more >GraphQL Resolvers: Best Practices | by Mark Stuart
Root Query fields, like user and album, are executed in parallel but ... We will test out the first option: adding it to...
Read more >Arguments
field :search_posts, [PostType], null: false do argument :category, ... are optional and the query does not provide any arguments, then the resolver method ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a small note, there’s a built-in
Required<T>
type:I would prefer if it would be required by default and if you want to split it into modules, you use the already existing Partial type. Guess that’s just personal preference. Anyways, thank you for your answer! 😃