♪♪ ♪♪ ♪♪ Hi, everybody. I'm Maxime Beunier. I'm a developer advocate at MongoDB, based in Paris. I'm super happy to be talking today at GraphQL Galaxy, and today I want to show you how to build serverless GraphQL API in less than seven minutes, so buckle up because it's going to be very, very quick.
So at the very beginning of COVID, everybody knows, it was like about two years ago, my idea was to start to build some charts and some APIs to show the data and make everybody aware and make the data available to everybody, so I ended up building a REST API, a GraphQL API, and some MongoDB Atlas charts, as you can see here, and you will find the links to all of that in the last slide of this presentation.
So, I was inspired by John Hopkins University and their charts, so they actually provide, in the term of use here, a GitHub repository. This repository, sorry, looks like this, it's just a very simple repository with some CSV files. As you can see in the time series folder, they provide actually five files, so the global one, which is like for all the countries, and some specific one for the US with more details for the US. The files look all the same, they look like this, so basically, you know, state, province, country, region, latitude, longitude, and one colon for each date, and so if you import those files into MongoDB using, for example, the mongoinport tool that supports CSV, you will end up with an absolute terrible schema, so you don't want to do that.
So instead, you want to, for example, work with dates like this instead of being a key. You want that to be a value and preferably a date, and also, you want to work with, like, geosystem data, for example, for the localization, so it's more well-supported in MongoDB charts, for example, and for, like, 2D indexes or these kind of things. So there's also another file called lookup table where you have more information about the countries, like, for example, the population and, you know, some country codes, et cetera. So I wanted also this in the mix, so I ended up doing some Python scripts, which is also available in one of the links, and in the end, I ended up with some documents like this, so where you have, like, for each country, so you have a bunch of fields, you know, to describe where the data is related to, one date, and the values for that particular date, right? So in the end, I have this, you know, one country, one place, one date for one particular date, and, you know, the numbers for that particular day.
So let's build a GraphQL API now built on this, so as you can see, I ended up with, like, those five collections here at the bottom, and I'm gonna work with the global one just to show you how to do that. So let's hack! So to do this, I'm moving now into MongoDB Atlas, which is where you can host your MongoDB databases in the cloud of your choice, and I have this cluster in production here called COVID-19. So I'm gonna move now to Realm, which is the place where you can build your application, your serverless application, that's gonna stay and, you know, live on top of your MongoDB Atlas cluster. I'm gonna create a new app that's one in production. As you can see, I'm gonna call this Galaxy, for example. I'm gonna link this to the actual cluster in production, and I'm gonna be deploying this in Ireland because I want this to be in Ireland because the cluster is also in Ireland, so like, they are both in the same location. So as you can see here, you have a bunch of options, and I have triggers, I have like a sync as well, if you want to sync data across mobile devices, for example, but I'm gonna stick with the GraphQL. I'm gonna click here on Generate Schema because GraphQL relies on schema, so I need to generate a schema which drove me back to rules. In rules, I can select my collection here, global. I can say that a user can read all data because I'm doing a public API here. Say configure. Yes, I want to save. Got it. I'm gonna generate schema. I'm gonna click here on Generate Schema just for the global collection, and I'm gonna say Generate Schema. So I have now a schema that has been generated. I see it's missing the state, so I can copy paste the country, for example, and I can also modify as I want the schema.