apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.87k stars 717 forks source link

Is there customTypeMapping in apollo-codegen-config.json #3307

Closed harish-suthar closed 9 months ago

harish-suthar commented 9 months ago

Question

Is there customTypeMapping in apollo-codegen-config.json something similar to apollo-kotlin?

calvincestari commented 9 months ago

Hi @harish-suthar. Yes we do support Custom Scalars, you can find the documentation for it here.

harish-suthar commented 9 months ago

@calvincestari I saw the document and it states "Because custom scalar files are only generated once, they can then be edited, and your changes will never be overwritten by subsequent code generation execution."

Which means one have to manually edit file once but the question I asked is a kind of option where one can declare and then no need to edit the generated code.

calvincestari commented 9 months ago

Which means one have to manually edit file once but the question I asked is a kind of option where one can declare and then no need to edit the generated code.

The answer is in the name of the feature - "Custom" Scalars. This means it's a completely custom type that Apollo iOS does not have any knowledge of and you need to write the customized logic to handle transformation of the type and it's format.

The documentation also states that "By default, each custom scalar is treated as a Swift String". If all you want is a custom type name but it's OK for it to be a Swift String type then you don't need to write any custom logic. However, if your custom scalar type is anything like the GeoPoint example then you must write the logic yourself, this is why codegen does not overwrite the file.