You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simple [GraphQL](https://graphql.org/) APIs implementation using [Node JS](https://nodejs.org/en/docs/) and [AWS Lambda](https://aws.amazon.com/lambda/) with [Apollo Server](https://www.apollographql.com/docs/apollo-server/) and [MongoDB Atlas](https://www.mongodb.com/docs/atlas/).
1
+
# react-app-simple-book-search-graphql
3
2
4
-
This example illustrates how to deploy [GraphQL](https://graphql.org/) APIs using [NodeJS](https://nodejs.org/en/docs/) functions running on [AWS Lambda](https://aws.amazon.com/lambda/)using the traditional [Serverless](https://www.serverless.com/framework/docs/providers/aws/guide/intro) Framework. The deployed functions work with [MongoDB Atlas](https://www.mongodb.com/docs/atlas/).
3
+
A Simple Book Search Application using [React JS](https://reactjs.org/docs/getting-started.html), a JavaScript library to make awesome UI by Facebook, [Node JS](https://nodejs.org/en/docs) with [AWS Lambda](https://aws.amazon.com/lambda/)and [MongoDB](https://docs.mongodb.com/). To connect with the Backend [GraphQL](https://graphql.org/) is used with the framework [Apollo Client](https://www.apollographql.com/docs/react/) where the [Apollo Server](https://www.apollographql.com/docs/react/)
5
4
6
-
To work with [GraphQL](https://graphql.org/) features, i.e. **Type Definitions, Mutations, Queries, Resolvers** the framework [Apollo Server](https://www.apollographql.com/docs/apollo-server/) is used.
5
+
This application uses [React JS](https://reactjs.org/docs/getting-started.html) component oriented UI creation paradigm. All components are written in [JSX](https://reactjs.org/docs/jsx-in-depth.html) and ES6 style and are combined to get a single build for production purpose using [Webpack 5](https://webpack.js.org/concepts/).
7
6
8
-
This Example works with [AWS HTTP API](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop.html) events i.e. `httpApi`. All *logs* for the function is kept in [AWS Cloudwatch](https://aws.amazon.com/cloudwatch/) i.e *persistent*.
9
-
10
-
For *session tracking*[JSON Web Token (JWT)](https://jwt.io/) is used.
7
+
ES6 `module` creation along with `import /export` is used. [Babel](https://babeljs.io/docs/en/babel-preset-react) is used to _transpile_ all [JSX](https://reactjs.org/docs/jsx-in-depth.html) code to vanilla JavaScript code. To install all the dependecies `npm` is used.
11
8
12
-
To use the code in this example you **must** have an valid [AWS account](https://aws.amazon.com/account/) and necessary [AWS IAM](https://aws.amazon.com/iam/) roles and programmatic access to an user. You **must** have a [MongoDB Atlas](https://www.mongodb.com/docs/atlas/) account.
9
+
Back end is implemented using [Node JS](https://nodejs.org/en/docs) with [AWS Lambda](https://aws.amazon.com/lambda/) and [MongoDB](https://docs.mongodb.com/). [Atlas](https://www.mongodb.com/cloud/atlas), the _Cloud_ version of [MongoDB](https://docs.mongodb.com/) is used.
13
10
14
-
**This application is closely related to [simple-book-search-react](https://github.com/anijitsahu/simple-book-search-react). For Frontend deployment please check the repo [simple-book-search-react](https://github.com/anijitsahu/simple-book-search-react)**
11
+
For UI creation [HTML5](https://www.w3schools.com/html/html5_intro.asp) and [CSS3](https://www.w3schools.com/css/) are used. [Grid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout), the new feature of [CSS3](https://www.w3schools.com/css/) is used for layout creation purpose.
12
+
13
+
This is a _responsive web application_ for viewing in both Mobile and Desktop.
14
+
15
+
**This Application is closely related to [simple-apollo-server-graphql-lambda](https://github.com/anijitsahu/simple-apollo-server-graphql-lambda). For Backend Deployment details please check [simple-apollo-server-graphql-lambda](https://github.com/anijitsahu/simple-apollo-server-graphql-lambda).**
16
+
17
+
## Features
18
+
19
+
1. Code is rewritten with [React JS 18](https://reactjs.org/docs/getting-started.html) and [Node JS 18](https://nodejs.org/en/docs/)
20
+
2. Latest features of JavaScript i.e. ES6, ES7, ES8 is used
21
+
3.[React JS Hooks](https://reactjs.org/docs/hooks-intro.html) are used with Functional components
22
+
4. ES8 `async/await` is used
23
+
24
+
<br/>
25
+
26
+
<olstart=5>
27
+
<li> This is Simple Book Search Application. It is a <b>CRUD</b> application. </li>
28
+
<li> It is a Full Stack Application. This repo contains only the <i>Frontend</i> part. For the <b>Backend</b> please check the <ahref="https://github.com/anijitsahu/simple-apollo-server-graphql-lambda">simple-apollo-server-graphql-lambda</a></li>
29
+
</ol>
15
30
31
+
7. All the book details, authors and publication detils are stored in the [MongoDB Atlas](https://www.mongodb.com/cloud/atlas). This is a _free/ shared_ account on [Atlas](https://www.mongodb.com/cloud/atlas). **So Please use it wisely**
32
+
33
+
<olstart=8>
34
+
<li>Login feature is added </li>
35
+
<li>Error will be shown if the credentials are not correct or Network is <i>not</i> present</li>
36
+
<li> <b>Session tracking</b> is supported using <ahref="https://https://jwt.io/">JSON Web Tokens (JWT)</a>
37
+
<li><ahref="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage">LocalStorage</a> is used to save the <ahref="https://https://jwt.io/">JSON Web Tokens (JWT)</a></li>
38
+
<li> To implement the features of <ahref="https://graphql.org/">GraphQL</a> like <b>Queries, Mutations</b> the framework <ahref="https://www.apollographql.com/docs/react/">Apollo Client</a> is used</li>
39
+
</ol>
40
+
41
+
13._for simplicity passwords are not encrypted_
16
42
17
43
## Features
44
+
18
45
1.[AWS Lambda](https://aws.amazon.com/lambda/) function using [NodeJS](https://nodejs.org/en/docs/)
19
-
2. Function is using latest version of [AWS SDK JavaScript v3](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/welcome.html) with all **ES6+**syntaxes like Promises, `async/await`
46
+
2. Function is using latest version of [AWS SDK JavaScript v3](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/welcome.html) with all **ES6+** syntaxes like Promises, `async/await`
20
47
21
48
<olstart="3">
22
49
<li>
@@ -28,8 +55,7 @@ To use the code in this example you **must** have an valid [AWS account](https:/
28
55
<li>
29
56
All the deployment is created in <a href="https://aws.amazon.com/s3/">AWS S3</a> to store the <code>.zip</code> of the function code and <a href="https://aws.amazon.com/cloudformation/">AWS CloudFormation</a> Stack.
30
57
</li>
31
-
</ol>
32
-
58
+
</ol>
33
59
34
60
6. For **session tracking**[JWT](https://jwt.io/) is used.
35
61
7.[AWS HTTP API](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop.html) are using [AWS API GateWay](https://aws.amazon.com/api-gateway/)
@@ -40,12 +66,47 @@ To use the code in this example you **must** have an valid [AWS account](https:/
40
66
<li> This APIs can also be consumed by any <b>Frontend Application</b>.</li>
41
67
<li> To use <ahref="https://graphql.org/">GraphQL</a> features <ahref="https://www.apollographql.com/docs/apollo-server/">Apollo Server</a> is used
42
68
<li> For the <i>Schema</i> generation <b>Type Definitions</b> are added. <b>Queries</b> are used for the <i>Reading</i> operations while <b>Mutations</b> are added for <i>Mutable</i> operations.
43
-
</ol>
69
+
</ol>
44
70
71
+
12.[NPM](https://www.npmjs.com/) dependencies are used for various purposes.
45
72
73
+
## Installation
46
74
47
-
12.[NPM](https://www.npmjs.com/) dependencies are used for various purposes.
Install all the necessary dependecies and run the application
88
+
89
+
```bash
90
+
$ npm install
91
+
92
+
# To serve the application we use a npm module named http-server
93
+
$ npm run serve
94
+
```
48
95
96
+
### Login to book search
97
+
98
+
---
99
+
100
+
1. Open web browser and type`http://localhost:8080` in the address bar to load the application
101
+
2. Now login with username `admin` and password `admin123`
102
+
103
+
**Test users**
104
+
105
+
| Username | Password |
106
+
| -------- | -------- |
107
+
| admin | admin123 |
108
+
109
+
_tested with latest versions of <imgsrc="screenshots/chrome.png"width="20px"title="Google Chrome">[Google Chrome](https://www.google.com/chrome/) and <imgsrc="screenshots/firefox.png"width="25px"title="Firefox Developer edition">[Mozilla Firefox](https://www.mozilla.org/en-US/firefox/new/)_
Install all the necessary dependencies by going inside the directory
58
120
59
121
```bash
@@ -64,7 +126,6 @@ $ cd simple-apollo-server-graphql
64
126
$ npm install
65
127
```
66
128
67
-
68
129
### Deployment
69
130
70
131
In order to deploy the example, you need to run the following command:
@@ -75,34 +136,33 @@ $ serverless deploy
75
136
76
137
### Invocation
77
138
78
-
After successful deployment, you can invoke the deployed **functions / resolvers**.
139
+
After successful deployment, you can invoke the deployed **functions / resolvers**.
79
140
80
-
However, to call using [GraphQL](https://graphql.org/) API you can use any *supported* Client like [Altair GraphQL Client](https://chrome.google.com/webstore/detail/altair-graphql-client/flnheeellpciglgpaodhkhmapeljopja?hl=en) with the `url` and *HTTP Verbs* as shown in Terminal after using `serverless deploy`.
141
+
However, to call using [GraphQL](https://graphql.org/) API you can use any _supported_ Client like [Apollo Sandbox](https://studio.apollographql.com/sandbox/explorer/?_gl=1%2Abuieem%2A_ga%2AMjAyNTg2NTkxOC4xNjc5OTg3MzI4%2A_ga_0BGG5V2W2K%2AMTY3OTk4NzMyOC4xLjEuMTY3OTk4NzM0NS4wLjAuMA..) with the `url` and _HTTP Verbs_ as shown in Terminal.
81
142
82
143
## API Listing
83
144
84
145
API listing is given below, -
85
146
86
-
**POST** /url-of-the-deployed-lambda/graphql
147
+
All APIs have common endpoint as following.
148
+
**POST** /url-of-the-deployed-lambda/graphql (for `localhost` it will be `http://localhost:4000/graphql`)
87
149
88
150
Following username and password is valid
89
151
90
-
|Username | Password |
91
-
|---|---|
92
-
|admin | admin123 |
152
+
|Username | Password |
153
+
|-------- |-------- |
154
+
|admin| admin123 |
93
155
94
156
```javascript
95
157
query CreateTokenQuery{
96
158
// these are the only possible username and password
<imgsrc="screenshots/desktop 4.png"width="590px"title="If credentials are not correct screen"/>
289
+
<imgsrc="screenshots/mobile 4.png"width="190px"title="If credentials are not correct screen"/>
290
+
</p>
291
+
292
+
<p> Edit a Book <br/>
293
+
<imgsrc="screenshots/desktop 5.png"width="590px"title="After a successful login screen"/>
294
+
<imgsrc="screenshots/mobile 5.png"width="190px"title="After a successful login screen"/>
295
+
</p>
296
+
297
+
<p> Delete a Book <br/>
298
+
<imgsrc="screenshots/desktop 6.png"width="590px"title="When a new user joins screen"/>
299
+
<imgsrc="screenshots/mobile 6.png"width="190px"title="When a new user joins screen"/>
300
+
</p>
301
+
302
+
Simple [GraphQL](https://graphql.org/) APIs implementation using [Node JS](https://nodejs.org/en/docs/) and [AWS Lambda](https://aws.amazon.com/lambda/) with [Apollo Server](https://www.apollographql.com/docs/apollo-server/) and [MongoDB Atlas](https://www.mongodb.com/docs/atlas/).
303
+
304
+
This example illustrates how to deploy [GraphQL](https://graphql.org/) APIs using [NodeJS](https://nodejs.org/en/docs/) functions running on [AWS Lambda](https://aws.amazon.com/lambda/) using the traditional [Serverless](https://www.serverless.com/framework/docs/providers/aws/guide/intro) Framework. The deployed functions work with [MongoDB Atlas](https://www.mongodb.com/docs/atlas/).
305
+
306
+
To work with [GraphQL](https://graphql.org/) features, i.e. **Type Definitions, Mutations, Queries, Resolvers** the framework [Apollo Server](https://www.apollographql.com/docs/apollo-server/) is used.
307
+
308
+
This Example works with [AWS HTTP API](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop.html) events i.e. `httpApi`. All _logs_ for the function is kept in [AWS Cloudwatch](https://aws.amazon.com/cloudwatch/) i.e _persistent_.
309
+
310
+
For _session tracking_[JSON Web Token (JWT)](https://jwt.io/) is used.
311
+
312
+
To use the code in this example you **must** have an valid [AWS account](https://aws.amazon.com/account/) and necessary [AWS IAM](https://aws.amazon.com/iam/) roles and programmatic access to an user. You **must** have a [MongoDB Atlas](https://www.mongodb.com/docs/atlas/) account.
313
+
314
+
**This application is closely related to [simple-book-search-react](https://github.com/anijitsahu/simple-book-search-react). For Frontend deployment please check the repo [simple-book-search-react](https://github.com/anijitsahu/simple-book-search-react)**
0 commit comments