menu

Apollo

A community of developers, designers and others who love Apollo and GraphQL. 🚀

Channels
# All channels
view-forward
# General
view-forward
# Apollo Angular
view-forward
# Announcements
view-forward
# Apollo Android
view-forward
# Apollo Client
view-forward
# Apollo iOS
view-forward
# Apollo Link
view-forward
# Apollo Link Rest
view-forward
# Local State
view-forward
# Apollo Studio
view-forward
# Apollo Server
view-forward
# Apollo Tooling
view-forward
# Contributing
view-forward
# Docs
view-forward
# Events
view-forward
# GraphQL Tools
view-forward
# Jobs
view-forward
# Random
view-forward
# React Apollo
view-forward
# Showcase
view-forward
# Subscriptions
view-forward
# Testing
view-forward
# Vue Apollo
view-forward
Team

Using codegen for types alongside vs code extension?

May 11, 2020 at 8:20am

Using codegen for types alongside vs code extension?

May 11, 2020 at 8:20am
I'm running into an issue that I feel like must have a reasonable solution I'm missing. I want to use the codegen tooling to get typescript types. I can execute this command to get this:
apollo codegen:generate --target typescript --excludes=node_modules/* --tagName=gql --outputFlat src/generated --includes=**/*.tsx --endpoint https://xxxxxxx/v1/graphql
This works, and I have my types which is great. But I also want IDE support for autocomplete when writing queries. For this, I'm using the vs code Apollo extension. I have it configured like this:
module.exports = {
client: {
service: {
name: "asset-store",
url: "https://xxxxxxx/v1/graphql"
}
}
};
It feels dirty specifying my endpoint twice, but that's another problem. This should work, but I get errors when loading the schema about my types being defined twice. I suspect the VS Code extension is generating and loading the types somewhere, and my Apollo CLI command is doing the same... Is there any workaround for this, or do I have to settle for either IDE support or types, but not both?

May 11, 2020 at 11:25am
Are you using graph manager? And do you have any client only schema? The plugin won’t generate types but it tries to shim in Client schema. You can use the “excludes:[file glob pattern]” option to ignore client schema.
  • reply
  • like

May 11, 2020 at 5:28pm
Good question, I'm actually just pointing this to a Hasura endpoint.
  • reply
  • like
Are you saying I could point the "excludes:[file glob pattern]" at my generated types folder and that should work?
  • reply
  • like
Where your client schema is defined (typedefs) is excluded for looking for types. in my case its in src/client folder excludes: ['./src/client/**/*'],
  • reply
  • like
did you get it working? I can report that the vscode plugin "just works" from codegen once everything is set up. I initially had an issue with double-included types as well, because I was also generating a local schema.json file. Once I realized that I didn't need that, everything worked great.
  • reply
  • like

May 12, 2020 at 4:11pm
actually I was totally wrong about this "just working", and this bit me today when another developer made a schema change, and my tooling couldn't tell me which queries were wrong :(
Did you ever get this working?
  • reply
  • like