We have a Java Application and we are invoking Appsync/GraphQL for search Service. Appsync searches different systems based on the search criteria passed, consolidate the results(for matching records) and sends it back to our application. The response is a common JSON schema but fields varies based on the system the Search criteria has matched. There is a query parameter which specifically says which system to search and I know which fields I need to query and get back in the response.
I need suggestions on what is the best design pattern I can use in my java application to build fields dynamically that needs to be in the schema(as I know the target system and fields available at the system). I am planning to use a properties file and hold placeholders for each system and its corresponding fields(that I want in response) and pass this while building the query.
For example GraphQL schema is as below
BooksSchema {
bookDetails {
bookName
bookEdition
bookcolor
}
authorDetails {
authorName
authorAge
authorPublication
}
bookPrice {
totalCost
costExclVat
vatPercentage
costInOtherCountry
discount
}
}
}
}
Query fields should be like below when libraryName
is High Street London
as I know bookPrice
is not available at this library
query MyQuery {
searchBooks(bookSearchRules: {authorName: "Kipling", bookName: "Jungle Book", libraryName: "High Street London"}) {
... on BooksSchema {
bookDetails {
bookName
bookEdition
bookcolor
}
authorDetails {
authorName
authorAge
authorPublication
}
}
}
}
Query fields should be like below when libraryName
is High Street Reading
as I know authorDetails
is not available at this library
query MyQuery {
searchBooks(bookSearchRules: {authorName: "Kipling", bookName: "Jungle Book", libraryName: "High Street Reading"}) {
... on BooksSchema {
bookDetails {
bookName
bookEdition
bookcolor
}
bookPrice {
totalCost
costExclVat
vatPercentage
costInOtherCountry
discount
}
}
}
}