我的graphql模式中有两个模型,我试图查询的一个模型Sessions有两个@belongsTo指令(在论坛上阅读这很重要(。我可以成功保存这些模型,并在AWS AppSync Queries选项卡上查看它们,在那里我可以成功查询getSessions,但当我尝试在本地按照这些文档进行完全相同的查询时:
(https://docs.amplify.aws/lib/graphqlapi/advanced-workflows/q/platform/flutter/#combining-多次操作(
我在本地得到一个错误:
type "Null" is not a subtype of type 'string'
我做错了什么?我该如何解决这个问题,以便成功检索我的嵌套查询:
以下是我的模型作为参考:
会话:
type Session
@model
@auth(
rules: [
{ allow: public }
{ allow: owner }
{ allow: groups, groups: ["Admin"] }
]
) {
id: ID!
name: String
numPeoplePresent: Int
notes: String
eIdReader: String
weighTiming: String
cows: [Cow] @manyToMany(relationName: "CowSession")
proceduresID: ID
procedures: Procedures @hasOne(fields: ["proceduresID"])
}
奶牛:
type Cow
@model
@auth(
rules: [
{ allow: public }
{ allow: owner }
{ allow: groups, groups: ["Admin"] }
]
) {
id: ID!
name: String!
RfId: String
weight: [Float!]!
temperament: [Int]
breed: String
type: String
dateOfBirth: AWSDate
sessions: [Session] @manyToMany(relationName: "CowSession")
procedures: [Procedures] @manyToMany(relationName: "CowProcedures")
}
这是导致错误的查询:
const getSession = 'getSession';
String graphQLDocument = '''query getSession($id: ID!) {
$getSession(id: $id) {
numPeoplePresent
notes
name
eIdReader
id
owner
proceduresID
updatedAt
weighTiming
cows {
items {
cow {
RfId
}
}
}
}
}''';
final getSessionRequest = GraphQLRequest<Session>(
document: graphQLDocument,
modelType: Session.classType,
variables: <String, String>{'id': sessID}, //parameter of the current session can hardcode to whatever you need here
decodePath: getSession,
);
final response =
await Amplify.API.query(request: getSessionRequest).response;
print('Response: ${response.data}');
放大器的优秀人员很快就回答了这个问题,所以我将在这里转发信息:
问题是中介id没有包括在我的本地查询中,所以它无法检索嵌套的Cows。更新后的查询如下:
getSession = 'getSession';
String graphQLDocument = '''query getSession($id: ID!) {
$getSession(id: $id) {
numPeoplePresent
notes
name
eIdReader
id
owner
proceduresID
updatedAt
weighTiming
cows {
items {
id <-- needed this one
cow {
id <-- and this id too
RfId
breed
dateOfBirth
name
type
weight
}
}
}
}
}''';