Practical GraphQL: Learning Full-Stack GraphQL Development with Projects 1st Edition Nabendu Biswas pdf download
Practical GraphQL: Learning Full-Stack GraphQL Development with Projects 1st Edition Nabendu Biswas pdf download
https://ebookmeta.com/product/practical-graphql-learning-full-
stack-graphql-development-with-projects-1st-edition-nabendu-
biswas/
https://ebookmeta.com/product/full-stack-graphql-
applications-1st-edition-william-lyon/
https://ebookmeta.com/product/learning-graphql-1st-edition-eve-
porcello-alex-banks/
https://ebookmeta.com/product/typescript-basics-learn-typescript-
from-scratch-and-solidify-your-skills-with-projects-1st-edition-
nabendu-biswas/
https://ebookmeta.com/product/medical-ethics-law-and-
communication-at-a-glance-1st-edition-patrick-davey-anna-
rathmell-michael-dunn-charles-foster-helen-salisbury/
Bridging Relational and NoSQL Databases Advances in
Data Mining and Database Management 1st Edition
Drazena Gaspar
https://ebookmeta.com/product/bridging-relational-and-nosql-
databases-advances-in-data-mining-and-database-management-1st-
edition-drazena-gaspar/
https://ebookmeta.com/product/ironsworn-1st-edition-shawn-tomkin/
https://ebookmeta.com/product/pathfinder-ap-the-ghouls-hunger-
blood-lords-4-of-6-2nd-edition-paizo-publishing/
https://ebookmeta.com/product/person-centered-medicine-1st-
edition-juan-e-mezzich/
https://ebookmeta.com/product/precarious-rhetorics-1st-edition-
wendy-s-hesford/
The Dragon s Cyber Secret Sassy Ever After Draconia
Outcasts Book 2 1st Edition Mandy Rosko Renee Hewett
https://ebookmeta.com/product/the-dragon-s-cyber-secret-sassy-
ever-after-draconia-outcasts-book-2-1st-edition-mandy-rosko-
renee-hewett/
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.
(Heads disappear.)
(No interlude.)
Song: "We'll gather round the Christmas Tree." Santa Claus and
Old Woman distribute presents to the company. Curtain falls.
REAR VIEW OF COPPER TOE SHOE HOUSE.
AN ALLEGORY.
CHARACTERS.
Justicia, Genius of Idylcourt.
Primeva, Goddess of Nature.
Majesta, Guardian of the Mountains.
Loftie, Aerie, Mountain-Spirits.
Flora, Guardian of the Fields.
Pomona, Agria, Field-Spirits.
Oceana, Guardian of the Sea.
Shellie, Wava, Sea-Spirits.
Genia, Goddess of Art.
Blenda, Genius of Painting.
Classica, Genius of Sculpture.
Harmonia, Genius of Music.
Faith, Hope, Charity, Classica's Models.
Religion, Prayer, Sorrow, Joy, Blenda's Picture.
Poesie, a wandering Maiden.
During the singing of the Chorus, enter, R., Primeva, Majesta, Flora,
and Oceana. Enter L., Genia, Classica, Blenda, Harmonia. At the
conclusion, enter Justicia R., and stands C. Positions are indicated
by the following diagram:—
Justici Welcome, fair sisters, to our regal court;
a. Your tuneful measures breathe of good report;
Twin guardian spirits of the fruitful earth,
To glad mankind creation gave you birth.
To you, Primeva, Nature bends in awe;
From you, fair Genia, Art receives its law.
Your free acclaim, upon this regal seat,
Justicia placed, all arguments to meet
With ear impartial; bade her voice decide,
That blissful harmony might here abide.
Your graceful homage, to our royal ear
Is but the foretaste of more welcome cheer.
You need our aid: unto our grateful heart
Your mission's import quickly now impart.
Prime Fair genius—
va. Sweet Justicia—
Genia. Our decree,
Justici By courtly rule, admits no double plea.
a. Be gracious, sisters.
Genia.
I was wanting grace,
And humbly bend to give Primeva place.
Prime Justicia, yonder proud and haughty sprite
va. Usurps a name Primeva claims by right.
I would have justice!
Justici Art thou just to her?
a. Genia usurper! 'tis a cruel slur.
Brave, truthful speech bears no envenomed sting,
But, like good metal, has an honest ring.
Prime It was an honest truth, I dare repeat;
va. I may be rough in speech, but scorn deceit.
Genia. 'Tis true, Justicia, in a friendly way,
I chanced to cross Primeva's path to-day,
And held some converse with my sister sprite,
Whose bold, free speech is often my delight.
Our theme was conquest; and, in pleasant strife,
Each boasted of her power o'er human life;
And, half in jest, this boast I gayly hurled,—
"I, Genia, am the empress of the world."
Prime 'Tis false. It was no jest.
va. Primeva, cease!
Justici Your angry humor doth disturb our peace.
a. Primeva met my jest with frowning brow,
Genia. And angry words, so bitter in their flow,
My jesting humor fled. We argued long
To whom, by right, that title should belong;
Leaving all else but this great truth behind,—
She is the greatest who best serves mankind.
Justici Who won the battle?
a. That you must decide.
Genia. By your impartial fiat we abide.
Prime On this we are agreed. Justicia, hear,
va. And let your judgment be both wise and clear.
Nature's own goddess, crowned and sceptred, I
Stand forth all meaner powers to defy.
I rule the field, the mount, the sky, the sea:
Who shall presume in power to rival me?
I wave my hand; and, o'er the barren waste,
Upspringing flowers to meet my coming haste.
I smile: the trees, o'erburdened with their fruit,
Bend low, with blushing cheeks, for my salute.
I speak: the bristling hillocks, far and near,
Present in homage many an opening ear;
The grand old mountains, stately and serene,
Welcome my coming, own me as their queen;
Adown their sides I loose the mimic streams,
To sport and revel in the sun's warm beams.
I rule the mighty sea by wave and tide;
I deck with starry gems the heavens wide;
I hurl the storm upon the maddening sea;
The shifting winds, obedient, follow me;
I bind the waters in an icy band,
And spread a snowy pall o'er all the land;
With all the elements I sport at will,
And, fast or loose, all my commands fulfil.
Fair genius, 'tis but just, that, so renowned,
As empress of the world I should be crowned.
Justici There's anger in thy speech, pride in thine eye;
a. Ambition's soaring pinions lift thee high.
What says your rival to this weighty claim?
Can aught be found to heighten Genia's fame?
Genia. Justicia, I a mightier sceptre sway,
And make Primeva's realms but pave the way
To grand achievements. Through her flowery field
I drive the plough, and bounteous harvests yield;
With skilful husbandry I trim and train,
And bursting garners from wild growth obtain;
Tunnel her mountains with resistless force,
And make a pathway for the iron horse;
Gird up her waters to obey my will,
And move the strong arm of the whirring mill.
Across her broad expanse, the mighty sea,
My white-winged messengers move swift and free;
From out their earthen graves I pluck the gems
That warm and shape, or glow in diadems.
In aërial flights I wander through her sphere,
Or with rare science draw her planets near,
With touch electric feel the farthest clime,
And count the storm-specks on the wings of time.
She empress of the world! it cannot be;
All her possessions minister to me.
Rough and ill-shaped the treasure she displays;
I mould and carve, and make the jewel blaze.
I claim the crown. Justicia, be thou true;
She must be greatest who can all subdue.
Justici Unto this haughty speech, and fulsome praise,
a. We've listened, Genia, in a wild amaze.
Hast thou forgot, self-laudatory boast
Was ne'er the leader of a conquering host?
But that to sober justice we're allied,
We should be merry at such foolish pride.
Genia. We wait your verdict.
Prime 'Twill give me the crown.
va. Primeva, cease.
Genia.I care not for your frown.
Prime Betwixt the false and true she must decide:
va. Mine is the wise, and yours the foolish pride.
Justici This idle skirmish doth our court defame;
a. A silly quarrel for an empty name.
Prime A silly quarrel! Is Justicia fair,
va. To shun a verdict by excuse so bare?
Genia. She's bound to rule whene'er we make appeal:
Be wise, Justicia, and your choice reveal.
Justici Hear, then, the judgment which we now proclaim:—
a. As each has sought to blazon her own fame,
The key to right in this one truth we find,—
She is the greatest who best serves mankind.
On this you are agreed. Here rest your case,
And leave the verdict to the human race.
Ofttimes, in Idylcourt, you've chanced to meet
An earthly maid, who favors our retreat,
With curious, watchful eyes, as though she sought
Food for the nourishment of new-born thought,—
A goodly type of fair, ingenuous youth,
About whom floats an atmosphere of truth.
Woo her, fair sisters, with all fair device,
Which should in honest rivalry suffice;
In peaceful tourney meet to win the maid;
And on the victor shall our hand be laid
In benediction of so wise a choice;
Then harmony prevails, and all rejoice.
Prime An admirable plan.
va. Justicia's right.
Genia. Prepare your forces for the bloodless fight.
Justici Be earnest in the strife, but loyal ever,
a. And some success must crown a right endeavor.