© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
N. BiswasPractical GraphQLhttps://doi.org/10.1007/978-1-4842-9621-9_2

2. Queries

Nabendu Biswas1  
(1)
Bhopal, India
 

In this chapter, we will start creating an e-commerce app and learn how to use GraphQL with it.

Setting Up the GraphQL Server

First, we will create an index.js file in our e-commerce app. Here, we import ApolloServer and gql first. With gql, we define the structure of the query. The query itself is given in resolvers.

After the resolvers, we create a server through an instance of ApolloServer, by passing typeDefs and resolvers. Lastly, we listen to this server on a predefined URL. See Listing 2-1.
const { ApolloServer, gql } = require("apollo-server"); ...

Get Practical GraphQL: Learning Full-Stack GraphQL Development with Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.