amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Expected scalar and got X

Open sprucify opened this issue 7 years ago • 7 comments

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 avatar Jun 19 '19 17:06 sprucify

@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.

mikeparisstuff avatar Jun 20 '19 17:06 mikeparisstuff

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 }

luizdanieldesouza avatar Jun 22 '19 01:06 luizdanieldesouza

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: *)

sprucify avatar Jun 22 '19 15:06 sprucify

I created a new issue for this #1714

sprucify avatar Jun 23 '19 19:06 sprucify

@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.

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?

avlonder avatar Jun 10 '20 10:06 avlonder

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.

djsmedes avatar Jul 26 '20 00:07 djsmedes

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 *-help channels for those types of questions.

github-actions[bot] avatar May 26 '21 01:05 github-actions[bot]