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

Suffix of generated types should maybe be "Result" instead of "Query" #315

Closed
jonaskello opened this issue Dec 11, 2017 · 13 comments
Closed

Comments

@jonaskello
Copy link
Contributor

Today the types that are generated are named GetFooQuery. Becuase of this naming convention, it is quite easy for someone to assume that that type represents the actual query. But in reality it represents the result/reponse that the query will generate. If the types instead were named GetFooResult or something similar it might be easier to understand what the type represents. Or perhaps make it possible for the user to decide the suffix (perhaps it already is but I have not found that option).

The generation examples now state:

apollo-codegen generate **/*.graphql --schema schema.json --target typescript --output operation-result-types.ts

Which is good becuase the file name operation-result-types.ts communicates what the generated types represents. If the type names did the same I think it would clear up some confusion.

@martijnwalraven
Copy link
Contributor

Yeah, that's fair. On iOS, we generate actual query classes as GetFooQuery, and then a nested Data struct for the data part of the result. The whole result is represented as GraphQLResult<Data>, which has both data and errors.

We probably want to think about this in the context of #308, which is about generating query classes for TypeScript or Flow as well.

@alamothe
Copy link

alamothe commented Apr 7, 2018

It should probably be GetFooQueryResult

GetFooQuery definitely collides with the actual query (gql or graphql definition)

@alamothe
Copy link

alamothe commented Apr 7, 2018

...It would be great to come up with a convention and settle on naming scheme.

For example, typescript-modern does not append Query/Mutation anymore, so it's incompatible with typescript 😞

@jonaskello
Copy link
Contributor Author

jonaskello commented Apr 8, 2018

I think either a suffix of Response or Result would be appropriate. And I tend to agree with Result being the best choice.

@nilshartmann
Copy link
Contributor

I also think Result is a good idea. A "larger" solution might be adding some configuration options.

@nilshartmann
Copy link
Contributor

Any chance this will be implemented? If your interested, I could try to help implementing...

@nilshartmann
Copy link
Contributor

ICYI: I've written a little codemod script that renames the generated types after they have been generated by apollo-codegen (as workaround until this problem gets solved in apollo-codegen)

You can find the transform script here: https://gist.github.com/nilshartmann/39e6dc755c91a60c1dc1911180e154b5

@jardakotesovec
Copy link

As @alamothe mentioned, suffixes disappeared with 0.20 version, which is breaking change and was not mentioned/explained in CHANGELOG.. so I am confused about the intentions behind it. I personally liked the suffixes.. so would at least appreciate explanation for this change.

@kgtkr
Copy link

kgtkr commented Aug 13, 2018

import { myQuery } from "./my-query.gql";
import { myQuery } from "./__generated__/myQuery";

Names conflict

@brabeji
Copy link
Contributor

brabeji commented Nov 27, 2018

@jbaxleyiii since this issue have been closed, is there any official resolution to this problem? The generated name conflicts with my query UserDetailManageScreenQuery component. Why not UserDetailManageScreenQueryData in a same way as UserDetailManageScreenQueryVariables are suffixed?

@wolthers
Copy link

wolthers commented Feb 8, 2019

Any resolution to this?

@PowerKiKi
Copy link

PowerKiKi commented Mar 30, 2019

@lewisf you contributed #304 a while ago, which I believe was when the suffix Query was removed from generated types in Typescript. Could you please explain why it was decided to drop the suffix Query ? was the risk of collision considered during that decision ? And was Result, instead of Query, ever considered ?

AFAIK it is possible to have a GraphQL schema that include a query and a mutation with the same name. In this case codegen would probably generate invalid code with duplicated identifiers.

@philipjscott
Copy link

Is there any news on this? A suffix option would be great

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