>> Hi everyone. Welcome to this special series introducing
Apollo Server and how you can host your GraphQL server in Azure.
My name is Michael Watson,
and I work at Apollo where I worked with
various organizations on their GraphQL projects.
In today's video, we're going to build out
a simple GraphQL schema that's going to be
hosted with Apollo Server that was built with TypeScript.
We're going to use this project as the base for
our entire series of what we're going
to be hosting inside of Azure.
Now, if you're not familiar with GraphQL,
there's a lot of resources online.
There is Apollo GraphQLs documentation,
there's other introduction videos to GraphQL on Channel 9,
and then there's also GraphQL.org where there's a lot of
information that you can further learn about GraphQL.
Now, let's jump on into it.
We're going to start with a simple array of books as
our data set that we're going to expose and our GraphQL server.
The first thing we're going to need to do is install
the relevant GraphQL on Apollo Server packages.
The Apollo Server package is
just a GraphQL spec compliant library that
allows us to host our schema and build
out that server using JavaScript or TypeScript.
We'll need to import our Apollo Server in GQL tag.
The GQL tag is actually what we're going to
use to define out our schema.
Now, we need to define out our book type,
which from our data we just have a simple title,
that's a string and then the author, that's a string.
Now that we've defined our book,
we need to find what is able to be
queryable in our GraphQL server.
From that, we have a query root type.
This is going to be where we can define what
can be queried inside of our GraphQL server.
So for example, here,
we're just going to allow everyone to look at all the books.
That's just going to return an array of that book type.
Now that we've defined out our schema,
we need to just find out a set of resolvers that's going to
resolve the data for those fields and types in our schema.
So for that, we're going to have
our route query level type in our resolver.
For that, we have our books field.
We're just going to want that to resolve to that array of books.
Now that we've defined out our schema and our resolvers,
we just need to provide that to our server.
Oh, make sure you spell things right.
By default, Apollo Server is going to listen on Port 4000.
Now as best-practice, I always like to make sure that I set up
my launch configuration for
debugging right from the get-go in the project.
This just makes it a lot easier for me to develop
my GraphQL server and do things
like set some breakpoints in my resolvers.
Now, let's go look at our server running locally.
Apollo Server ships with GraphQL playground as the default.
You might have noticed graphical used in some of
the Intro to GraphQL videos on Channel 9.
This is also an option that you can bake into your GraphQL server.
The idea is the same.
We want to be able to explore into our schema.
What is available for us to query into,
and we want to be able to write out
a query and execute that query.
Since we have that breakpoint set,
you can see that we're unable to debug and start using all
of the great things inside of
VS Code to build out our GraphQL server.
Now that we've created our simple GraphQL service,
stay tuned for our next video where
we'll take this project and we'll upload it into
an Azure App Service using VS Code and
the VS Code App Service extension. Talk to you soon.