Download Practical GraphQL: Learning Full-Stack GraphQL Development with Projects 1st Edition Nabendu Biswas ebook All Chapters PDF
Download Practical GraphQL: Learning Full-Stack GraphQL Development with Projects 1st Edition Nabendu Biswas ebook All Chapters PDF
com
https://ebookmass.com/product/practical-graphql-learning-
full-stack-graphql-development-with-projects-1st-edition-
nabendu-biswas/
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmass.com/product/practical-matlab-deep-learning-a-
projects-based-approach-2nd-edition-michael-paluszek/
ebookmass.com
https://ebookmass.com/product/practical-rust-projects-second-edition-
shing-lyu/
ebookmass.com
With Full Malice Brenda Hill
https://ebookmass.com/product/with-full-malice-brenda-hill/
ebookmass.com
https://ebookmass.com/product/engineering-for-sustainable-development-
theory-and-practice-wahidul-k-biswas/
ebookmass.com
https://ebookmass.com/product/heartbeat-sensor-projects-with-
pulsesensor-prototyping-devices-with-biofeedback-1st-edition-yury-
gitman/
ebookmass.com
https://ebookmass.com/product/practical-machine-learning-on-
databricks-1st-edition-debu-sinha/
ebookmass.com
Practical
GraphQL
Learning Full-Stack GraphQL
Development with Projects
—
Nabendu Biswas
Practical GraphQL
Learning Full-Stack GraphQL
Development with Projects
Nabendu Biswas
Practical GraphQL: Learning Full-Stack GraphQL Development with
Projects
Nabendu Biswas
Bhopal, India
Introduction���������������������������������������������������������������������������������������xiii
v
Table of Contents
Adding Reviews����������������������������������������������������������������������������������������39
Adding Filtering����������������������������������������������������������������������������������������42
Filter by Average Rating���������������������������������������������������������������������������46
Summary��������������������������������������������������������������������������������������������������48
Chapter 3: Mutations��������������������������������������������������������������������������49
Creating Data�������������������������������������������������������������������������������������������49
Deleting Data��������������������������������������������������������������������������������������������57
Updating Data�������������������������������������������������������������������������������������������68
Summary��������������������������������������������������������������������������������������������������75
Chapter 4: Full-Stack GraphQL�����������������������������������������������������������77
The Setup�������������������������������������������������������������������������������������������������77
Create an Express Server�������������������������������������������������������������������������78
Set Up GraphQL����������������������������������������������������������������������������������������80
Client Queries�������������������������������������������������������������������������������������������82
Project Queries�����������������������������������������������������������������������������������������85
Cloud MongoDB����������������������������������������������������������������������������������������89
Mongoose Models and Fetching Data����������������������������������������������������100
Client Mutations�������������������������������������������������������������������������������������104
Project Mutations�����������������������������������������������������������������������������������107
Client with React������������������������������������������������������������������������������������114
Apollo Setup for the Client���������������������������������������������������������������������120
Adding the deleteClient and addClient Mutations����������������������������������125
Displaying Projects and the React Router����������������������������������������������133
vi
Table of Contents
vii
Table of Contents
Index�������������������������������������������������������������������������������������������������257
viii
About the Author
Nabendu Biswas is a full-stack JavaScript
developer and has been working in the IT
industry for the past 16 years for some of
world’s top development firms and investment
banks. He is a passionate tech blogger and
YouTuber and currently works as an Architect
in an IT firm. He is also the author of six Apress
books focusing on topics such as Gatsby,
MERN, TypeScript and React Firebase, all of
which can be found on Amazon.
ix
About the Technical Reviewer
Preethi Vasudev is an Oracle Certified Java
programmer with more than 20 years of
industry experience in investment banking,
healthcare, and other domains. She has a
master’s degree from Auburn University,
Alabama, and enjoys participating in coding
competitions.
xi
Introduction
GraphQL is revolutionizing how we develop and build websites. Seen
as an alternative to REST APIs, this query language has become popular
among developers and engineers who are looking for a query language
to help them quickly develop and deploy applications and features with
minimal fuss.
Starting with the basics, this book will teach you how to set up
GraphQL and key details regarding queries and mutations, before moving
on to more advanced, practical topics and projects.
You will gain a full understanding of the full web development
ecosystem from front end to back end, by learning to build React
applications using Prisma Apollo Client and MongoDB. Using a project-
based approach, this book will equip you with all the practical knowledge
needed to tackle full enterprise projects and turbocharge your skills and
projects.
xiii
CHAPTER 1
Getting Started
In this book, you will learn about GraphQL. GraphQL is a new way to
create APIs. Traditional APIs were created with REST. The problem with
REST is that even when you need a subset of data, the endpoint gives all
the data from the databases.
This is a waste of precious network resources. So, in this book, you will
learn all about GraphQL. Here, you will learn to create APIs in a new way
in NodeJS. You will also learn to connect them to the front end.
Initial Setup
In this first chapter, you will learn how to install GraphQL on your system.
Also, you will learn to add extensions for GraphQL on VS Code to help you
in the development process.
To start using GraphQL, you need to have NodeJS installed on
your system. You will be using VS Code in your project. After that, you
should also install an extension called GraphQL, which will be helpful in
highlighting GraphQL in VS Code (Figure 1-1).
2
Chapter 1 Getting Started
There are different ways to use graphql, and apollo is the most
popular one (Figure 1-2).
S
ummary
In this chapter, you installed the packages apollo-server and graphql
in your system, through the terminal. You installed the official GraphQL
extension in VS Code, which will help you in the development process.
In the next chapter, you will learn about queries in GraphQL, which are
similar to GET APIs in RESTful endpoints and are used to get the data from
the database.
3
CHAPTER 2
Queries
In this chapter, we will start creating an e-commerce app and learn how to
use GraphQL with it.
As the house door was closed and the door of the shed
stood open, Vinzi went to the hayrick. That no steps led up
to the little door was not surprising to Vinzi; he knew the
arrangement. The little shed did not rest on the ground but
stood firmly on four blocks, to keep the hay dry and
ventilated. As Vinzi knew, it was a case of clambering up to
the open door, which was so low a full-grown man had to
stoop to enter. Vinzi climbed up nimbly, and found a tall
man working inside.
"He can eat right away," said she. "Supper is just ready;
the smoke drove me from the hearth. I will serve it at once,
for we need not wait for the boys; they will soon be
coming."
Stepping into the house, she took off Vinzi's knapsack,
and the lad was soon comfortably seated at the table. As
they ate, all timidity vanished. He was ravenously hungry
for he had scarcely eaten on the journey. Somehow his
cousin must have guessed this, and long before his plate
was empty, had heaped it again. Vinzi thought he had never
eaten anything better than the steaming potatoes and the
lovely yellow cheese.
Now and again the wife would say, "Pour out some more
milk for the boy. He must be thirsty after all the wind and
dust on that long trip."
She bustled off, and her three sons soon followed, and
as Vinzi thought perhaps he could help, he would have gone
too. But his cousin beckoned him back, declaring his
knapsack had been enough of a load for that day; it was
none too light, and hanging it on his arm, they went out to
the hayrick.
When the last had been put in, his cousin said, "Now
we'll say good-night. Inside the door is a wooden bolt, just
like the one outside. With it fastened, you are sole master
of your castle."
"Yes, I'll call good and loud through the round air hole,"
promised Jos.
When they reached the house, the cousin and his wife
were still at the breakfast table. Both gave Vinzi a friendly
greeting, and Josepha set a large cup of coffee before him,
suggesting that he eat plenty of bread with it, for the fresh
mountain breeze would soon make him hungry.
Jos and Faz had all they could do to keep the cows on
the roadway and to urge them along, for fresh grass
tempted them now to one side, now to the other.
Russli ran eagerly ahead and soon turned off the road
across a pasture, until he reached a large bush whose
branches grew straight up into the air.
Vinzi looked around him. Here and there stood tall, dark
larches, through whose delicate branches one could glimpse
the blue of the heavens above. Beneath their feet stretched
the lovely green of the mountain pasture land, brightened
by the fiery red alpine roses which grew amongst the moss-
covered stones. A full mountain stream rushed along its
course, and the rocks that hindered its passage tossed it
high into snow white foam. So this was the pasture!
Vinzi now ran off to where the cows grazed and looked
about for his cousins. Across the road was a very large
treeless pasture in which browsed many cattle. A small
group of young herders were bending over a smoking spot
on the ground. Jos and Faz were among them, Vinzi saw
that. He called out to Jos with all his might, but in vain for
some time, but as soon as Jos heard him he came over to
him.
With flashing eyes the happy boy put the pipe to his
mouth and blew a high, piercing shriek. Russli himself was
frightened at it.
"Here, take it," said he. "This is yours; the others have
already taken theirs."
Taking the pipe from Faz, Vinzi said, "I will give it a trial
myself," and began to play a little tune.
"Vinzi, keep the little chap with you on the way home;
that will be helping us."
"Look there, the boys are coming with the cattle," said
the father before whose eyes Russli held the pipe. "Go and
show it to your mother. I'll soon come in."
"Are you awake again?" asked Faz who had done the
tugging, fully believing that Vinzi had fallen asleep in the
path.
And now to the house, with Faz in the lead. The mother
was waiting for them at the table, patiently enduring the
noise Russli was making with his pipe.
"Can you play 'I Sing to You with Heart and Mouth?'"
she asked.
Yes, Vinzi knew it well, and after seeking a little for the
right pitch, played with assurance. The mother sang well
and her husband joined in with a strong bass, and suddenly
Jos lifted his fine voice. Faz growled after his father, then
jumped to his mother's high notes, and Russli squeaked in
between. But the other voices were so strong, that these
false notes did not disturb the song. Mrs. Lesa was so
delighted that she begged for another song directly the first
was finished, and then another and another.
Lorenz had just stepped into the room where his wife
was setting the table for supper.
"The man from Leuk will not come today," said Lorenz.
"I suppose he will be here tomorrow, and we must make
him understand the joy Vinzi has brought us."
"Indeed so," his wife agreed. "I was just wondering why
they sent him up here. Certainly we would wish to keep
such a son at home. People do that sort of thing if a boy is
not as he should be, or if he has strange fancies which he
might lose among strangers. But Vinzi is an exceptional boy.
Since he has been in our home, I scarcely know my own
boys. There is Russli, for instance. He had to be dragged to
the pump every morning and while he was being washed,
he would scream and fight for dear life. Now as soon as he
is out of bed, he rushes to the stream behind the hayrick
and thinks it fun to wash himself because Vinzi does it and
likes it. He scrubs himself cleaner than I ever washed him,
just because he wants to be like Vinzi, who certainly always
is spick and span. And now Russli never comes home from
the pasture crying. When I ask him how it happens he
comes home without howling and complaining, he says Faz
doesn't beat him any more because Vinzi takes his part.
When I ask Faz how it is he lets Russli come home in peace,
he declares Vinzi keeps the boy in order so he needs no
beating. Faz says he likes it better so, and wishes Vinzi
would remain with us always. He never talked that way
before, and he liked to hit out. And Jos, who always made
the least trouble, as you yourself must admit—"
"Yes, truly, the eldest son is always the model boy in his
mother's eyes," interrupted her husband.
"You may well believe that Vinzenz Lesa had some good
reason," replied her husband. "But I have asked myself the
same question and am unable to answer it. All I remember
is that he told me something about some fault in the boy.
When that man from Leuk asked if Vinzi's reserve and such-
like annoyed us, I recalled that Vinzenz thought our boys
were more interested in their work and wished his son were
so, and thought a summer with us, in altogether different
surroundings, might help him. He was right, for Vinzi is as a
lark now and makes everybody else merrier than they
were."
"No; the boys are all on the pasture from six in the
morning till six in the evening, singing and playing the pipe,
and wishing for nothing better," explained Lorenz. "That
news will please my cousin better than if you had found the
lad in the house."
Vinzi had kept his promise to cut beautiful pipes for Jos
and Faz, and there had been such a frenzy of practising that
pipe-playing had come to be their sole entertainment.
Black Vereli ran off with his prize with many thanks and
shouts of joy.
And then they were off, Russli a little in the rear with
Vinzi as always. He had listened attentively to his father's
words and now said, "Come back soon. Come down to us
again as soon as you have played for grandfather."
"No."
"A pipe."
When they came to the pasture, Jos and Faz drove the
herd to the right of the road toward the larch trees, but
Vinzi continued on his way.
The three boys called out, "Come back soon," over and
over again, and each time Vinzi waved his cap in answer, at
last flinging it up in the all for sheer joy and shouting
repeated hurrahs.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookmass.com