graphqlamazon-dynamodbaws-amplifyaws-appsync

AWS Amplify - Choosing Attributes to Project on GSI in Schema


I am using Amplify with AppSync and DynamoDB. I have the following schema.graphql currently, with a GSI on the attribute itemType as partition key and companyName as sort key.

input AMPLIFY {
  globalAuthRule: AuthRule = { allow: public }
}
type Item
  @model
   @auth(
    rules: [
      { allow: owner, ownerField: "sub", operations: [create, update, delete] }
      { allow: private, operations: [read] }
      { allow: public, operations: [read] }
    ]
  ) {
  pk: String! @primaryKey(sortKeyFields: ["sk"])
  sk: String!
  companyName: String
  itemType: String
    @index(
      name: "companyList"
      sortKeyFields: ["companyName"]
      queryField: "listCompanies"
    )
  otherAttributeOne: String
  otherAttributeTwo: String
  otherAttributeThree: String
}

I want to choose the items to be projected on the GSI but don't know how. I dont want to be manually changing resolvers or adding it via the console.

If however it is not possible and must be done through the console, does it need to be manually added for each environment (e.g. dev and prod)?


Solution

  • I solved it by creating the GSI in the console, and then added to my schema with @index without needing to reference projected attributes.