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/apollo-server/) is used to implement GraphQL Server.
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` along with [JSX Components](https://reactjs.org/docs/jsx-in-depth.html) 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. For UI creation [HTML5](https://www.w3schools.com/html/html5_intro.asp) and [CSS3](https://www.w3schools.com/css/) are 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
+
This is a _responsive web application_ for viewing in both Mobile and Desktop.
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
+
Back end is implemented using [Node JS](https://nodejs.org/en/docs) with [Apollo Server](https://www.apollographql.com/docs/apollo-server/) and [MongoDB](https://docs.mongodb.com/). [Atlas](https://www.mongodb.com/cloud/atlas), the _Cloud_ version of [MongoDB](https://docs.mongodb.com/) is used.
15
12
13
+
**This Application uses standalone GraphQL Server. For Backend Deployment with AWS Lambda details please check [aws-lambda branch](https://github.com/anijitsao/simple-apollo-server-graphql/tree/aws-lambda).**
16
14
17
15
## Features
18
-
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`
20
-
21
-
<olstart="3">
22
-
<li>
23
-
Function are deployed using <a href="https://www.serverless.com/framework/docs/providers/aws/guide/intro">Serverless</a> Framework.
24
-
</li>
25
-
<li>
26
-
<code>serverless.json</code> is used for deployment configuration instead of <code>serverless.yml</code>.
27
-
</li>
28
-
<li>
29
-
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
-
</li>
31
-
</ol>
32
-
33
-
34
-
6. For **session tracking**[JWT](https://jwt.io/) is used.
35
-
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/)
36
-
37
-
<olstart="8">
38
-
<li> All data is saved in <ahref="https://www.mongodb.com/docs/atlas/">MongoDB Atlas</a> i.e. <i>persistent</i>
39
-
<!--- <li> <strong>Caching</strong> is used for faster response in the APIs. <a href="https://redis.io/">Redis</a> is used for that purpose</li> -->
40
-
<li> This APIs can also be consumed by any <b>Frontend Application</b>.</li>
41
-
<li> To use <ahref="https://graphql.org/">GraphQL</a> features <ahref="https://www.apollographql.com/docs/apollo-server/">Apollo Server</a> is used
42
-
<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>
44
16
17
+
1. Code is rewritten with latest version of [React JS](https://reactjs.org/docs/getting-started.html) and [Node JS](https://nodejs.org/en/docs/).
18
+
2. Latest features of JavaScript i.e. ESNext is used.
45
19
20
+
<br/>
46
21
47
-
12.[NPM](https://www.npmjs.com/) dependencies are used for various purposes.
22
+
<olstart=3>
23
+
<li> This is Simple Book Search Application. It is a <b>CRUD</b> application. </li>
24
+
<li> It is a Full Stack Application with <b>Standalone GraphQL Server</b>. For the <b>Backend with AWS Lambda</b> please check the <ahref="https://github.com/anijitsao/simple-apollo-server-graphql/tree/aws-lambda">aws-lambda branch</a>.</li>
25
+
</ol>
48
26
27
+
5. 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**.
49
28
50
-
## Usage
29
+
<olstart=6>
30
+
<li>Login feature is added. </li>
31
+
<li>Error will be shown if the credentials are not correct or Network is <i>not</i> present.</li>
32
+
<li> <b>Session tracking</b> is supported using <ahref="https://https://jwt.io/">JSON Web Tokens (JWT).</a>
33
+
<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>
34
+
<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 in <i>Client</i> side. </li>
35
+
</ol>
51
36
52
-
First clone the repo
37
+
11._for simplicity passwords are not encrypted_
38
+
39
+
<olstart="12">
40
+
<li> To use <ahref="https://graphql.org/">GraphQL</a> features in <b>Server side</b> <ahref="https://www.apollographql.com/docs/apollo-server/">Apollo Server</a> is used
41
+
<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.
Install all the necessary dependencies by going inside the directory
51
+
52
+
Navigate inside the directory:
58
53
59
54
```bash
60
-
# Navigating inside the directory
61
-
$ cd simple-apollo-server-graphql
55
+
$ cd react-app-simple-book-search-graphql
56
+
```
57
+
58
+
Install all the necessary dependecies and run the **client side** of the application
62
59
63
-
# To install all the necessary dependencies
60
+
```bash
64
61
$ npm install
65
-
```
66
62
63
+
# To serve the application we use a npm module named http-server
64
+
$ npm run client-start
65
+
```
67
66
68
-
### Deployment
67
+
Now open **Another Terminal** and navigate to the same directory and run the **GraphQL Server**
69
68
70
-
In order to deploy the example, you need to run the following command:
69
+
```bash
70
+
$ cd /path/to/react-app-simple-book-search-graphql
71
71
72
-
```
73
-
$ serverless deploy
72
+
# Run the GraphQL Server
73
+
$ npm run server-start
74
74
```
75
75
76
-
### Invocation
76
+
### Login to book search
77
77
78
-
After successful deployment, you can invoke the deployed **functions / resolvers**.
78
+
---
79
79
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`.
80
+
1. Open web browser and type`http://localhost:8080` in the address bar to load the application
81
+
2. Now login with username `admin` and password `admin123`
82
+
83
+
**Test users**
84
+
85
+
| Username | Password |
86
+
| -------- | -------- |
87
+
| admin | admin123 |
88
+
89
+
_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">[Mozilla Firefox](https://www.mozilla.org/en-US/firefox/new/)_
90
+
91
+
However, to _test_[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
92
82
93
## API Listing
83
94
84
95
API listing is given below, -
85
96
86
-
**POST** /url-of-the-deployed-lambda/graphql
97
+
All APIs have common endpoint as following.
87
98
88
-
Following username and password is valid
99
+
**POST** /url-of-the-deployed-service/graphql (for `localhost` it will be `http://localhost:4000/graphql`)
89
100
90
-
|Username | Password |
91
-
|---|---|
92
-
|admin | admin123 |
101
+
Following _Queries_ use the same URL mentioned above
93
102
94
103
```javascript
95
104
query CreateTokenQuery{
96
105
// these are the only possible username and password
0 commit comments