Module 8 Summary
This lesson is a summary of the work we've done in Module 8.0.
📝 This module's quiz can be found - here.
🗒️ Solutions for this module's quiz can be found - here.
In this module, we build the functionality to have the client be able to query for a list of listings.
Server Project#
src/graphql/typeDefs.ts
#
We created a single root-level listings
field that can be queried from the client to receive the information for a list of listings. The listing
query field returns a collection of listings that satisfies three input arguments:
limit
: The amount of listing objects to be returned for a single page.page
: The page (i.e. subset) of listing objects to be returned from the"listings"
collection.filter
: The filter (i.e. sort) to be applied to the list of listings returned.
type Query {
authUrl: String!
user(id: ID!): User!
listing(id: ID!): Listing!
listings(filter: ListingsFilter!, limit: Int!, page: Int!): Listings!
}
The ListingsFilter
Enum determines the different filter values that can be applied to the listings
query field. We've established two separate filter values:
PRICE_LOW_TO_HIGH
: To sort the listings from the lowest price to the highest price.PRICE_HIGH_TO_LOW
: To sort the listings from the highest price to the lowest price.
enum ListingsFilter {
PRICE_LOW_TO_HIGH
PRICE_HIGH_TO_LOW
}
src/graphql/resolvers/Listing/index.ts
#
In the listingResolvers
map in the src/graphql/resolvers/Listing/index.ts
file, we created the root-level query listings()
resolver function to find a paginated list of listings from the "listings"
collection based on the argument values provided.
listings: async (
_root: undefined,
{ filter, limit, page }: ListingsArgs,
{ db }: { db: Database }
): Promise<ListingsData> => {
try {
const data: ListingsData = {
total: 0,
result: []
};
This page is a preview of TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL - Part Two