Skip to content

Commit 5e3fe8a

Browse files
authored
Merge pull request #2 from symptomizer/add-linting
Add linting etc.
2 parents 9fc6aed + a3fc3d4 commit 5e3fe8a

File tree

19 files changed

+27432
-71
lines changed

19 files changed

+27432
-71
lines changed

.nvmrc

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

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"tabWidth": 2,
3+
"trailingComma": "es5"
4+
}

README.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
1-
# Getting Started with Create React App
1+
# Symptomizer
22

3-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
3+
> The frontend of Symptomizer
44
5-
## Available Scripts
5+
## Prerequisites
66

7-
In the project directory, you can run:
7+
- [Node.js](https://nodejs.org/en/)
88

9-
### `npm start`
9+
v15.6.0 is confirmed to work.
1010

11-
Runs the app in the development mode.\
12-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
## Getting Started
1312

14-
The page will reload if you make edits.\
15-
You will also see any lint errors in the console.
13+
1. `git clone [email protected]:symptomizer/frontend.git`
14+
1. `cd frontend`
15+
1. `npm i`
16+
1. `npm run build`
1617

17-
### `npm test`
18+
## Project Structure
1819

19-
Launches the test runner in the interactive watch mode.\
20-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
20+
This project is primarily a [Create React App](https://create-react-app.dev/). It uses [TypeScript](https://www.typescriptlang.org/) to aid the developer experience.
2121

22-
### `npm run build`
22+
### React App
2323

24-
Builds the app for production to the `build` folder.\
25-
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
If you only need to run the React app, you can just run `npm run start`. It auto hot-reloads so is great for developing the UI.
2625

27-
The build is minified and the filenames include the hashes.\
28-
Your app is ready to be deployed!
26+
## FAB
2927

30-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
28+
This project is enhanced as a [FAB](https://fab.dev/), which allows us to sprinkle in some server-side functionality. These plugins can be found in the `./api` folder. Right now, there's just a mock GraphQL server, but in the future, we could use this for user authorization etc.
3129

32-
### `npm run eject`
30+
## Testing
3331

34-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
32+
Pretty minimal at this point, but CRA comes with Jest testing built-in, so there's one example in `./src/App.test.tsx`.
3533

36-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
34+
### Static Testing & Linting
3735

38-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
36+
[ESLint](https://eslint.org/) comes pre-setup with CRA, and [Prettier](https://prettier.io/) is setup with [`lint-staged`](https://github.com/okonet/lint-staged) and [`husky`](https://github.com/typicode/husky) so it be run automatically when you `git commit`.
3937

40-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
38+
## Deployment
4139

42-
## Learn More
43-
44-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45-
46-
To learn React, check out the [React documentation](https://reactjs.org/).
40+
[Linc](https://linc.sh/) is setup to handle the CI/CD pipeline to build and deploy the FAB on [Cloudflare Workers](https://workers.cloudflare.com/). Preview builds happen for every commit, and anything merged into the default branch is deployed to production (currently that's [https://symptomizer.gregbrimble.workers.dev/](https://symptomizer.gregbrimble.workers.dev/), but we'll obviously get setup with a custom domain at some point).

__generated__/globalTypes.ts

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

api/graphql/schema/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import { typeDefs as scalarTypeDefs } from "./types/scalars";
44
import { typeDefs as relayTypeDefs } from "./types/relay";
55
import { typeDefs as externalSourceTypeDefs } from "./types/externalSource";
66
import { typeDefs as documentTypeDefs } from "./types/document";
7-
import { typeDefs as searchResultTypeDefs } from "./types/searchResult";
7+
import {
8+
typeDefs as searchResultTypeDefs,
9+
resolvers as searchResultResolvers,
10+
} from "./types/searchResult";
811

912
const typeDefs = gql`
1013
type Query {
11-
hello: String
14+
hello: String!
1215
}
1316
`;
1417

@@ -27,5 +30,5 @@ export const schema = makeExecutableSchema({
2730
documentTypeDefs,
2831
searchResultTypeDefs,
2932
],
30-
resolvers: [resolvers],
33+
resolvers: [resolvers, searchResultResolvers],
3134
});

api/graphql/schema/types/searchResult.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { connectionArgs } from "graphql-relay-tools";
1+
import { connectionArgs, connectionFromArray } from "graphql-relay-tools";
22
import gql from "graphql-tag";
33

44
export const typeDefs = gql`
@@ -10,3 +10,51 @@ export const typeDefs = gql`
1010
search(query: String!): SearchResult!
1111
}
1212
`;
13+
14+
const nhs = {
15+
id: "nhs",
16+
name: "NHS",
17+
description: "National Health Service",
18+
url: "https://nhs.uk/",
19+
};
20+
21+
const documents = [
22+
{
23+
id: "a",
24+
name: "A Document",
25+
description: "A Description",
26+
url: "https://a.a/",
27+
externalSource: nhs,
28+
},
29+
{
30+
id: "b",
31+
name: "B Document",
32+
description: "B Document",
33+
url: "https://b.b/",
34+
externalSource: nhs,
35+
},
36+
{
37+
id: "abba",
38+
name: "ABBA Document",
39+
description: "Swedish pop group",
40+
url: "https://ab.ba/",
41+
externalSource: nhs,
42+
},
43+
];
44+
45+
export const resolvers = {
46+
Query: {
47+
search: async (obj, { query }: { query: string }) => {
48+
return {
49+
documents: async args =>
50+
connectionFromArray(
51+
documents.filter(
52+
document =>
53+
document.name.toLowerCase().indexOf(query.toLowerCase()) > -1
54+
),
55+
args
56+
),
57+
};
58+
},
59+
},
60+
};

apollo.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
client: {
3+
service: {
4+
name: "symptomizer",
5+
locallSchemaFile: "./schema.graphql",
6+
},
7+
},
8+
};

fab.config.json5

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
dir: "build",
66
},
77
"@fab/plugin-precompile": {
8-
"./api/graphql/index.ts": {
9-
_config: "./plugin-overrides.js",
10-
},
8+
"./api/graphql/index.ts": {},
119
},
1210
"@fab/plugin-render-html": {
1311
fallback: "/index.html",
@@ -31,11 +29,5 @@
3129
// However, we recommend automatic deploys (triggered by git push)
3230
// using a service such as Linc (https://linc.sh)
3331
// • See https://fab.dev/kb/automatic-deploys for setup instructions.
34-
"cf-workers": {
35-
account_id: "@CF_WORKERS_ACCOUNT_ID",
36-
api_token: "@CF_WORKERS_API_TOKEN",
37-
workers_dev: true,
38-
script_name: "symptomizer",
39-
},
4032
},
4133
}

0 commit comments

Comments
 (0)