Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration from apollo:codegen to typescript-operations #6344

Closed
Nicoowr opened this issue Jul 19, 2021 · 4 comments
Closed

Migration from apollo:codegen to typescript-operations #6344

Nicoowr opened this issue Jul 19, 2021 · 4 comments

Comments

@Nicoowr
Copy link

Nicoowr commented Jul 19, 2021

Is your feature request related to a problem? Please describe.

We are generating types from graphql operations with apollo:codegen, but we'd like to migrate to graphql-codegen. However, the structure of generated types is very different between both, which would require a big change in our codebase if we wanted to migrate. For instance:

  • All the types are generated in one single file in graphql-codegen, instead of multiple files in apollo:codegen
  • Here is the shape of types generated by apollo:
export interface findTrades_findTrades {
  foo: findTrades_findTrades_foo | null;
}

export interface findTrades {
  findTrades: findTrades_findTrades[];
}

export interface findTradesVariables {
  ids: string[];
}
  • Here is the shape of those generated by graphql-codegen:
export type FindTradesQueryVariables = Exact<{
  ids: Array<Scalars['ID']> | Scalars['ID'];
}>;


export type FindTradesQuery = (
  { __typename?: 'Query' }
  & { findTrades: Array<(
    { __typename?: 'Proposition' }
    & { foo?: Maybe<(
      { __typename?: 'Foo' }
      & Pick<Foo, 'id'>
    )> }
  )> }
);

Another thing to note is that it's possible to use subtypes in those generated by apollo.

Describe the solution you'd like
I'd like to be able to reproduce the shape of generated types in apollo:codegen with graphql-codegen.

Describe alternatives you've considered
Refactor my whole codebase, but it'd be awesome if there was an alternative...

In any case, thanks for your awesome tool !!

@ivansky
Copy link

ivansky commented Jul 20, 2021

@Nicoowr
We also had an experience with migrating from apollo codegen.
Unfortunately there is no way to make the same structure.
You need to use fragments to achieve similar effect and generate types subset.

@Nicoowr
Copy link
Author

Nicoowr commented Jul 20, 2021

I see, then is there any way to generate one file per operation? I checked the near-operation-file plugin but I'd like to have them all in the same folder.

@dotansimha
Copy link
Owner

GraphQL Codegen and Apollo Codegen have different goals. While GraphQL Codegen plugins aim to generate output that could work with any client/server, the Apollo Codegen is specific to the Apollo ecosystem and their client.

We are not generating sub-types for each selection set (we had that in older versions, and it caused conflicts and types bloat). In specific cases where you with to get sub-types, you can use GraphQL fragments, and codegen will generate a type for each fragment.

Also, you can use this as a comparison / migration guide: apollographql/apollo-tooling#2053

@Nicoowr
Copy link
Author

Nicoowr commented Jul 20, 2021

Very clear, thanks for your insight!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants