0

I have a model for orders, I made an index that would let me query the orders based on what month and year they were created. Now that I am able to query those orders, I want to avoid unnecessary connection (order-vendor) queries every time I query using that month-year index since I only want the list of the orders' number and status. Is there a way that I can do that?

here is my schema:

type Vendor @model @searchable{
id: ID!
vendorName: String!
location: String!
telNo: String!
terms: String!
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
}

type PurchaseOrder @model @searchable
@key(name:"MonthYearCreatedAt" fields:["monthYear", "createdAt"] queryField: "purchaseOrderMonthCreatedAt")
{
id: ID!
purchaseOrderNo: String!
vendor: Vendor! @connection
orders:[String!]
totalPrice: Float!
requestedBy: String!
category: String
addNotes: String
status: Status!
monthYear: String!
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
}
Jtaw Cañada
  • 147
  • 1
  • 7

1 Answers1

1

You can do that by adapting your query

query getPurchases {
  purchaseOrderMonthCreatedAt(monthYear: ..., createdAt: ...) {
    items {
      totalPrice
    }
  }
}

vs

query getPurchases {
  purchaseOrderMonthCreatedAt(monthYear: ..., createdAt: ...) {
    items {
      vendor { vendorName }
      totalPrice
    }
  }
}

Using the second query will navigate the vendor connection.

Gerard Sans
  • 2,269
  • 1
  • 13
  • 13