Is there a way I can group my results based on a custom scalar?
type Group
@model
{
id: ID!
owner: String
groupname: String!
groupcode: String!
swipes: [Swipe] @connection(name: "GroupSwipes")
}
type Schedule
@model
@key(name: "ByGroup", fields: ["group"], queryField: "schedulesByGroup")
{
id: ID!
recipe: Recipe! @connection
group: Group!
cookdate: AWSDateTime
timestamp: AWSDateTime
}
What I like to query is "Give me all the schedules for group X"
But when I setup like the schema above I get an error saying: Expected scalar and got Group
@sprucify The @key directive can only create indexes on top of scalar fields. If you want to index such that you can lookup resources by the logical then you can add a field groupId: ID! and then index on that.
Thanks Mike. How can @key be applied to a '@connection' field. Example:
type Content @model
@key(name: "BySite", fields: ["site", "status"], queryField: "itemsBySite")
{
id: ID!
name: String!
site: Site! @connection(name: "SiteProjects")
status: Status!
}
enum Status {
ACTIVE
DELETED
}
I changed my structure as recommended, but this results in a rollback:
type Group
@model
{
id: ID!
owner: String
groupname: String!
groupcode: String!
swipes: [Swipe] @connection(name: "GroupSwipes")
}
type Schedule
@model
@key(name: "ByGroup", fields: ["groupId"], queryField: "schedulesByGroup")
{
id: ID!
recipe: Recipe! @connection
groupId: ID!
cookdate: AWSDateTime
timestamp: AWSDateTime
}
The error in the log:
One or more parameter values were invalid: Both ReadCapacityUnits and WriteCapacityUnits must be specified for index: ByGroup (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: *)
I created a new issue for this #1714
@sprucify The
@keydirective can only create indexes on top of scalar fields. If you want to index such that you can lookup resources by the logical then you can add a fieldgroupId: ID!and then index on that.
Is there a specific reason for this? Why, for example, can't we use @key(name: "byProductByStatus", fields: ["id", "status"]) where the status attribute is an enum instead of a scalar type?
Especially because you CAN use enums as part of composite sort keys by doing something like @key(name: "byProductByStatus", fields: ["id", "status", "createdAt"]). They're all just strings to Dynamo.
Most helpful comment
Is there a specific reason for this? Why, for example, can't we use @key(name: "byProductByStatus", fields: ["id", "status"]) where the status attribute is an enum instead of a scalar type?