Skip to content

Commit b9d73b7

Browse files
apollo client is working!
1 parent aec1f4a commit b9d73b7

File tree

9 files changed

+170
-30
lines changed

9 files changed

+170
-30
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"scripts": {
1010
"lerna": "lerna",
1111
"site": "yarn workspace @howtographql/oss",
12+
"server": "yarn workspace @howtographql/server",
1213
"theme": "yarn workspace @howtographql/gatsby-theme",
1314
"publish": "lerna publish --skip-git"
1415
},

packages/gatsby-theme/config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type Config = {
2+
apiUrl: string;
3+
}
4+
5+
const config: Config = {
6+
apiUrl: process.env.GATSBY_API_URL || "http://localhost:4000"
7+
}
8+
9+
export default config;

packages/gatsby-theme/gatsby-ssr.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from "react";
2+
import { ApolloProvider } from "react-apollo";
3+
import { client } from "./src/Apollo";
4+
5+
export const wrapRootElement = ({ element }) => (
6+
<ApolloProvider client={client}>{element}</ApolloProvider>
7+
);

packages/gatsby-theme/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
"@mdx-js/loader": "^0.20.3",
4343
"@mdx-js/mdx": "^1.0.0-rc.0",
4444
"@mdx-js/react": "^1.0.0-rc.0",
45+
"@types/isomorphic-fetch": "^0.0.35",
4546
"@types/react-copy-to-clipboard": "^4.2.6",
47+
"apollo-cache-inmemory": "^1.5.1",
48+
"apollo-client": "^2.5.1",
49+
"apollo-link-http": "^1.5.14",
4650
"babel-plugin-styled-components": "^1.10.0",
4751
"gatsby-image": "^2.0.33",
4852
"gatsby-mdx": "^0.5.7",
@@ -57,10 +61,12 @@
5761
"gatsby-source-filesystem": "^2.0.24",
5862
"gatsby-transformer-remark": "^2.3.2",
5963
"gatsby-transformer-sharp": "^2.1.17",
64+
"isomorphic-fetch": "^2.2.1",
6065
"mdx-utils": "^0.1.1",
6166
"prism-react-renderer": "^0.1.6",
6267
"prismjs": "^1.15.0",
6368
"prop-types": "^15.7.2",
69+
"react-apollo": "^2.5.5",
6470
"react-copy-to-clipboard": "^5.0.1",
6571
"react-helmet": "^5.2.0",
6672
"react-live": "^2.0.1",

packages/gatsby-theme/src/Apollo.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApolloClient } from 'apollo-client';
2+
import { HttpLink } from 'apollo-link-http';
3+
import { InMemoryCache } from 'apollo-cache-inmemory';
4+
import fetch from 'isomorphic-fetch';
5+
import config from '../config';
6+
7+
export const client = new ApolloClient({
8+
link: new HttpLink({ uri: config.apiUrl, fetch }),
9+
cache: new InMemoryCache(),
10+
});

packages/gatsby-theme/src/pages/index.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
import { RouterProps } from '@reach/router';
22
import * as React from 'react';
3+
import { Query } from 'react-apollo'
4+
import gql from 'graphql-tag';
5+
36
import Layout from '../components/layout';
47
import Listing from '../components/listing';
58
import { GlobalStyles } from '../styles';
69

710
const IndexPage: React.FunctionComponent<RouterProps> = ({ location }) => (
811
<Layout location={location}>
12+
<Query query={gql`
13+
query Test {
14+
feed {
15+
id
16+
}
17+
}
18+
`}>
19+
{({ data, error, loading }) => {
20+
console.log(data, error, loading)
21+
return <div />
22+
}}
23+
</Query>
924
<GlobalStyles />
1025
<Listing />
1126
</Layout>

packages/gatsby-theme/wrap-root-element.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from "react";
22
import { MDXProvider } from "@mdx-js/react";
33
import { preToCodeBlock } from "mdx-utils";
4+
import { ApolloProvider } from "react-apollo";
5+
6+
import { client } from "./src/Apollo";
7+
48
import { Code } from "./src/components/code";
59

610
// components is its own object outside of render so that the references to
@@ -18,5 +22,9 @@ const components = {
1822
}
1923
};
2024
export const wrapRootElement = ({ element }) => {
21-
return <MDXProvider components={components}>{element}</MDXProvider>;
25+
return (
26+
<ApolloProvider client={client}>
27+
<MDXProvider components={components}>{element}</MDXProvider>
28+
</ApolloProvider>
29+
);
2230
};

packages/server/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "with-db",
2+
"name": "@howtographql/server",
33
"private": true,
44
"scripts": {
55
"dev": "yoga dev",
@@ -29,4 +29,4 @@
2929
},
3030
"license": "MIT",
3131
"version": "1.0.1"
32-
}
32+
}

yarn.lock

+111-27
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,11 @@
12461246
version "4.0.1"
12471247
resolved "https://registry.yarnpkg.com/@types/is-glob/-/is-glob-4.0.1.tgz#a93eec1714172c8eb3225a1cc5eb88c2477b7d00"
12481248

1249+
"@types/isomorphic-fetch@^0.0.35":
1250+
version "0.0.35"
1251+
resolved "https://registry.npmjs.org/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.35.tgz#c1c0d402daac324582b6186b91f8905340ea3361"
1252+
integrity sha512-DaZNUvLDCAnCTjgwxgiL1eQdxIKEpNLOlTNtAgnZc50bG2copGhRrFN9/PxPBuJe+tZVLCbQ7ls0xveXVRPkvw==
1253+
12491254
"@types/istanbul-lib-coverage@^2.0.0":
12501255
version "2.0.1"
12511256
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff"
@@ -1445,6 +1450,11 @@
14451450
version "12.0.12"
14461451
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-12.0.12.tgz#45dd1d0638e8c8f153e87d296907659296873916"
14471452

1453+
"@types/zen-observable@^0.8.0":
1454+
version "0.8.0"
1455+
resolved "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.0.tgz#8b63ab7f1aa5321248aad5ac890a485656dcea4d"
1456+
integrity sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg==
1457+
14481458
"@webassemblyjs/[email protected]":
14491459
version "1.7.11"
14501460
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.7.11.tgz#b988582cafbb2b095e8b556526f30c90d057cace"
@@ -1757,6 +1767,40 @@ [email protected]:
17571767
apollo-server-env "2.2.0"
17581768
graphql-extensions "0.5.4"
17591769

1770+
apollo-cache-inmemory@^1.5.1:
1771+
version "1.5.1"
1772+
resolved "https://registry.npmjs.org/apollo-cache-inmemory/-/apollo-cache-inmemory-1.5.1.tgz#265d1ee67b0bf0aca9c37629d410bfae44e62953"
1773+
integrity sha512-D3bdpPmWfaKQkWy8lfwUg+K8OBITo3sx0BHLs1B/9vIdOIZ7JNCKq3EUcAgAfInomJUdN0QG1yOfi8M8hxkN1g==
1774+
dependencies:
1775+
apollo-cache "^1.2.1"
1776+
apollo-utilities "^1.2.1"
1777+
optimism "^0.6.9"
1778+
ts-invariant "^0.2.1"
1779+
tslib "^1.9.3"
1780+
1781+
[email protected], apollo-cache@^1.2.1:
1782+
version "1.2.1"
1783+
resolved "https://registry.npmjs.org/apollo-cache/-/apollo-cache-1.2.1.tgz#aae71eb4a11f1f7322adc343f84b1a39b0693644"
1784+
integrity sha512-nzFmep/oKlbzUuDyz6fS6aYhRmfpcHWqNkkA9Bbxwk18RD6LXC4eZkuE0gXRX0IibVBHNjYVK+Szi0Yied4SpQ==
1785+
dependencies:
1786+
apollo-utilities "^1.2.1"
1787+
tslib "^1.9.3"
1788+
1789+
apollo-client@^2.5.1:
1790+
version "2.5.1"
1791+
resolved "https://registry.npmjs.org/apollo-client/-/apollo-client-2.5.1.tgz#36126ed1d32edd79c3713c6684546a3bea80e6d1"
1792+
integrity sha512-MNcQKiqLHdGmNJ0rZ0NXaHrToXapJgS/5kPk0FygXt+/FmDCdzqcujI7OPxEC6e9Yw5S/8dIvOXcRNuOMElHkA==
1793+
dependencies:
1794+
"@types/zen-observable" "^0.8.0"
1795+
apollo-cache "1.2.1"
1796+
apollo-link "^1.0.0"
1797+
apollo-link-dedup "^1.0.0"
1798+
apollo-utilities "1.2.1"
1799+
symbol-observable "^1.0.2"
1800+
ts-invariant "^0.2.1"
1801+
tslib "^1.9.3"
1802+
zen-observable "^0.8.0"
1803+
17601804
17611805
version "0.3.1"
17621806
resolved "https://registry.yarnpkg.com/apollo-datasource/-/apollo-datasource-0.3.1.tgz#4b7ec4c2dd7d08eb7edc865b95fd46b83a4679fd"
@@ -1796,7 +1840,33 @@ apollo-graphql@^0.1.0:
17961840
apollo-env "0.4.0"
17971841
lodash.sortby "^4.7.0"
17981842

1799-
apollo-link@^1.2.3:
1843+
apollo-link-dedup@^1.0.0:
1844+
version "1.0.18"
1845+
resolved "https://registry.npmjs.org/apollo-link-dedup/-/apollo-link-dedup-1.0.18.tgz#635cb5659b082e7f270f7649c4b0f71021f7bb4b"
1846+
integrity sha512-1rr54wyMTuqUmbWvcXbwduIcaCDcuIgU6MqQ599nAMuTrbSOXthGfoAD8BDTxBGQ9roVlM7ABP0VZVEWRoHWSg==
1847+
dependencies:
1848+
apollo-link "^1.2.11"
1849+
tslib "^1.9.3"
1850+
1851+
apollo-link-http-common@^0.2.13:
1852+
version "0.2.13"
1853+
resolved "https://registry.npmjs.org/apollo-link-http-common/-/apollo-link-http-common-0.2.13.tgz#c688f6baaffdc7b269b2db7ae89dae7c58b5b350"
1854+
integrity sha512-Uyg1ECQpTTA691Fwx5e6Rc/6CPSu4TB4pQRTGIpwZ4l5JDOQ+812Wvi/e3IInmzOZpwx5YrrOfXrtN8BrsDXoA==
1855+
dependencies:
1856+
apollo-link "^1.2.11"
1857+
ts-invariant "^0.3.2"
1858+
tslib "^1.9.3"
1859+
1860+
apollo-link-http@^1.5.14:
1861+
version "1.5.14"
1862+
resolved "https://registry.npmjs.org/apollo-link-http/-/apollo-link-http-1.5.14.tgz#ed6292248d1819ccd16523e346d35203a1b31109"
1863+
integrity sha512-XEoPXmGpxFG3wioovgAlPXIarWaW4oWzt8YzjTYZ87R4R7d1A3wKR/KcvkdMV1m5G7YSAHcNkDLe/8hF2nH6cg==
1864+
dependencies:
1865+
apollo-link "^1.2.11"
1866+
apollo-link-http-common "^0.2.13"
1867+
tslib "^1.9.3"
1868+
1869+
apollo-link@^1.0.0, apollo-link@^1.2.11, apollo-link@^1.2.3:
18001870
version "1.2.11"
18011871
resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.11.tgz#493293b747ad3237114ccd22e9f559e5e24a194d"
18021872
dependencies:
@@ -1875,7 +1945,7 @@ [email protected]:
18751945
apollo-server-env "2.2.0"
18761946
graphql-extensions "0.5.4"
18771947

1878-
apollo-utilities@^1.0.1, apollo-utilities@^1.2.1:
1948+
apollo-utilities@1.2.1, apollo-utilities@^1.0.1, apollo-utilities@^1.2.1:
18791949
version "1.2.1"
18801950
resolved "https://registry.yarnpkg.com/apollo-utilities/-/apollo-utilities-1.2.1.tgz#1c3a1ebf5607d7c8efe7636daaf58e7463b41b3c"
18811951
dependencies:
@@ -6753,6 +6823,11 @@ imagemin@^6.0.0:
67536823
pify "^4.0.1"
67546824
replace-ext "^1.0.0"
67556825

6826+
immutable-tuple@^0.4.9:
6827+
version "0.4.10"
6828+
resolved "https://registry.npmjs.org/immutable-tuple/-/immutable-tuple-0.4.10.tgz#e0b1625384f514084a7a84b749a3bb26e9179929"
6829+
integrity sha512-45jheDbc3Kr5Cw8EtDD+4woGRUV0utIrJBZT8XH0TPZRfm8tzT0/sLGGzyyCCFqFMG5Pv5Igf3WY/arn6+8V9Q==
6830+
67566831
immutable@~3.7.6:
67576832
version "3.7.6"
67586833
resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.7.6.tgz#13b4d3cb12befa15482a26fe1b2ebae640071e4b"
@@ -7366,14 +7441,7 @@ isobject@^3.0.0, isobject@^3.0.1:
73667441
version "3.0.1"
73677442
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
73687443

7369-
isomorphic-fetch@^2.1.1:
7370-
version "2.2.1"
7371-
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
7372-
dependencies:
7373-
node-fetch "^1.0.1"
7374-
whatwg-fetch ">=0.10.0"
7375-
7376-
isomorphic-fetch@^2.2.1:
7444+
isomorphic-fetch@^2.1.1, isomorphic-fetch@^2.2.1:
73777445
version "2.2.1"
73787446
resolved "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
73797447
integrity sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=
@@ -7977,22 +8045,7 @@ jsonify@~0.0.0:
79778045
version "0.0.0"
79788046
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
79798047

7980-
jsonwebtoken@^8.1.0, jsonwebtoken@^8.3.0:
7981-
version "8.5.1"
7982-
resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d"
7983-
dependencies:
7984-
jws "^3.2.2"
7985-
lodash.includes "^4.3.0"
7986-
lodash.isboolean "^3.0.3"
7987-
lodash.isinteger "^4.0.4"
7988-
lodash.isnumber "^3.0.3"
7989-
lodash.isplainobject "^4.0.6"
7990-
lodash.isstring "^4.0.1"
7991-
lodash.once "^4.0.0"
7992-
ms "^2.1.1"
7993-
semver "^5.6.0"
7994-
7995-
jsonwebtoken@^8.5.1:
8048+
jsonwebtoken@^8.1.0, jsonwebtoken@^8.3.0, jsonwebtoken@^8.5.1:
79968049
version "8.5.1"
79978050
resolved "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d"
79988051
integrity sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==
@@ -8322,6 +8375,11 @@ lodash.isboolean@^3.0.3:
83228375
version "3.0.3"
83238376
resolved "https://registry.yarnpkg.com/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6"
83248377

8378+
lodash.isequal@^4.5.0:
8379+
version "4.5.0"
8380+
resolved "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
8381+
integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA=
8382+
83258383
lodash.isinteger@^4.0.4:
83268384
version "4.0.4"
83278385
resolved "https://registry.yarnpkg.com/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343"
@@ -9536,6 +9594,13 @@ opn@^5.1.0, opn@^5.4.0, opn@^5.5.0:
95369594
dependencies:
95379595
is-wsl "^1.1.0"
95389596

9597+
optimism@^0.6.9:
9598+
version "0.6.9"
9599+
resolved "https://registry.npmjs.org/optimism/-/optimism-0.6.9.tgz#19258ff8b3be0cea29ac35f06bff818e026e30bb"
9600+
integrity sha512-xoQm2lvXbCA9Kd7SCx6y713Y7sZ6fUc5R6VYpoL5M6svKJbTuvtNopexK8sO8K4s0EOUYHuPN2+yAEsNyRggkQ==
9601+
dependencies:
9602+
immutable-tuple "^0.4.9"
9603+
95399604
optimist@^0.6.1:
95409605
version "0.6.1"
95419606
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
@@ -11032,6 +11097,18 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.2.7:
1103211097
minimist "^1.2.0"
1103311098
strip-json-comments "~2.0.1"
1103411099

11100+
react-apollo@^2.5.5:
11101+
version "2.5.5"
11102+
resolved "https://registry.npmjs.org/react-apollo/-/react-apollo-2.5.5.tgz#0f27079a8fa9d9ceea8b29a5977eb42885f88fb9"
11103+
integrity sha512-zoJYlkI3i7+f1ejCbFtWU2GLCxjrmB3Es6RANyEZcbl0yetf5TI6ofMjBzILTvwoqp6tiQHH/8q66vQF0KcLmQ==
11104+
dependencies:
11105+
apollo-utilities "^1.2.1"
11106+
hoist-non-react-statics "^3.3.0"
11107+
lodash.isequal "^4.5.0"
11108+
prop-types "^15.7.2"
11109+
ts-invariant "^0.4.0"
11110+
tslib "^1.9.3"
11111+
1103511112
react-copy-to-clipboard@^5.0.1:
1103611113
version "5.0.1"
1103711114
resolved "https://registry.yarnpkg.com/react-copy-to-clipboard/-/react-copy-to-clipboard-5.0.1.tgz#8eae107bb400be73132ed3b6a7b4fb156090208e"
@@ -12778,7 +12855,7 @@ swap-case@^1.1.0:
1277812855
lower-case "^1.1.1"
1277912856
upper-case "^1.1.1"
1278012857

12781-
symbol-observable@^1.0.4, symbol-observable@^1.1.0, symbol-observable@^1.2.0:
12858+
symbol-observable@^1.0.2, symbol-observable@^1.0.4, symbol-observable@^1.1.0, symbol-observable@^1.2.0:
1278212859
version "1.2.0"
1278312860
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
1278412861

@@ -13094,6 +13171,13 @@ ts-invariant@^0.3.2:
1309413171
dependencies:
1309513172
tslib "^1.9.3"
1309613173

13174+
ts-invariant@^0.4.0:
13175+
version "0.4.1"
13176+
resolved "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.4.1.tgz#2612cb76626cf7c6debf59e6d284d0abd9caae07"
13177+
integrity sha512-fdL8AZinDiVKMsOI0cOWHLprS85LWy2p/eVSctVe6fpZF9BAvO59sQYMEWQ37yybBtlKU2zkmILYmy1jrOf6+g==
13178+
dependencies:
13179+
tslib "^1.9.3"
13180+
1309713181
ts-jest@^24.0.0:
1309813182
version "24.0.2"
1309913183
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.0.2.tgz#8dde6cece97c31c03e80e474c749753ffd27194d"

0 commit comments

Comments
 (0)