apollo-kotlin
apollo-kotlin copied to clipboard
Dedicated apollo api for kotlin
Use case
In the kotlin server side
data class Category(
@BsonId
@BsonRepresentation(BsonType.OBJECT_ID)
override val id: String = newObjectIdString,
val code: String,
val name: String,
val description: String,
val tagging: Set<String> = emptySet(),
override val createdAt: LocalDateTime = LocalDateTime.now(),
override val updatedAt: LocalDateTime? = null,
override val isActive: Boolean = true,
override val isDeleted: Boolean = false
) : Entity
using apollo-api generated model,
- notice that there is a public keyword which is already the default for kotlin
- generated naming convention is bad, I expect it to be only
CategorynotGetCategory
@ApolloAdaptableWith(GetCategoriesQuery_ResponseAdapter.Data::class)
public data class Data(
/**
* Get all categories
*/
public val getCategories: List<GetCategory>,
) : Query.Data
public data class GetCategory(
public val id: String,
public val code: String,
public val name: String,
public val description: String,
public val tagging: List<String>,
public val createdAt: Any,
public val updatedAt: Any?,
public val isActive: Boolean,
public val isDeleted: Boolean,
)
Describe the solution you'd like
Or if possible to be generated same as Server side model
data class Category(
val id: String,
val code: String,
val name: String,
val description: String,
val tagging: Set<String> = emptySet(),
override val createdAt: LocalDateTime = LocalDateTime.now(),
override val updatedAt: LocalDateTime? = null,
override val isActive: Boolean = true,
override val isDeleted: Boolean = false
) : Entity
Hi 👋
Thanks for sending this.
there is a public keyword which is already the default for kotlin
This is the KotlinPoet default. See also https://github.com/square/kotlinpoet/issues/1001. We are aligned with this default and have no plans to change this.
If you want to remove the public keyword, you can do so using an Apollo Compiler Plugin. See kotlinOutputTransform.
generated naming convention is bad, I expect it to be only Category not GetCategory
This is weird. Can you share your GraphQL schema? From the looks of the generated code, I'm expecting something like this:
type Query {
getCategories: [Category]
}
If you change your GraphQL schema to
type Query {
categories: [Category]
}
it should use a better naming.
For more context there, the models are named from field names and not types because there can be 2 fields with the same type:
type Query {
# If we were to use Address for both those fields, we'd have a conflict.
homeAddress: Address
workAddress: Address
}
Hey @ronjunevaldoz anything else we can do to help here?
All goods on your side. I'll just check the compiler plugin for more custom data.
@ronjunevaldoz I'm closing this for now. Please feel free to leave a message if you need any help with the compiler plugins.
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better.