[typescript] Why is parent/args hardcoded as optional?
See original GitHub issueHi there, awesome project to make server-side graphql even more enjoyable.
I just generated some typescript typings
gql-gen --schema ./schema.js --template graphql-codegen-typescript-template --out ./typings/
It generated typings/types.ts as expected:
...
export type Resolver<Result, Parent = any, Context = any, Args = any> = (
parent?: Parent,
args?: Args,
context?: Context,
info?: GraphQLResolveInfo
) => Promise<Result> | Result;
...
“parent” and “args” are optional, this is hardcoded in:
AFAIK the “parent” field is only optional for root types Query/Mutation/Subscription.
The “args” field should only be optional if the corresponding graphql field arguments are optional.
Am I doing something wrong?
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Resolvers - Apollo GraphQL Docs
A resolver can optionally accept four positional arguments: (parent, args, contextValue, ... The following example defines a hardcoded data set, a schema, ...
Read more >how to use multiple optional arguments in typescript
I've been working in TypeScript for a while and completely skipped over the fact that they used Number , which would cause an...
Read more >Optional and default parameters in Typescript - YouTube
In this video, learn what is Optional and default parameter concept in typescript and how to use it.
Read more >Using hardcoded IP addresses is security-sensitive
TypeScript static code analysis. Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your TYPESCRIPT code.
Read more >Documentation - TypeScript 3.7
Optional Chaining · function makeRequest(url: string, log?: (msg: string) => void) { · log?.(`Request started at ${new Date().toISOString()}`); · // roughly ...
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
@dotansimha @ardatan @jzimmek
I would make them non optional, because in most cases they are. This will hurt a bit while unit testing:
But.
You can always wrap resolvers with this function in unit tests:
This will make all arguments optional and TS, that weird mad beast, won’t scream