这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dc13c6c
First commit. Copied from react tutorial site.
coco98 May 1, 2019
2618c01
Updates introduction
coco98 May 2, 2019
7921701
remove old files
praveenweb May 5, 2019
dc36fbb
init: learn hasura
praveenweb May 5, 2019
d6c2064
content structure setup
praveenweb May 5, 2019
f0b8f1f
content till data model
praveenweb May 5, 2019
0f2b929
added authentication
praveenweb May 6, 2019
2686f63
update dockerfile
praveenweb May 6, 2019
c1223aa
Merge branch 'master' into learn-hasura-backend
praveenweb May 6, 2019
87b9143
update tutorials, business logic in wip
praveenweb May 6, 2019
2d1fb69
add event trigger, remote-schema
praveenweb May 7, 2019
1d4b1a2
update manifests
praveenweb May 7, 2019
82b70f0
update caddy config
praveenweb May 7, 2019
4d71bd6
remove intro to graphql
praveenweb May 7, 2019
19fd7ea
update content
praveenweb May 7, 2019
84a1904
move images to cdn
praveenweb May 7, 2019
378de26
move react-tutorial images to cdn
praveenweb May 7, 2019
58cfa65
add readinessProbe
praveenweb May 7, 2019
e11b1d2
update manifest
praveenweb May 7, 2019
a1a34cf
Merge branch 'master' into learn-hasura-backend
praveenweb May 7, 2019
35840d4
content updates
praveenweb May 8, 2019
737ab91
Merge branch 'learn-hasura-backend' of github.com:praveenweb/graphql-…
praveenweb May 8, 2019
a38f881
update content
praveenweb May 8, 2019
e7ae040
update image cdn
praveenweb May 8, 2019
b58e326
update image cdn
praveenweb May 8, 2019
f91f7c7
update image cdn
praveenweb May 8, 2019
ae1bd5a
update images for react tutorial
praveenweb May 8, 2019
c3e857d
Merge branch 'master' into learn-hasura-backend
praveenweb May 8, 2019
a7b07f7
fix image links
praveenweb May 8, 2019
0f6346d
Merge branch 'learn-hasura-backend' of github.com:praveenweb/graphql-…
praveenweb May 8, 2019
a1fe90b
update youtube videos
praveenweb May 8, 2019
167d6ae
update title tag
praveenweb May 8, 2019
5fa8495
update authentication content
praveenweb May 8, 2019
c82bd26
fix content
praveenweb May 8, 2019
5542f4a
update videos, content fix
praveenweb May 9, 2019
caccfb8
update videos
praveenweb May 9, 2019
f72c24b
update dockerfile
praveenweb May 9, 2019
81cf1d2
update dockerfile
praveenweb May 9, 2019
a3ec6b8
Merge branch 'master' into learn-hasura-backend
praveenweb May 10, 2019
6b6f82b
update content
praveenweb May 10, 2019
4056b8d
Merge branch 'learn-hasura-backend' of github.com:praveenweb/graphql-…
praveenweb May 10, 2019
883bfbe
Merge branch 'master' into learn-hasura-backend
praveenweb May 10, 2019
a8c1f9c
revert to v1alpha1
praveenweb May 10, 2019
5d9ccb9
Merge branch 'master' into learn-hasura-backend
praveenweb May 10, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ We use [dotenv](https://github.com/motdotla/dotenv) for setting environment vari
```
PORT=3000
NODE_ENV=development
GRAPHQL_ENDPOINT=http://localhost:8090/v1/graphql
GRAPHQL_ENDPOINT=http://localhost:8090/v1alpha1/graphql
HEADER_STRING='{}'
VARIABLE_STRING='{}'
QUERY_STRING='query { test_table { id } }'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dataApisContent.push({
},
request: {
method: 'POST',
url: getUrl('/v1/graphql'),
url: getUrl('/v1alpha1/graphql'),
headers: defaultHeader,
bodyType: 'graphql',
params: JSON.stringify({}, null, 4),
Expand Down
12 changes: 9 additions & 3 deletions community/learn/graphql-tutorials/manifests/caddy-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ data:
/graphql/react/ /graphql/react/introduction
}

redir 301 {
/graphql/hasura/ /graphql/hasura/introduction
}

redir 302 {
if {path} is /
/ /graphql/react/introduction
Expand All @@ -25,8 +29,8 @@ data:
without /graphql/console
}

proxy /graphql/v1/graphql hasura/v1/graphql {
without /graphql/v1/graphql
proxy /graphql/v1alpha1/graphql hasura/v1alpha1/graphql {
without /graphql/v1alpha1/graphql
websocket
}

Expand All @@ -42,9 +46,11 @@ data:
without /graphql/graphiql
}

proxy /graphql/hasura hasura-backend

proxy /graphql/react react-apollo

proxy /graphql hasura/v1/graphql {
proxy /graphql hasura/v1alpha1/graphql {
without /graphql
websocket
}
Expand Down
49 changes: 49 additions & 0 deletions community/learn/graphql-tutorials/manifests/hasura-backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: hasura-backend
name: hasura-backend
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: hasura-backend
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
template:
metadata:
labels:
app: hasura-backend
spec:
containers:
- image: hasura/base-git-image:0.7
imagePullPolicy: IfNotPresent
name: hasura-backend
ports:
- containerPort: 8080
protocol: TCP
readinessProbe:
httpGet:
path: /graphql/hasura/introduction
port: 8080
---
apiVersion: v1
kind: Service
metadata:
labels:
app: hasura-backend
name: hasura-backend
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: hasura-backend
type: ClusterIP
2 changes: 1 addition & 1 deletion community/learn/graphql-tutorials/manifests/hasura.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
app: hasura
spec:
containers:
- image: hasura/graphql-engine:v1.0.0-alpha44
- image: hasura/graphql-engine:v1.0.0-alpha45
imagePullPolicy: IfNotPresent
name: hasura
env:
Expand Down
4 changes: 4 additions & 0 deletions community/learn/graphql-tutorials/manifests/homepage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
ports:
- containerPort: 8080
protocol: TCP
readinessProbe:
httpGet:
path: /
port: 8080
---
apiVersion: v1
kind: Service
Expand Down
4 changes: 4 additions & 0 deletions community/learn/graphql-tutorials/manifests/react-apollo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
ports:
- containerPort: 8080
protocol: TCP
readinessProbe:
httpGet:
path: /graphql/react/introduction
port: 8080
---
apiVersion: v1
kind: Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
This app uses environment variables.

```
REACT_APP_GRAPHQL_URL=https://hasura-todo-test.herokuapp.com/v1/graphql
REACT_APP_GRAPHQL_URL=https://hasura-todo-test.herokuapp.com/v1alpha1/graphql

REACT_APP_REALTIME_GRAPHQL_URL=wss://hasura-todo-test.herokuapp.com/v1/graphql
REACT_APP_REALTIME_GRAPHQL_URL=wss://hasura-todo-test.herokuapp.com/v1alpha1/graphql

REACT_APP_CALLBACK_URL=http://localhost:3000/callback

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
This app uses environment variables.

```
REACT_APP_GRAPHQL_URL=https://hasura-todo-test.herokuapp.com/v1/graphql
REACT_APP_GRAPHQL_URL=https://hasura-todo-test.herokuapp.com/v1alpha1/graphql

REACT_APP_REALTIME_GRAPHQL_URL=wss://hasura-todo-test.herokuapp.com/v1/graphql
REACT_APP_REALTIME_GRAPHQL_URL=wss://hasura-todo-test.herokuapp.com/v1alpha1/graphql

REACT_APP_CALLBACK_URL=http://localhost:3000/callback

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ GraphQL is designed for developers of web/mobile apps (HTTP clients) to be able
## GraphQL vs REST: an example
Let's say you have an API to fetch a user's profile and their address. In a typical REST scenario, this is what the request/response would look like:

![GraphQL API example](./intro-to-graphql/rest-api.png)
![GraphQL API example](https://graphql-engine-cdn.hasura.io/learn-hasura/assets/graphql-react/rest-api.png)

If your API server was a GraphQL server instead, this is what your API calls would look like:

![GraphQL API example](./intro-to-graphql/graphql-api.gif)
![GraphQL API example](https://graphql-engine-cdn.hasura.io/learn-hasura/assets/graphql-react/graphql-api.gif)

You can see that the response JSON is different for different "queries" sent by the client.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GraphQL is actually used in an HTTP client (typically a web/mobile app).
Check out the diagram below, to get a sense of how GraphQL is typically used in
your stack:

![GraphQL over HTTP](./graphql-on-http.png)
![GraphQL over HTTP](https://graphql-engine-cdn.hasura.io/learn-hasura/assets/graphql-react/graphql-on-http.png)

### GraphQL client-server flow:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ When you connect GraphiQL to a GraphQL endpoint, it
queries the server for its GraphQL schema and gives you a UI to browse
and test queries, and that powers its amazing autocomplete!

![GraphiQL demo](./graphiql.gif)
![GraphiQL demo](https://graphql-engine-cdn.hasura.io/learn-hasura/assets/graphql-react/graphiql.gif)

Tools like GraphiQL make GraphQL APIs really easy
to use and integrate APIs in your app without requiring
Expand All @@ -44,7 +44,7 @@ use a tool like GraphiQL to explore and test your GraphQL queries.
name
}
}
```
```

4. Hit `ctrl + enter` or `cmd + enter` (mac) or click on the ▶️ icon to run the GraphQL query
5. On the right, you should see a list of users by their names that are in the system!
Expand All @@ -60,7 +60,7 @@ that you see on the right hand side.
Our todo app has users, todos and information about users that are currently online.
This is what our API "schema" looks like:

![Schema](./schema.png)
![Schema](https://graphql-engine-cdn.hasura.io/learn-hasura/assets/graphql-react/schema.png)

As you can see, it is a "graph" like schema where all the 3 models are linked to each other.

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ You need to have npm/yarn & node 8+ running.

## How long will this tutorial take?
Less than 2 hours

## Will this course teach setting up the GraphQL backend?
No, this course is focussed on the frontend. You can take the [Introduction to Hasura](https://learn.hasura.io/graphql/hasura) backend course to know how the backend for this realtime todo app was setup.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Our task will be to convert the "static" UI into a working realtime app.

This is what you should see after the steps above:

![Boilerplate after login](./assets/boilerplate-after-login.png)
![Boilerplate after login](https://graphql-engine-cdn.hasura.io/learn-hasura/assets/graphql-react/boilerplate-after-login.png)

### Load GraphiQL to play with your GraphQL APIs

Expand All @@ -31,4 +31,4 @@ This is what you should see after the steps above:

This is what you should see after the steps above:

![GraphiQL after login](./assets/graphiql-after-login.png)
![GraphiQL after login](https://graphql-engine-cdn.hasura.io/learn-hasura/assets/graphql-react/graphiql-after-login.png)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Congratulations! You have successfully completed the course.

In case you are wondering what to do next, you have the following options:

## Take the Hasura backend course
We have an [Introduction to Hasura](https://learn.hasura.io/graphql/hasura) backend course to build the backend that you just used for your react app.

## Join Discord for Support
We have a Discord Channel for those who are new to GraphQL. Please post your queries or feedback regarding this course. It is a pretty active channel.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.env
node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# sendgrid-email-event-trigger

[![DEPLOY TO GLITCH](https://raw.githubusercontent.com/hasura/graphql-engine/master/community/boilerplates/auth-webhooks/nodejs-express/assets/deploy-glitch.png)](https://glitch.com/~sendgrid-send-email-event)

## Environment variables
After remixing to your own project on Glitch, modify the `.env` file to enter the
- `SMTP_LOGIN`,
- `SMTP_PASSWORD`,
- `SMTP_HOST`

values appropriately.

Additionally you should also configure the sender and receiver address using
- `SENDER_ADDRESS`
- `RECEIVER_ADDRESS`

env variables.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport('smtp://'+process.env.SMTP_LOGIN+':'+process.env.SMTP_PASSWORD+'@' + process.env.SMTP_HOST);
const fs = require('fs');
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();

app.set('port', (process.env.PORT || 3000));

app.use('/', express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Cache-Control', 'no-cache');
next();
});

app.post('/send-email', function(req, res) {

const name = req.body.event.data.new.name;
// setup e-mail data
const mailOptions = {
from: process.env.SENDER_ADDRESS, // sender address
to: process.env.RECEIVER_ADDRESS, // list of receivers
subject: 'A new user has registered', // Subject line
text: 'Hi, This is to notify that a new user has registered under the name of ' + name, // plaintext body
html: '<p>'+'Hi, This is to notify that a new user has registered under the name of ' + name + '</p>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
res.json({'success': true});
});

});

app.listen(app.get('port'), function() {
console.log('Server started on: ' + app.get('port'));
});
Loading