apollo-ios icon indicating copy to clipboard operation
apollo-ios copied to clipboard

Add casing strategies for queries names and schema types

Open iDylanK opened this issue 2 years ago • 3 comments

Use case

When using the following conversion strategies:

 "conversionStrategies":  {
      "enumCases": "camelCase",
      "fieldAccessors": "camelCase"
}

all queries and types are generated using snake case.

Furthermore, because of this all mocks are also generated using snake case.

In our swift codebase, we don't want to have to use any snake case objects.

Describe the solution you'd like

No response

iDylanK avatar Aug 21 '23 09:08 iDylanK

It would be great if you could provide a sample of the generated code you are getting so we can make sure we're talking about the same things here.

We don't currently have a codegen feature to convert names of types. If the names of the types in your schema use snake_case, then it makes sense you are getting types with snake_case. This is definitely a reasonable feature request. Though it's not a high priority issue for us. If you would like to contribute a PR to add this functionality, we'd be happy to work with you and review it!

As for the queries themselves, I'm not quite sure what you're referring to currently. Our query names are generated based on the names of your query operations in your .graphql files. So you have complete control over the naming there.

AnthonyMDev avatar Aug 22 '23 18:08 AnthonyMDev

A codegen feature that convert names of types would indeed be useful to us.

Furthermore we would like to be able to convert the MockObjects to CamelCase. Our backend only supports snake_case. So we define our queries like this:

query getPlayedTrakcs (
    $id: String!
  ){
  playedTracks: played_tracks(
    id: $id
  ) {
     id
     name
  }
}

The Mock is generated as: played_track

iDylanK avatar Sep 30 '23 10:09 iDylanK

@iDylanK, the codegen engine is respecting the field alias name played_tracks to generate the model property name and corresponding type name. You could try using a value of camelCase for the options.conversionStrategies.fieldAccessors codegen configuration option. I believe it should work with the field alias and give you the camel case property name you want.

calvincestari avatar Oct 02 '23 17:10 calvincestari

I'm closing this issue due to inactivity. If this is still unresolved, feel free to provide more information and we can re-open this, or create a new issue.

AnthonyMDev avatar May 17 '24 17:05 AnthonyMDev

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.

github-actions[bot] avatar May 17 '24 17:05 github-actions[bot]