CreateBooking GraphQL Fields

For users to book a listing in our app, we'll need functionality to handle this as well as the capability to process transactions between the tenant and host. In this lesson, we'll establish the GraphQL fields in our API that will help achieve this.

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL - Part Two course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL - Part Two, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL - Part Two

In order for users to book a listing in our app, we'll need some kind of functionality to handle this as well as the capability to process transactions between the tenant and host and for us to collect a platform fee. Remember, if we recall, we've mentioned that when a booking is made, the tenant or that is to say the person making the booking will pay the host, that is to say the person who owns the listing a set price. We, Tinyhouse, will take a small percentage of the payment as a platform fee. Let's brainstorm what GraphQL fields we'll need to accomplish this. All we'll need for this is a single root level mutation called Create Booking. On the client, when the tenant picks the dates of when the booking should be made, provides their payment information and finally confirms their booking, this Create Book ing mutation will be fired which facilitates that the booking has been made. Fairly straightforward, however, we'll need to handle a few things within this mutation, such as recognizing the dates in which the tenant is picked for their booking and facilitating a stripe charge from the tenant to the host. We'll handle this step by step. In this lesson, we'll set up the GraphQL mutation field before we finalize the implementation in the next lesson or so. In our GraphQL type definitions, we'll create a new field in the root mutation object called Create Booking. And just for now, we'll have it return a string when resolved successfully. Now as a fun fact, this is the last mutation and the last root level GraphQL field we'll be creating for a wrap. Now since this mutation falls within the domains of bookings, we'll head over to the booking resolvers map we have and look to create the mutation resolver function. In the map, we'll first create the mutation object and within, we'll create the resolver function. For now, we'll simply have it return a string that says mutation.create booking . With our server project running, we'll head to GraphQL playground and attempt to run the create booking mutation. When run, it gives us the value we expect, a string that says mutation.create booking. Great. In the next coming lessons, we'll see how we can use stripes API to create a stripe charge as well as how we can build out the create booking mutation function. [BLANK_AUDIO]