我试图在Android/GraphQL上完成AWS教程,但失败得很惨。我的构建在以下命令中自动生成的一段代码上失败
amplify codegen models
用作源的模式是…
type NoteData
@model
@auth (rules: [ { allow: owner } ]) {
id: ID!
name: String!
description: String
image: String
}
生成的代码的失败部分是…
/** This is an auto generated class representing the NoteData type in your schema. */
@SuppressWarnings("all")
@ModelConfig(pluralName = "NoteData", authRules = {
@AuthRule(allow = AuthStrategy.OWNER, ownerField = "owner", identityClaim = "cognito:username", **provider** = "userPools", operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ })
})
public final class NoteData implements Model {
public static final QueryField ID = field("NoteData", "id");
public static final QueryField NAME = field("NoteData", "name");
public static final QueryField DESCRIPTION = field("NoteData", "description");
public static final QueryField IMAGE = field("NoteData", "image");
private final @ModelField(targetType="ID", isRequired = true) String id;
private final @ModelField(targetType="String", isRequired = true) String name;
private final @ModelField(targetType="String") String description;
private final @ModelField(targetType="String") String image;
private @ModelField(targetType="AWSDateTime", **isReadOnly** = true) Temporal.DateTime createdAt;
private @ModelField(targetType="AWSDateTime", **isReadOnly** = true) Temporal.DateTime updatedAt;
public String getId() {
return id;
}
我的生成错误是。。。
C:UsersyawbeAndroidStudioProjectsAndroidGettingStartedappsrcmainjavacomamplifyframeworkdatastoregeneratedmodelNoteData.java:25: error: cannot find symbol
@AuthRule(allow = AuthStrategy.OWNER, ownerField = "owner", identityClaim = "cognito:username", provider = "userPools", operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ })
^
symbol: method provider()
location: @interface AuthRule
C:UsersyawbeAndroidStudioProjectsAndroidGettingStartedappsrcmainjavacomamplifyframeworkdatastoregeneratedmodelNoteData.java:36: error: cannot find symbol
private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime createdAt;
^
symbol: method isReadOnly()
location: @interface ModelField
C:UsersyawbeAndroidStudioProjectsAndroidGettingStartedappsrcmainjavacomamplifyframeworkdatastoregeneratedmodelNoteData.java:37: error: cannot find symbol
private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime updatedAt;
^
symbol: method isReadOnly()
location: @interface ModelField
C:UsersyawbeAndroidStudioProjectsAndroidGettingStartedappsrcmainjavacomamplifyframeworkdatastoregeneratedmodelNoteData.java:28: error: method field in class QueryField cannot be applied to given types;
public static final QueryField ID = field("NoteData", "id");
^
required: String
found: String,String
reason: actual and formal argument lists differ in length
C:UsersyawbeAndroidStudioProjectsAndroidGettingStartedappsrcmainjavacomamplifyframeworkdatastoregeneratedmodelNoteData.java:29: error: method field in class QueryField cannot be applied to given types;
public static final QueryField NAME = field("NoteData", "name");
^
required: String
found: String,String
reason: actual and formal argument lists differ in length
C:UsersyawbeAndroidStudioProjectsAndroidGettingStartedappsrcmainjavacomamplifyframeworkdatastoregeneratedmodelNoteData.java:30: error: method field in class QueryField cannot be applied to given types;
public static final QueryField DESCRIPTION = field("NoteData", "description");
^
required: String
found: String,String
reason: actual and formal argument lists differ in length
C:UsersyawbeAndroidStudioProjectsAndroidGettingStartedappsrcmainjavacomamplifyframeworkdatastoregeneratedmodelNoteData.java:31: error: method field in class QueryField cannot be applied to given types;
public static final QueryField IMAGE = field("NoteData", "image");
^
required: String
found: String,String
reason: actual and formal argument lists differ in length
这看起来像是两个未定义的符号和四个变量数量错误的调用。对于后者,工具提示显示了以下用法,它确实需要一个参数。
public static QueryField field(String fieldName)
我不知道为什么自动生成的代码有两个,但如果我删除第一个参数,那么
field("NoteData", "image")
成为
field("image")
这真的会解决问题吗?还是只是在给我创建一整套新的运行时问题时对构建错误进行排序?
回到这两个未定义的符号,它们似乎没有缺少导入,而是定义和生成的代码之间不兼容。AuthRule的源代码没有定义提供者字段,所以这似乎是错误的一个明显原因,但我不明白的是,为什么放大会把它放在那里,以及需要什么来替换它(大概是什么?(。isReadOnly也是如此,它没有定义,所以为什么放大会尝试使用它?
希望有人能直截了当地告诉我,到目前为止,我基本上理解了所有其他代码,但正是这个放大生成的文件让我头疼。
如果对Gradle Library版本进行以下更改,则不会发生构建错误
implementation 'com.amplifyframework:aws-api:1.24.0'
implementation 'com.amplifyframework:aws-auth-cognito:1.24.0'