In AWS Amplify+ Appsync, using @connection to generate connection between tables is very easy. A simple example of this is the following Task
table and related Comments
type Task @model{
id: ID!
createdAt: String
name: String
comments: [Comments] @connection(name:"TaskComments", sortField: "createdAt")
status: String
}
type Comments @model{
id: ID!
createdAt: String
task: Task @connection(name:"TaskComments", sortField: "createdAt")
taskId: String
}
and it even autogenerates the schema for you:
type Task {
id: ID!
createdAt: String
name: String
comments(limit: Int, nextToken: String): ModelCommentsConnection
Status: String
}
type Query {
///... other not-related queries omitted
getTask(id: ID!): Task
}
The problem is that the query only returns 10 items (Comments)
even when I have a lot more. (I can see the nextToken
in the response but that's a different story). I want to be able to return 20, 30 or more comments per initial load.
I tried to pass limit:1000
, but the query is ignoring it.
graphql(
gql(getTask),
{
options: ({match: {params: {id}}}) => ({
variables: {id, limit:1000},
fetchPolicy: 'cache-and-network',
}),
props: ({data: {getTask: task, loading}}) => ({
task,
loading,
}),
},
),
This is a very similar question to : AWS Amplify Graphql query on @connection
But in my case I'm using React + AWS Amplify.
Thanks a lot.
答案 0 :(得分:0)
Amplify为您生成的代码是一个起点。可能需要进行一些有限的编辑。
如果您要使用src / graphql / queries.js,会看到类似这样的内容吗?
query GetTasks(id:ID!, limit:Int) {
getTask(input: {id: $id}) {
id
createdAt
name
comments(limit: $limit) {
items {
id
}
}
status
}
}
如果在此查询定义中没有看到限制,则可能需要添加它。 (PS-我不确定我上面使用的语法是100%,但是希望这会为您指明正确的方向。)
答案 1 :(得分:0)
仅测试了以下代码,它似乎运行良好: 即可以添加$ {nextToken}以便能够迭代超过1000个限制。
query GetTasks(id:ID!, limit:Int) {
getTask(input: {id: $id}) {
id
createdAt
name
comments (limit: $limit nextToken: ${nextToken}) {
items {
id
}
}
status
} }