apollographql / apollographql/apollo-tooling
Add Example of Using Query Types to Documentation
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 460
- PR merge metrics
- No merged PRs in 30d
Description
It was not immediately obvious to me how I should reference types generated by codegen throughout my application.
When creating multiple queries that access different fields on a schema type, this can cause issues for fields required on the schema type, but missing in the query.
The documentation loosely shows how to destructure a query result to use the inner objects, rather than using the schema type, such as:
```
function CharacterFigures({ characters }: CharactersQuery) {
...
}
```
Less obvious was how I might reference these inner types throughout my application, which I have now discovered can be achieved like so:
`type Character = CharactersQuery['characters'][0];`
It might make sense to have an explicit section in the documentation for working with these types.
While this was due to a lack of Typescript knowledge on my part, I still feel it would help others running into this issue in the future.
Contributor guide
Research direction
No documentation file or test is named in the issue. Locate the TypeScript code-generation documentation that currently shows destructuring a query result, then add an explicit example for referencing an inner generated type throughout an application. Done means the documentation explains the use case and includes the reported Character type pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100