gpt4 book ai didi

kotlin - 将graphql枚举映射到kotlin枚举

转载 作者:行者123 更新时间:2023-12-03 14:32:30 24 4
gpt4 key购买 nike

我对Graphql和Kotlin还是很陌生,但是遇到了问题。我有一个称为成分的对象(kotlin中的数据类,在graphql中键入)。成分具有名称和ID(均包含字符串)以及纯素食和无麸质值(均属于枚举)。

我遇到的问题是,当我尝试创建具有突变的成分时,我得到的纯素食主义者和无麸质食物类型不匹配,它期望“type.Vegan”并找到“me.paxana.myapplication.models.Vegan”

这是我用来创建配料的功能。由于上面提到的类型不匹配,在该文件中下划线标有Ingredient.vegan和Ingredient.gf。

fun createIngredient(ingredient: Ingredient ) {
val createIngredientInput = CreateIngredientInput.builder().name(ingredient.name).vegan(ingredient.vegan).gf(ingredient.gf).build()
mAWSAppSyncClient!!.mutate(CreateIngredientMutation.builder().input(createIngredientInput).build())
.enqueue(mutationCallback)
}

这是成分数据类:
data class Ingredient(val id: String, val name: String, val vegan: Vegan = Vegan.UNKNOWN, val gf: GlutenFree = GlutenFree.UNKNOWN ) 

这是我的素食类(class)
enum class Vegan {
VEGAN, NONVEGAN, UNKNOWN
}

这是我的graphQL模式
input CreateIngredientInput {
name: String!
vegan: Vegan
gf: GlutenFree
}

input DeleteIngredientInput {
id: ID!
}

enum GlutenFree {
GLUTENFREE
CONTAINSGLUTEN
UNKNOWN
}

type Ingredient {
id: ID!
name: String!
vegan: Vegan
gf: GlutenFree
}

type IngredientConnection {
items: [Ingredient]
nextToken: String
}

input ModelBooleanFilterInput {
ne: Boolean
eq: Boolean
}

input ModelFloatFilterInput {
ne: Float
eq: Float
le: Float
lt: Float
ge: Float
gt: Float
contains: Float
notContains: Float
between: [Float]
}

input ModelIDFilterInput {
ne: ID
eq: ID
le: ID
lt: ID
ge: ID
gt: ID
contains: ID
notContains: ID
between: [ID]
beginsWith: ID
}

input ModelIntFilterInput {
ne: Int
eq: Int
le: Int
lt: Int
ge: Int
gt: Int
contains: Int
notContains: Int
between: [Int]
}

enum ModelSortDirection {
ASC
DESC
}

input ModelStringFilterInput {
ne: String
eq: String
le: String
lt: String
ge: String
gt: String
contains: String
notContains: String
between: [String]
beginsWith: String
}

type Mutation {
createIngredient(input: CreateIngredientInput!): Ingredient
updateIngredient(input: UpdateIngredientInput!): Ingredient
deleteIngredient(input: DeleteIngredientInput!): Ingredient
}

type Query {
getIngredient(id: ID!): Ingredient
listIngredients(filter: TableIngredientFilterInput, limit: Int, nextToken: String): IngredientConnection
}

type Subscription {
onCreateIngredient(
id: ID,
name: String,
vegan: Vegan,
gf: GlutenFree
): Ingredient
@aws_subscribe(mutations: ["createIngredient"])
onUpdateIngredient(
id: ID,
name: String,
vegan: Vegan,
gf: GlutenFree
): Ingredient
@aws_subscribe(mutations: ["updateIngredient"])
onDeleteIngredient(
id: ID,
name: String,
vegan: Vegan,
gf: GlutenFree
): Ingredient
@aws_subscribe(mutations: ["deleteIngredient"])
}

input TableBooleanFilterInput {
ne: Boolean
eq: Boolean
}

input TableFloatFilterInput {
ne: Float
eq: Float
le: Float
lt: Float
ge: Float
gt: Float
contains: Float
notContains: Float
between: [Float]
}

input TableIDFilterInput {
ne: ID
eq: ID
le: ID
lt: ID
ge: ID
gt: ID
contains: ID
notContains: ID
between: [ID]
beginsWith: ID
}

input TableIngredientFilterInput {
id: TableIDFilterInput
name: TableStringFilterInput
vegan: TableBooleanFilterInput
gf: TableBooleanFilterInput
}

input TableIntFilterInput {
ne: Int
eq: Int
le: Int
lt: Int
ge: Int
gt: Int
contains: Int
notContains: Int
between: [Int]
}

input TableStringFilterInput {
ne: String
eq: String
le: String
lt: String
ge: String
gt: String
contains: String
notContains: String
between: [String]
beginsWith: String
}

input UpdateIngredientInput {
id: ID!
name: String
vegan: Vegan
gf: GlutenFree
}

enum Vegan {
VEGAN
NONVEGAN
UNKNOWN
}

最佳答案

好的,所以在我的项目上运行amplify codegen之后,我有了可以使用的type.Vegan和type.GlutenFree枚举,因此我摆脱了本地的kotlin枚举,并设置了成分对象type.Vegan和type.GlutenFree的属性。

奇迹般有效。

关于kotlin - 将graphql枚举映射到kotlin枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55319629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com