Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@

Too many Jasons?

## Is the `firstName` field just a hardcoded `"Jason"` string?
## Update 9 Match 2020

On <time dateTime="2020-03-09">9 March</time> I disabled the
serverless functions from running in production.

The site's loading and waving mechanisms have been adjusted to
be **visually identical** to when the serverless functions
were online. As a result, waves are no longer sent to the database and
will not be counted.

To view the code of this site when serverless functions were enabled,
check out [the repository at the last state with serverless functions enabled](https://github.com/NickyMeuleman/jason-api/tree/dfb0a7f2469fef55aa4f616b9e181d09bf40007b)

Only a few lines of code are different. The different lines were
commented out and replaced immediately below.

To view the code that moved away from serverless functions, check
out [the pull request that removes serverless functions](https://github.com/NickyMeuleman/jason-api/pull/6)

## Pre 9 March

### Is the `firstName` field just a hardcoded `"Jason"` string?

Yes, yes it is.

## Notes
### Notes

Some mutation are commented out in the schema (as are their respective resolvers).
They are fully functional, but disabled because the GraphQL playground is open and I don't want the internet to have free reign over the database 🤷‍♂
38 changes: 38 additions & 0 deletions extract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file was ran once to get the data to a .json file

const fs = require(`fs`);

const path = require(`path`);

require(`isomorphic-fetch`);

// started up the app and went to the graphql endpoint (not localhost because I'm on WSL2)
fetch(`http://172.24.16.127:8000/.netlify/functions/graphql`, {
method: `POST`,
headers: {
"Content-Type": `application/json`
},
body: JSON.stringify({
query: `
query {
allJasons {
__typename
id
name
twitter
likes
}
}`
})
})
.then(res => res.json())
.then(jsonres => {
const snapshotLocation = path.resolve(
process.cwd(),
`jasons-2020-03-09.json`
);
fs.writeFileSync(snapshotLocation, JSON.stringify(jsonres.data));
})
.catch(error => {
throw new Error(`oh-oh`, error);
});
16 changes: 12 additions & 4 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ module.exports = {
}
},
{
resolve: `gatsby-source-graphql`,
resolve: `gatsby-source-filesystem`,
options: {
typeName: `JASONAPI`,
fieldName: `JasonAPI`,
url: `http://localhost:9000/.netlify/functions/graphql`
name: `data`,
path: `${__dirname}/src/data/`
}
},
`gatsby-transformer-json`,
// {
// resolve: `gatsby-source-graphql`,
// options: {
// typeName: `JASONAPI`,
// fieldName: `JasonAPI`,
// url: `http://localhost:9000/.netlify/functions/graphql`
// }
// },
{
resolve: `gatsby-plugin-manifest`,
options: {
Expand Down
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[build]
command = "yarn build"
functions = "lambda"
# functions = "lambda"
publish = "public"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"gatsby-plugin-typescript": "^2.1.9",
"gatsby-source-filesystem": "^2.1.28",
"gatsby-source-graphql": "^2.1.17",
"gatsby-transformer-json": "^2.2.27",
"graphql": "^14.5.0",
"graphql-import-loader": "^0.2.1",
"graphql-tag": "^2.10.1",
Expand Down
8 changes: 7 additions & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ const Header: React.FC<IProps> = () => (
SON API
<span>{` }`}</span>
</Brand>
<GraphQL href="/.netlify/functions/graphql">
{/* <GraphQL href="/.netlify/functions/graphql">
<span>GraphQL Playground </span>
<span role="img" aria-label="hand pointing to right">
👉
</span>
</GraphQL> */}
<GraphQL href="#functions-offline">
<span>GraphQL Playground </span>
<span role="img" aria-label="hand pointing to right">
👉
Expand Down
9 changes: 6 additions & 3 deletions src/components/Jason.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from "react";
import styled from "@emotion/styled";
import { css } from "@emotion/core";
import { useMutation } from "@apollo/react-hooks";
// import { useMutation } from "@apollo/react-hooks";
import gql from "graphql-tag";
import { IJason } from "../types";
import useFakeMutation from "../useFakeMutation";

interface IProps {
jason: IJason;
Expand Down Expand Up @@ -59,15 +60,17 @@ const WAVE_MUTATION = gql`
const Jason: React.FC<IProps> = ({ jason, loading }) => {
const [waves, setWaves] = React.useState(jason.likes || 0);
const [didWave, setDidWave] = React.useState(false);
const [waveToJason] = useMutation(WAVE_MUTATION);
// const [waveToJason] = useMutation(WAVE_MUTATION);
const [waveToJason] = useFakeMutation(WAVE_MUTATION);

const onWaveClick = async (id: string): Promise<void> => {
// optimistic setWave is optimistic
setDidWave(true);
const { data } = await waveToJason({
variables: { id }
});
data && setWaves(data.upvoteJason.likes);
// data && setWaves(data.upvoteJason.likes);
data && setWaves(jason.likes + 1);
};

return (
Expand Down
76 changes: 76 additions & 0 deletions src/data/jasons-2019-12-28.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"allJasons": [
{
"likes": 131,
"name": "Jason Lengstorf",
"twitter": "@jlengstorf",
"id": "ck19j0sit000101ky33p751eo"
},
{
"likes": 43,
"name": "Jason Miller",
"twitter": "@_developit",
"id": "ck19ml110000101md12iqalf4"
},
{
"likes": 39,
"name": "Jason Brown",
"twitter": "@browniefed",
"id": "ck1b117ct000001mj8aqsf4wy"
},
{
"likes": 32,
"name": "Jason Bourne",
"twitter": "@jasonbourne",
"id": "ck1b5xkho0000ydlxf7dg2cbe"
},
{
"likes": 19,
"name": "Jason Bateman",
"twitter": "@batemanjason",
"id": "ck1b62m7f0001ydlxfpa6bvza"
},
{
"likes": 9,
"name": "Jason Statham",
"twitter": "@realjstatham",
"id": "ck1b66xem0002ydlxcs80h39d"
},
{
"likes": 10,
"name": "Jason Momoa",
"twitter": null,
"id": "ck1b6cjl50003ydlx7xec8bl2"
},
{
"likes": 10,
"name": "Jason Voorhees",
"twitter": null,
"id": "ck1b6cvaa0004ydlx9tmd9zth"
},
{
"likes": 11,
"name": "Jason Segel",
"twitter": "@jasonsegel",
"id": "ck1b6gxwr0005ydlxd77dc9ue"
},
{
"likes": 10,
"name": "Jason Biggs",
"twitter": "@JasonBiggs",
"id": "ck1b6j6fd0006ydlx56ux58um"
},
{
"likes": 27,
"name": "Jason Bahl",
"twitter": "@jasonbahl",
"id": "ck1ceb6a10000wklx0sy7cb3z"
},
{
"likes": 18,
"name": "Jason Mitchell",
"twitter": "@_jasonmit",
"id": "ck1cmxaf70000ywlx23e6cvpk"
}
]
}
88 changes: 88 additions & 0 deletions src/data/jasons-2020-03-09.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"allJasons": [
{
"__typename": "Jason",
"id": "ck19j0sit000101ky33p751eo",
"name": "Jason Lengstorf",
"twitter": "@jlengstorf",
"likes": 159
},
{
"__typename": "Jason",
"id": "ck19ml110000101md12iqalf4",
"name": "Jason Miller",
"twitter": "@_developit",
"likes": 64
},
{
"__typename": "Jason",
"id": "ck1b117ct000001mj8aqsf4wy",
"name": "Jason Brown",
"twitter": "@browniefed",
"likes": 44
},
{
"__typename": "Jason",
"id": "ck1b5xkho0000ydlxf7dg2cbe",
"name": "Jason Bourne",
"twitter": "@jasonbourne",
"likes": 38
},
{
"__typename": "Jason",
"id": "ck1b62m7f0001ydlxfpa6bvza",
"name": "Jason Bateman",
"twitter": "@batemanjason",
"likes": 22
},
{
"__typename": "Jason",
"id": "ck1b66xem0002ydlxcs80h39d",
"name": "Jason Statham",
"twitter": "@realjstatham",
"likes": 17
},
{
"__typename": "Jason",
"id": "ck1b6cjl50003ydlx7xec8bl2",
"name": "Jason Momoa",
"twitter": null,
"likes": 15
},
{
"__typename": "Jason",
"id": "ck1b6cvaa0004ydlx9tmd9zth",
"name": "Jason Voorhees",
"twitter": null,
"likes": 14
},
{
"__typename": "Jason",
"id": "ck1b6gxwr0005ydlxd77dc9ue",
"name": "Jason Segel",
"twitter": "@jasonsegel",
"likes": 15
},
{
"__typename": "Jason",
"id": "ck1b6j6fd0006ydlx56ux58um",
"name": "Jason Biggs",
"twitter": "@JasonBiggs",
"likes": 17
},
{
"__typename": "Jason",
"id": "ck1ceb6a10000wklx0sy7cb3z",
"name": "Jason Bahl",
"twitter": "@jasonbahl",
"likes": 32
},
{
"__typename": "Jason",
"id": "ck1cmxaf70000ywlx23e6cvpk",
"name": "Jason Mitchell",
"twitter": "@_jasonmit",
"likes": 21
}
]
}
Loading