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.
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo 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 single-time purchase. Already have access to this course? Log in here.
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.
[00:00 - 00:24] 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.
[00:25 - 00:34] 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.
[00:35 - 00:55] 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.
[00:56 - 01:12] 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.
[01:13 - 01:28] 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.
[01:29 - 01:44] 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.
[01:45 - 02:11] 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.
[02:12 - 02:30] 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.
[02:31 - 02:38] When run, it gives us the value we expect, a string that says mutation.create booking. Great.
[02:39 - 02:48] 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.