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

graphql response extensions #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
support 'extensions' field on query result model
a8t3r committed Jan 28, 2025
commit 821f141389ef9ac743598ea54795965d480288cd
Original file line number Diff line number Diff line change
@@ -437,6 +437,9 @@ internal fun generateDto(schema: KobbySchema, layout: KotlinLayout): List<FileSp
}
}

val argErrors = "errors" to LIST.parameterizedBy(dto.graphql.errorClass).nullable()
val extensions = "extensions" to MAP.parameterizedBy(STRING, ANY.nullable()).nullable()

// GraphQL Error
files += buildFile(dto.graphql.packageName, dto.graphql.errorName) {
buildClass(dto.graphql.errorName) {
@@ -460,16 +463,14 @@ internal fun generateDto(schema: KobbySchema, layout: KotlinLayout): List<FileSp
buildProperty("path", LIST.parameterizedBy(ANY).nullable()) {
jacksonIncludeNonEmpty()
}
buildProperty("extensions", MAP.parameterizedBy(STRING, ANY.nullable()).nullable()) {
buildProperty(extensions) {
jacksonIncludeNonEmpty()
}
}
}
}
}

val argErrors = "errors" to LIST.parameterizedBy(dto.graphql.errorClass).nullable()

// GraphQL Exception
files += buildFile(dto.graphql.packageName, dto.graphql.exceptionName) {
buildClass(dto.graphql.exceptionName) {
@@ -486,19 +487,30 @@ internal fun generateDto(schema: KobbySchema, layout: KotlinLayout): List<FileSp
}
}

fun TypeSpecBuilder.primaryConstructorProperties(className: ClassName) {
buildPrimaryConstructorProperties {
buildProperty("data", className.nullable()) {
jacksonIncludeNonAbsent()
}
buildProperty(argErrors) {
jacksonIncludeNonEmpty()
}
if (dto.serialization.enabled) {
buildProperty("extensions", SerializationJson.JSON_OBJECT.nullable())
} else {
buildProperty(extensions) {
jacksonIncludeNonEmpty()
}
}
}
}

// GraphQL QueryResult
files += buildFile(dto.graphql.packageName, dto.graphql.queryResultName) {
buildClass(dto.graphql.queryResultName) {
annotateSerializable()
addModifiers(KModifier.DATA)
buildPrimaryConstructorProperties {
buildProperty("data", schema.query.dtoClass.nullable()) {
jacksonIncludeNonAbsent()
}
buildProperty(argErrors) {
jacksonIncludeNonEmpty()
}
}
primaryConstructorProperties(schema.query.dtoClass)
}
}

@@ -507,14 +519,7 @@ internal fun generateDto(schema: KobbySchema, layout: KotlinLayout): List<FileSp
buildClass(dto.graphql.mutationResultName) {
annotateSerializable()
addModifiers(KModifier.DATA)
buildPrimaryConstructorProperties {
buildProperty("data", schema.mutation.dtoClass.nullable()) {
jacksonIncludeNonAbsent()
}
buildProperty(argErrors) {
jacksonIncludeNonEmpty()
}
}
primaryConstructorProperties(schema.mutation.dtoClass)
}
}

@@ -523,14 +528,7 @@ internal fun generateDto(schema: KobbySchema, layout: KotlinLayout): List<FileSp
buildClass(dto.graphql.subscriptionResultName) {
annotateSerializable()
addModifiers(KModifier.DATA)
buildPrimaryConstructorProperties {
buildProperty("data", schema.subscription.dtoClass.nullable()) {
jacksonIncludeNonAbsent()
}
buildProperty(argErrors) {
jacksonIncludeNonEmpty()
}
}
primaryConstructorProperties(schema.subscription.dtoClass)
}
}