Skip to content

Commit 7dd247a

Browse files
committed
apollo client basics
0 parents  commit 7dd247a

File tree

8 files changed

+7754
-0
lines changed

8 files changed

+7754
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Week_04
2+
Intro to React
3+
Adding a list of elements to your todo list

package-lock.json

Lines changed: 357 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "react-intro",
3+
"version": "1.0.0",
4+
"description": "Step 1",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "react-scripts start",
8+
"build": "react-scripts build"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"apollo-boost": "^0.1.23",
14+
"graphql": "^14.0.2",
15+
"react": "^16.4.2",
16+
"react-apollo": "^2.3.3",
17+
"react-dom": "^16.4.2",
18+
"react-scripts": "^1.1.5"
19+
}
20+
}

public/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>React App</title>
6+
</head>
7+
<body>
8+
<noscript>
9+
You need to enable JavaScript to run this app.
10+
</noscript>
11+
<div id="root"></div>
12+
</body>
13+
</html>

src/components/MyName.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { Component } from 'react'
2+
import ApolloClient from "apollo-boost";
3+
4+
import { Query } from "react-apollo";
5+
import gql from "graphql-tag";
6+
7+
const MyName = () => (
8+
<Query
9+
query={gql`
10+
{
11+
me {
12+
name
13+
}
14+
}
15+
`}
16+
>
17+
{({ loading, error, data }) => {
18+
if (loading) return <p>Loading...</p>;
19+
if (error) return <p>Error :(</p>;
20+
{console.log(data.me.name)}
21+
return <p> {data.me.name}</p>
22+
}}
23+
</Query>
24+
);
25+
export default MyName

src/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ApolloProvider } from "react-apollo";
2+
import ApolloClient from "apollo-boost";
3+
import React from "react";
4+
import { render } from "react-dom";
5+
6+
import MyName from "./components/MyName.js";
7+
8+
const client = new ApolloClient({
9+
uri: "http://localhost:8000/graphql"
10+
});
11+
12+
const App = () => (
13+
<ApolloProvider client={client}>
14+
<div>
15+
<h2>My first Apollo app 🚀</h2>
16+
<MyName />
17+
</div>
18+
</ApolloProvider>
19+
);
20+
21+
render(<App />, document.getElementById("root"));

0 commit comments

Comments
 (0)