fabien0102 / gatsby-starter

Gatsby 2.0 starter with typescript and many cools dev tools
386 stars 99 forks source link

[idea] you could use apollo-cli to generate interfaces for graphql queries #70

Open jeffwillette opened 6 years ago

jeffwillette commented 6 years ago

I am just getting started with converting my gatsby site to typescript and it looks like apollo-cli can generate all the interfaces for the page queries so you don't have to type out the interfaces yourself.

I had success with the following commands

apollo schema:download --endpoint https://localhost:8000/___graphql gatsby-schema.json
apollo codegen:generate --tagName=graphql --queries=./src/pages/**/* --schema=./gatsby-schema.json gatsby-queries.d.ts
fabien0102 commented 6 years ago

@deltaskelta Great idea! But it's already there ^^ https://github.com/fabien0102/gatsby-starter/blob/master/package.json#L20 it's done by gql-gen, can you tell me if it respond to your need? I don't know if the apollo-cli is better (it was not existing when I made this starter ;) )

jeffwillette commented 6 years ago

I believe the only difference in apollo is that is actually parses the graphql tags in your files so you get interfaces for your component queries and not just the whole API. This way you wouldn't have to assemble an interface to match the query in every component file.

fabien0102 commented 6 years ago

It can be a good improvement! I really need to test by myself 👍

If you want to add this command to the starter and replace the actual gql-gen with apollo-cli, I will review/accept your PR with pleasure :wink:

jeffwillette commented 6 years ago

I'd be happy to add it, but it seems there is a current problem with typescript in gatsby that is affecting this. I'll have to wait until I can find a way around that and then I'll add the commands. Here is the issue https://github.com/gatsbyjs/gatsby/issues/5789