'Sorting AWS AppSync 'GraphQL' connected queries (nesting sorting?)
I am Using AWS AppSync for my react native application and can't seem to figure out how to get sort inside of a query (nested queries/sorting?). Not sure what the proper terminology would be but here are my graphQL models, each month can contain many monthsPhotos:
type Month
@model
@auth(rules: [{ allow: owner, operations: [read, create, delete, update] }]) {
id: ID!
name: String!
owner: String!
monthsphotos: [MonthPhoto] @hasMany
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
sorttype: String!
@index(
name: "monthsByDateTime"
queryField: "monthsByDateTime"
sortKeyFields: ["createdAt"]
)
}
type MonthPhoto
@model
@auth(rules: [{ allow: owner, operations: [read, create, delete, update] }]) {
id: ID!
month: Month @belongsTo
thumbnail: String
owner: String!
caption: String
location: String
date: String
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
monthMonthsphotosId: ID!
@index(
name: "monthPhotosByDateTime"
queryField: "monthPhotosByDateTime"
sortKeyFields: ["createdAt"]
)
file: S3Object
}
my query for my months looks like this:
export const monthsByDateTime = /* GraphQL */ `
query MonthsByDateTime(
$sorttype: String!
$createdAt: ModelStringKeyConditionInput
$sortDirection: ModelSortDirection
$filter: ModelMonthFilterInput
$limit: Int
$nextToken: String
) {
monthsByDateTime(
sorttype: $sorttype
createdAt: $createdAt
sortDirection: $sortDirection
filter: $filter
limit: $limit
nextToken: $nextToken
) {
items {
id
name
monthsphotos {
items {
file {
bucket
region
key
}
createdAt
caption
date
location
}
}
}
}
}
`;
This lets me sort my months data by the date and time is was created. Ultimately I want a query that sorts all the months, and also sorts all the monthsPhotos within those months in 1 query. How would I go about doing this? Below is another query I made to sort monthsPhotos alone, I have not figured out how to connect these two into one:
export const monthPhotosByDateTime = /* GraphQL */ `
query MonthPhotosByDateTime(
$monthMonthsphotosId: ID!
$createdAt: ModelStringKeyConditionInput
$sortDirection: ModelSortDirection
$filter: ModelMonthPhotoFilterInput
$limit: Int
$nextToken: String
) {
monthPhotosByDateTime(
monthMonthsphotosId: $monthMonthsphotosId
createdAt: $createdAt
sortDirection: $sortDirection
filter: $filter
limit: $limit
nextToken: $nextToken
) {
items {
id
file {
bucket
region
key
}
caption
location
date
createdAt
monthMonthsphotosId
}
nextToken
}
}
`;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
