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

graphql composite key with no value in part of key throws error

Open frankclaassen opened this issue 6 years ago • 3 comments

Describe the bug I have the following schema:

type Student
  @model(subscriptions: null)
  @key(
    name: "byStudentName"
    fields: ["firstName", "middleName", "lastName", "birthDate"]
    queryField: "getStudentByName"
  )
  {
  id: ID!
  firstName: String!
  middleName: String
  lastName: String!
  gender: Gender!
  birthDate: AWSDate!
 }

When I try to run query getStudentByName with input { firstName: 'Emily', middleNameLastNameBirthDate: { eq: { middleName: "", lastName: 'Jacobs', birthDate: '2008-09-20' } } }

graphql throws error: 
 errorType: 'InvalidArgumentsError',
 errorInfo: null,
 locations: [Array],
 message: "When providing argument 'middleNameLastNameBirthDate.$operation.lastName' you must also provide 
 middleNameLastNameBirthDate.$operation.middleName'."

Amplify CLI Version 4.34.0

To Reproduce

  • use provided schema
  • try and run query

Expected behavior Expect no error to be thrown as having a middleName field with no value is valid data. DynamodDB creates the data with no middleName value but graphql transform is having an issue with generating the query

frankclaassen avatar Nov 26 '20 07:11 frankclaassen

Hi @frankclaassen as of now we don't support partial composite keys. Please refer to this issue for updates aws-amplify/amplify-category-api#262

ammarkarachi avatar Nov 27 '20 21:11 ammarkarachi

@ammarkarachi I see this as a critical design flaw in the amplify / appsync implementation as the current implementation does not cater for real world data. There are millions of people in the world with no middle name and for a system to enforce a value for something that does not exist is ridiculous and utterly poorly thought out. This seems like a very simple fix, if the supplied value is empty, then it will not cause any errors when constructing the composite key value. I can do this with my own code without issues, can't see why this cannot be fixed in appsync / amplify????????

frankclaassen avatar Nov 29 '20 10:11 frankclaassen

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 25 '21 13:05 github-actions[bot]