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

Can apollo codegen generate usable Typescript interfaces?

May 5, 2020 at 1:23pm

Can apollo codegen generate usable Typescript interfaces?

May 5, 2020 at 1:23pm (Edited 5 months ago)
I'm using the apollo CLI to generate typescript classes in a react app, however, in my opinion the interface names are too verbose and unusable in code.
For example, for the schema below,
type User {
id: ID!
firstName: String
lastName: String
}
type UsersConnection {
nodes: [User!]!
totalCount: Int
}
type Query {
users: UsersConnection!
}
And the query
query GetUsers {
users {
nodes {
id
firstName
lastName
}
totalCount
}
}
The generated typescript interface for the User type is GetUsers_users_nodes.
Is it possible to have the generated interface names match my graphql schema definition types?

May 11, 2020 at 5:40pm
For interfaces that I'm going to be referencing throughout my project, I create a nicely named type alias. Otherwise, if I'm just referencing it in a useQuery / useMutation, etc, I leave it as is.
  • reply
  • like