Skip to content

Commit

Permalink
Boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
asgeir-s committed Mar 9, 2022
1 parent 7ff3871 commit 74f33e4
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 192 deletions.
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn pre-commit
142 changes: 0 additions & 142 deletions node_modules/.yarn-integrity

This file was deleted.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
"react-markdown": "^8.0.0",
"react-router-dom": "6"
},
"devDependencies": {
"husky": "5.1.3"
},
"scripts": {
"predeploy": "cd packages/app && npm run build",
"deploy": "cd packages/app && gh-pages -d build"
"predeploy": "yarn --cwd packages/app yarn run build",
"deploy": "yarn --cwd packages/app yarn deploy",
"prepare": "husky install",
"pre-commit": "yarn --cwd packages/app pre-commit && yarn --cwd packages/subgraph pre-commit"
}
}
9 changes: 7 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
"web-vitals": "^2.1.0"
},
"scripts": {
"predeploy": "npm run build",
"predeploy": "yarn run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"fmt": "prettier '(test|src)/**/*.(ts|tsx)' -w",
"pre-commit": "yarn fmt"
},
"eslintConfig": {
"extends": [
Expand All @@ -43,5 +45,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"prettier": "^2.5.1"
}
}
8 changes: 4 additions & 4 deletions packages/app/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
import React from "react";
import { render, screen } from "@testing-library/react";
import App from "./App";

test('renders learn react link', () => {
test("renders learn react link", () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/reportWebVitals.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReportHandler } from 'web-vitals';
import { ReportHandler } from "web-vitals";

const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
import "@testing-library/jest-dom";
5 changes: 5 additions & 0 deletions packages/app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6957,6 +6957,11 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=

prettier@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a"
integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==

pretty-bytes@^5.3.0, pretty-bytes@^5.4.1:
version "5.6.0"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb"
Expand Down
6 changes: 6 additions & 0 deletions packages/subgraph/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": false,
"semi": false
}
1 change: 1 addition & 0 deletions packages/subgraph/example.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{

"article": "QmeoVkGPKXQznziD53rYrV4v1MRoMTpxJkRqJjutCZrQ4t",
"authors": ["Auryn", "Sam"],
"tags": ["Lorem Ipsum"],
Expand Down
8 changes: 7 additions & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
"deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ tabula",
"create-local": "graph create --node http://localhost:8020/ tabula",
"remove-local": "graph remove --node http://localhost:8020/ tabula",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 tabula"
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 tabula",
"fmt": "prettier '(test|src)/**/*.ts' -w",
"pre-commit": "yarn fmt"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.27.0",
"@graphprotocol/graph-ts": "0.25.0"
},
"devDependencies": {
"matchstick-as": "^0.4.0",
"prettier": "^2.5.1"
}
}
2 changes: 1 addition & 1 deletion packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type Post @entity {
tags: [String!]! # array of tags
title: String! # title of the post
description: String! # description of the post
previewImage: String # IPFS hash of the preview image for the post
image: String # IPFS hash of the preview image for the post
}
48 changes: 22 additions & 26 deletions packages/subgraph/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,58 @@
import { BigInt, Bytes, crypto, ipfs } from "@graphprotocol/graph-ts";
import { Poster, NewPost } from "../generated/Poster/Poster";
import { Post } from "../generated/schema";
import { json, JSONValueKind } from "@graphprotocol/graph-ts";
import { jsonToString, jsonToArrayString } from "./utils";
import { BigInt, Bytes, crypto, ipfs } from "@graphprotocol/graph-ts"
import { Poster, NewPost } from "../generated/Poster/Poster"
import { Post } from "../generated/schema"
import { json, JSONValueKind } from "@graphprotocol/graph-ts"
import { jsonToString, jsonToArrayString } from "./utils"

export function handleNewPost(event: NewPost): void {
// decode json content, fail gracefully.
let contentData = json.try_fromString(event.params.content);
let contentData = json.try_fromString(event.params.content)
if (contentData.isError) {
return;
return
}
let content = contentData.value.toObject();
let content = contentData.value.toObject()

// Load post entity
let post = Post.load(
event.transaction.hash.toHex() + "-" + event.logIndex.toString()
);
let post = Post.load(event.transaction.hash.toHex() + "-" + event.logIndex.toString())
// create new entity if it doesn't already exist
if (!post) {
post = new Post(
event.transaction.hash.toHex() + "-" + event.logIndex.toString()
);
post = new Post(event.transaction.hash.toHex() + "-" + event.logIndex.toString())
}
// Set user
post.publisher = event.params.user;
post.publisher = event.params.user

// Fetch article article from IPFS, fail gracefully.
let article = ipfs.cat(jsonToString(content.get("article")));
let article = ipfs.cat(jsonToString(content.get("article")))
if (!article) {
post.article = jsonToString(content.get("article"));
post.article = jsonToString(content.get("article"))
} else {
post.article = article.toString();
post.article = article.toString()
}

// Set article
// post.article = jsonToString(content.get("article"));

// Set authors
post.authors = jsonToArrayString(content.get("authors"));
post.authors = jsonToArrayString(content.get("authors"))

// Set postedOn timestamp
post.postedOn = event.block.timestamp;
post.postedOn = event.block.timestamp

// Set lastUpdated timestamp
post.lastUpdated = event.block.timestamp;
post.lastUpdated = event.block.timestamp

// Set tags
post.tags = jsonToArrayString(content.get("tags"));
post.tags = jsonToArrayString(content.get("tags"))

// Set title
post.title = jsonToString(content.get("title"));
post.title = jsonToString(content.get("title"))

// Set description
post.description = jsonToString(content.get("description"));
post.description = jsonToString(content.get("description"))

// Set image
post.image = jsonToString(content.get("image"));
post.image = jsonToString(content.get("image"))

// Safe updates to store
post.save();
post.save()
}
17 changes: 8 additions & 9 deletions packages/subgraph/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { JSONValue, JSONValueKind } from "@graphprotocol/graph-ts";
import { JSONValue, JSONValueKind } from "@graphprotocol/graph-ts"

/**
* Make sure the given JSONValue is a string and returns string it contains.
* Returns blank string otherwise.
*/
export function jsonToString(val: JSONValue | null): string {
if (val != null && val.kind === JSONValueKind.STRING) {
return val.toString();
return val.toString()
}
return "";
return ""
}

/**
Expand All @@ -18,13 +18,12 @@ export function jsonToString(val: JSONValue | null): string {
*/
export function jsonToArrayString(val: JSONValue | null): Array<string> {
if (val != null && val.kind === JSONValueKind.ARRAY) {
let valArray = val.toArray();
let result: Array<string> = new Array();
let valArray = val.toArray()
let result: Array<string> = new Array()
for (let i = 0; i < valArray.length; i++) {
if (valArray[i].kind === JSONValueKind.STRING)
result.push(valArray[i].toString());
if (valArray[i].kind === JSONValueKind.STRING) result.push(valArray[i].toString())
}
return result;
return result
}
return [];
return []
}
62 changes: 60 additions & 2 deletions packages/subgraph/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@
dependencies:
assemblyscript "0.19.10"

"@graphprotocol/graph-ts@^0.24.1":
version "0.24.1"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.24.1.tgz#50961b52b5383f9c5cf5e6e23fa039f24e729ddf"
integrity sha512-2vU4m5ZPQIqMlMce/z5vmOtGHRlRmcRhMfemS3NIwxCSxSBGVnX2zb7QBTzzdQKGwsAZdbz6V0okkOtvohELfQ==
dependencies:
assemblyscript "0.19.10"

"@types/bn.js@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.0.tgz#32c5d271503a12653c62cf4d2b45e6eab8cebc68"
Expand Down Expand Up @@ -460,6 +467,15 @@ [email protected]:
binaryen "101.0.0-nightly.20210723"
long "^4.0.0"

assemblyscript@^0.19.20:
version "0.19.23"
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.19.23.tgz#16ece69f7f302161e2e736a0f6a474e6db72134c"
integrity sha512-fwOQNZVTMga5KRsfY80g7cpOl4PsFQczMwHzdtgoqLXaYhkhavufKb0sB0l3T1DUxpAufA0KNhlbpuuhZUwxMA==
dependencies:
binaryen "102.0.0-nightly.20211028"
long "^5.2.0"
source-map-support "^0.5.20"

[email protected], assert-plus@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"
Expand Down Expand Up @@ -547,6 +563,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-101.0.0-nightly.20210723.tgz#b6bb7f3501341727681a03866c0856500eec3740"
integrity sha512-eioJNqhHlkguVSbblHOtLqlhtC882SOEPKmNFZaDuz1hzQjolxZ+eu3/kaS10n3sGPONsIZsO7R9fR00UyhEUA==

[email protected]:
version "102.0.0-nightly.20211028"
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-102.0.0-nightly.20211028.tgz#8f1efb0920afd34509e342e37f84313ec936afb2"
integrity sha512-GCJBVB5exbxzzvyt8MGDv/MeUjs6gkXDvf4xOIItRBptYl0Tz5sm1o/uG95YK0L0VeG5ajDu3hRtkBP2kzqC5w==

bindings@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
Expand Down Expand Up @@ -1390,9 +1411,9 @@ glob@^7.1.3:
once "^1.3.0"
path-is-absolute "^1.0.0"

"gluegun@git+https://github.com/edgeandnode/gluegun.git#v4.3.1-pin-colors-dep":
"gluegun@https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep":
version "4.3.1"
resolved "git+https://github.com/edgeandnode/gluegun.git#b34b9003d7bf556836da41b57ef36eb21570620a"
resolved "https://github.com/edgeandnode/gluegun#b34b9003d7bf556836da41b57ef36eb21570620a"
dependencies:
apisauce "^1.0.1"
app-module-path "^2.2.0"
Expand Down Expand Up @@ -2108,6 +2129,11 @@ long@^4.0.0:
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==

long@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/long/-/long-5.2.0.tgz#2696dadf4b4da2ce3f6f6b89186085d94d52fd61"
integrity sha512-9RTUNjK60eJbx3uz+TEGF7fUr29ZDxR5QzXcyDpeSfeH28S9ycINflOgOlppit5U+4kNTe83KQnMEerw7GmE8w==

looper@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/looper/-/looper-3.0.0.tgz#2efa54c3b1cbaba9b94aee2e5914b0be57fbb749"
Expand Down Expand Up @@ -2141,6 +2167,15 @@ mafmt@^7.0.0:
dependencies:
multiaddr "^7.3.0"

matchstick-as@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/matchstick-as/-/matchstick-as-0.4.0.tgz#7456c2f20abee6d12366b65f4216385a9ef62a50"
integrity sha512-XkWoXQWUg1ms8DaDMkl2M95woGPB89f7aysjwDNst/x+G9FV48dxcAKSwilJ1BVGV3MqU7HfuKGHxegSsuxQxQ==
dependencies:
"@graphprotocol/graph-ts" "^0.24.1"
assemblyscript "^0.19.20"
wabt "1.0.24"

md5.js@^1.3.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"
Expand Down Expand Up @@ -2602,6 +2637,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

prettier@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a"
integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==

process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
Expand Down Expand Up @@ -2948,6 +2988,19 @@ signed-varint@^2.0.1:
dependencies:
varint "~5.0.0"

source-map-support@^0.5.20:
version "0.5.21"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

split-ca@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/split-ca/-/split-ca-1.0.1.tgz#6c83aff3692fa61256e0cd197e05e9de157691a6"
Expand Down Expand Up @@ -3272,6 +3325,11 @@ [email protected]:
core-util-is "1.0.2"
extsprintf "^1.2.0"

[email protected]:
version "1.0.24"
resolved "https://registry.yarnpkg.com/wabt/-/wabt-1.0.24.tgz#c02e0b5b4503b94feaf4a30a426ef01c1bea7c6c"
integrity sha512-8l7sIOd3i5GWfTWciPL0+ff/FK/deVK2Q6FN+MPz4vfUcD78i2M/49XJTwF6aml91uIiuXJEsLKWMB2cw/mtKg==

wcwidth@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ history@^5.2.0:
dependencies:
"@babel/runtime" "^7.7.6"

[email protected]:
version "5.1.3"
resolved "https://registry.yarnpkg.com/husky/-/husky-5.1.3.tgz#1a0645a4fe3ffc006c4d0d8bd0bcb4c98787cc9d"
integrity sha512-fbNJ+Gz5wx2LIBtMweJNY1D7Uc8p1XERi5KNRMccwfQA+rXlxWNSdUxswo0gT8XqxywTIw7Ywm/F4v/O35RdMg==

inflight@^1.0.4:
version "1.0.6"
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
Expand Down

0 comments on commit 74f33e4

Please sign in to comment.