-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@connect - one to many - nextToken usage #6886
Comments
hi @codeinaire - I'm having trouble fully understanding the issue. Can you share more of your query itself? A sample schema & query would add sufficient context. Here's just some additional info on pagination: https://docs.amplify.aws/lib/graphqlapi/query-data/q/platform/js#paginating-queries |
This is the relevant part of the schema. type PageForms
@model
@auth(
rules: [
{ allow: private, operations: [update, read] }
{ allow: private, provider: iam, operations: [create, read, update] }
]
) {
id: ID!
pageId: String
mappingDatas: [MappingData]
@connection(keyName: "byPageForms", fields: ["id"], limit: 10)
}
type MappingData
@model
@auth(
rules: [
{ allow: private, operations: [update, read] }
{ allow: private, provider: iam, operations: [create, read, update] }
]
)
@key(
fields: ["archived", "formCreatedTime"]
name: "ByArchived"
queryField: "listMappingDataByArchived"
)
@key(
name: "ByFormIdAndArchive"
fields: ["formId", "archived", "formCreatedTime"]
queryField: "listFormsByPageIdAndArchive"
)
@key(name: "byPageForms", fields: ["pageFormsID", "formId"]) {
id: ID!
formName: String
formId: String
pageId: String
mappingInfo: MappingInfo
rawLeadFields: [RawLeadField]
status: Status
formCreatedTime: String
deliveryStatus: Int
errors: Int
campaignName: String
campaignId: String
archived: ArchivedStatus
pageFormsID: ID
leads: [Lead] @connection(keyName: "byMappingData", fields: ["id"])
} This is the relevant queries. let mappingDatas: any
const pageForms: any = await API.graphql(
graphqlOperation(listPageFormss, {
filter: {
pageId: {
eq: pageId
}
}
})
)
const pageForm: any = await API.graphql(
graphqlOperation(getPageForms, {
id: pageForms.data.listPageFormss.items[0].id
})
) This is the relevant result of pageForm {
...
pageId: 10
mappingDatas: {
items: Array(10) [ {…}, {…}, {…}, … ],
nextToken: "<a token>"
}
} I want to be able to get more of the mappingDatas by using I hope that clears it up. |
BTW @renebrandel the only reason I'm doing this is because of this issue. But if I can't do pagination with the p.s. I posted the issue I linked using my work github account. I should've posted this issue using the same account but forgot I was logged in on my personal account. |
Hi - can you share the |
Great! Here's the query: export const listPageFormss = /* GraphQL */ `
query ListPageFormss(
$filter: ModelPageFormsFilterInput
$limit: Int
$nextToken: String
) {
listPageFormss(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
pageId
createdAt
updatedAt
mappingDatas {
nextToken
}
}
nextToken
}
}
`; And, just in case, here's how it's used: const pageForms: any = await API.graphql(
graphqlOperation(listPageFormss, {
filter: {
pageId: {
eq: pageId
}
}
})
) |
@codeinaire the export const listPageFormss = /* GraphQL */ `
query ListPageFormss(
$filter: ModelPageFormsFilterInput
$limit: Int
$nextToken: String
$mappingDataNextToken: String
) {
listPageFormss(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
pageId
createdAt
updatedAt
mappingDatas (nextToken: $mappingDataNextToken){
items {
id
formName
formId
pageId
# Other fields that you're interested in
}
nextToken
}
}
nextToken
}
} When trying to get the next page of |
@yuth it appears to be working. Thanks for your help! BTW, is this anywhere in the docs? I couldn't find anything like this and not sure if it's not there or I just didn't look in the right places. |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Which Category is your question related to?
API GraphQL
Amplify CLI Version
You can use
amplify -v
to check the amplify cli version on your system4.45
What AWS Services are you utilizing?
Lambda, AppSync, Cloudfront, DynamoDB.
Provide additional details e.g. code snippets
I set up a one-to-many relationship between a couple of model. It works fine. I'm able to query for the one model record and from that get the many model records. However, I set a limit of 10 for the many model records but it's not obvious to me how to use the
nextToken
value to retrieve the other many model records.I've tried using the list query for the many model and the list query for the one model but I get the invalid start key error. How can I use the
nextToken
value to get the other many model records?The text was updated successfully, but these errors were encountered: