gatsby-starter icon indicating copy to clipboard operation
gatsby-starter copied to clipboard

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

Open jeffwillette opened this issue 7 years ago • 4 comments

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

jeffwillette avatar Jul 02 '18 03:07 jeffwillette

@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 ;) )

fabien0102 avatar Jul 02 '18 14:07 fabien0102

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.

jeffwillette avatar Jul 02 '18 16:07 jeffwillette

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:

fabien0102 avatar Jul 02 '18 20:07 fabien0102

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

jeffwillette avatar Jul 03 '18 09:07 jeffwillette