DEV Community

loading...
Microsoft Azure

Generating TypeScript Types From GraphQL Schemas

Aaron Powell
Hi, my name’s Aaron Powell and I’m a Cloud Developer Advocate (CDA) at Microsoft. My area of specialty is front-end web dev and .NET (especially F#), but I enjoy doing silly things with technology.
Originally published at aaron-powell.com on ・1 min read

Last week I did a live stream on creating a web app with React, TypeScript and GraphQL and there was a question that popped up on whether or not you could generate the TypeScript types from the GraphQL schema, as I was creating them by hand.

Today, I did a last-minute stream in which I showed how you could do it using GraphQL Code Generator. It was really simple to integrate and what's more, I found a problem in the types I had written by hand relative to the GraphQL schema, so it's a win-win. I even showed off how the pull request feature of Static Web Apps works.

Discussion (3)

Collapse
dan_piedra profile image
Daniel Piedra

Nice! Any experience with polymorphic models in the BE and graphql code generation?

Collapse
starpebble profile image
starpebble

Anything that brings code quality up is a plus.

Collapse
aaronpowell profile image
Aaron Powell Author

Exactly.

Also, it was funny that I'd stuffed up my hand-written types relative to the schema!