'Is there a way to override AppSync auto generated input types when using Amplify?

Let's say we have the following graphql schema

type Customer
  @model
  @auth(
    rules: [
      { allow: owner }
      { allow: groups, groups: ["Admin"] }
      { allow: public, provider: iam }
    ]
  ) {
  id: ID! @primaryKey
  owner: ID!
  customer_last_name: String
}

When pushing above schema to AppSync via AWS Amplify, the following is created in the autogenerated graphql schema.

type Query {
    getCustomer(id: ID!): Customer
        @aws_iam
@aws_cognito_user_pools
    listCustomers(
        id: ID,
        filter: ModelCustomerFilterInput,
        limit: Int,
        nextToken: String,
        sortDirection: ModelSortDirection
    ): ModelCustomerConnection
        @aws_iam
@aws_cognito_user_pools
}

Is it possible to pass and enforce a custom argument for the query input, such as getCustomer(id: ID!, owner:ID!): Customer instead of the autogenerated getCustomer(id: ID!): Customer ? This can be done by editing the autogenerated schema directly in the Appsync console, but in the case of a new Amplify push, the changes will be lost.



Solution 1:[1]

There can be only one Hash Key(aka Partition key or Primary Key) in dynamoDB. If you want multiple keys to be your Hash Key, you need to concatenate those keys into one Hash Key. The key pattern you want is called composite primary key.

For more information, https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey

For creating a composite key with amplify graphql schema, please check details on this link. (Assuming you are using amplify graphql transformer v1)

https://docs.amplify.aws/cli-legacy/graphql-transformer/key/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1