If you are coming from the world of relational databases, this might seem like it should be trivial. In the world of DynamoDB it is more complex. You cannot create a @key that is linked to a @connection ( as far as I understand ). Some solutions to this problem:
1: Add Author's Name to Book
The author's name doesn't change typically, so you could do the below. Duplicating data is not frowned upon in DynamoDB/NoSQL world. This will give you a faster query as well.
type Book
@model(subscriptions: null)
@key(name: "BooksByAuthorName", fields: ["authorName"], queryField: "getBooksByAuthorName")
{
id: ID!
title: String!
description: String!
image: String!
age: Int!
region: String!
isbn: String
narrator: String
status : Boolean!
createdAt: String!
isDeleted: Int!
book: String!
bookType: BookType!
authorId: ID!
authorName: String
authors: Author @connection(fields: ["authorId"])
}
2: Custom Resolvers
Custom resolvers, like @function ( Lambda functions ), or the more complex custom resolver templates can be used for multiple searches, and custom logic, though I would suggest option 1 first.
3: Exploring @searchable directive
See this for more info
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…