我对Graphql和Kotlin还是陌生的,但我遇到了问题。我有一个名为成分的对象(kotlin中的数据类,在graphql中键入)。成分具有一个名称和一个ID(均为字符串)以及一个纯素食和无麸质值(均为枚举)。
我遇到的问题是,当我尝试创建具有突变的成分时,我得到的纯素食主义者和无麸质食物类型不匹配,它期望“ type.Vegan”并找到“ me.paxana.myapplication.models” 。素食主义者”
这是我用来创建配料的功能。由于上述类型不匹配,在该文件中下划线标有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 )
这是我的素食主义者枚举课
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
}
答案 0 :(得分:1)
好吧,所以在我的项目上运行amplify codegen
之后,我有了一个type.Vegan和type.GlutenFree枚举可以使用,所以我摆脱了本地的kotlin枚举,并创建了成分对象类型的属性素食主义者,然后键入。GlutenFree。
像魅力一样工作。