Skip to content

Commit 7116985

Browse files
authored
refactor: use react-query instead (#108)
* fix: hide env * feat: use translation for seo * fix: downgrade graphql-tools * fix: redirect to current look when changing locale * test: update test with intl * ci: added .env to cache * ci(perf): added a build step to lhci * refactor: remove apollo client * fix: update env
1 parent 9b32644 commit 7116985

35 files changed

+368
-367
lines changed

.env.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ HOSTNAME=localhost
22
PORT=3000
33
# https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser
44
NEXT_PUBLIC_HOST=http://$HOSTNAME:$PORT
5+
NEXT_PUBLIC_GRAPHQL_ENDPOINT=/api/graphql
56
# You can start with this url, but you may need to configure your own database as this is only an example with a read only user !
67
DATABASE_URL=postgresql://baby_kirby:1234@kirby.cgqxnhhl7oal.eu-west-3.rds.amazonaws.com:5432/kirby?schema=public
7-
GRAPHQL_ENDPOINT=http://localhost:3000/api/graphql
8+

.github/workflows/tests.yml

+10
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
.next
9797
node_modules
9898
~/.cache/Cypress
99+
.env
99100
key: ${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}
100101
restore-keys: |
101102
${{ runner.os }}-node_modules-
@@ -109,6 +110,9 @@ jobs:
109110
if: steps.yarn-build-cache.outputs.cache-hit != 'true'
110111
run: yarn install
111112

113+
- name: Populate env
114+
run: cp .env.example .env
115+
112116
- name: Build
113117
run: yarn build
114118

@@ -134,6 +138,7 @@ jobs:
134138
.next
135139
node_modules
136140
~/.cache/Cypress
141+
.env
137142
key: ${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}
138143
restore-keys: |
139144
${{ runner.os }}-build-
@@ -147,6 +152,10 @@ jobs:
147152
if: steps.yarn-build-cache.outputs.cache-hit != 'true'
148153
run: yarn install
149154

155+
- name: Build
156+
if: steps.yarn-build-cache.outputs.cache-hit != 'true'
157+
run: yarn build
158+
150159
- name: Install Lhci
151160
run: npm install -g @lhci/cli@0.8.x
152161

@@ -169,6 +178,7 @@ jobs:
169178
.next
170179
node_modules
171180
~/.cache/Cypress
181+
.env
172182
key: ${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}
173183
restore-keys: |
174184
${{ runner.os }}-build-

README.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,21 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the
7171
This project is build with :
7272

7373
- [NextJs](https://nextjs.org/)
74+
- [React-Query](https://react-query.tanstack.com/)
7475
- [Apollo](https://www.apollographql.com/)
75-
- [prisma](https://www.prisma.io/)
76+
- [Prisma](https://www.prisma.io/)
7677
- [Tailwindcss](https://tailwindcss.com/)
7778
- [Typescript](https://www.typescriptlang.org/)
78-
- [react-intl](https://formatjs.io/)
79+
- [React-Intl](https://formatjs.io/)
7980
- [Jest](https://jestjs.io/)
80-
- [storybook](https://storybook.js.org/)
81+
- [Storybook](https://storybook.js.org/)
8182
- [Cypress](https://www.cypress.io/)
8283
- [Prettier](https://prettier.io/)
8384
- [Eslint](https://eslint.org/)
84-
- [husky](https://typicode.github.io/husky/#/)
85-
- [commitlint](https://commitlint.js.org/#/)
86-
- [standard-version](https://github.com/conventional-changelog/standard-version)
87-
- [vscode](https://code.visualstudio.com/)
85+
- [Husky](https://typicode.github.io/husky/#/)
86+
- [Commitlint](https://commitlint.js.org/#/)
87+
- [Standard-Version](https://github.com/conventional-changelog/standard-version)
88+
- [Vscode](https://code.visualstudio.com/)
8889

8990
## Tests
9091

@@ -144,6 +145,10 @@ With the graphql endpoint running launch `yarn codegen`, this will create a typi
144145

145146
Kirby use [vercel](https://vercel.com/docs) however you can use any other hosting service.
146147

148+
In order to not populate `.env` and still being able to deploy we are using [vercel-env](https://vercel.com/docs/concepts/projects/environment-variables).
149+
150+
You need to add both `NEXT_PUBLIC_GRAPHQL_ENDPOINT` and `DATABASE_URL` to have a sucessfull deployment on vercel.
151+
147152
## Roadmap:
148153

149154
(Would love Pull requests that build towards these objectives)

apollo/client.ts

-57
This file was deleted.

apollo/schema.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { makeExecutableSchema } from '@graphql-tools/schema';
2-
31
import typeDefs from './type-defs';
42
import resolvers from './resolvers';
53

6-
export default makeExecutableSchema({
4+
export default {
75
typeDefs,
86
resolvers,
9-
});
7+
};

apollo/type-defs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { gql } from '@apollo/client';
1+
import { gql } from 'apollo-server-micro';
22

33
export default gql`
44
type User {

codegen.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
overwrite: true
12
schema:
2-
- ${GRAPHQL_ENDPOINT}
3+
- http://${HOSTNAME}:${PORT}${GRAPHQL_ENDPOINT}
4+
documents:
5+
- './operations/**/*.ts'
36
generates:
47
./types/schema.ts:
58
plugins:
69
- typescript
10+
- typescript-operations
11+
- typescript-react-query
12+
config:
13+
fetcher: graphql-request

components/Head.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface Props {
77
description?: string;
88
}
99

10-
export default function Head({ title = SEO.title, description = SEO.description }: Props) {
10+
export default function Head({ title = SEO().title, description = SEO().description }: Props) {
1111
return (
1212
<NextHead>
1313
<title>{title}</title>

components/Layout.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useIntl } from 'react-intl';
2+
import { useRouter } from 'next/router';
23

34
import Head from 'components/Head';
45
import GithubSVG from 'components/Icons/Github';
@@ -32,11 +33,12 @@ const Header = () => {
3233

3334
const Footer = () => {
3435
const { formatDate } = useIntl();
36+
const { route } = useRouter();
3537

3638
const Langs = () => (
3739
<div className="flex justify-center space-x-1">
3840
{Object.keys(langs).map(lang => (
39-
<ButtonWithLink key={lang} locale={lang} href="/" label={lang} size="small" />
41+
<ButtonWithLink key={lang} locale={lang} href={route} label={lang} size="small" />
4042
))}
4143
</div>
4244
);

components/__tests__/Head.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe('Header', () => {
77
test('Should had default values', () => {
88
render(<Head />);
99

10-
expect(document.title).toEqual(SEO.title);
11-
expect((document.head.querySelector('meta[name=description]') as HTMLMetaElement).content).toEqual(SEO.description);
10+
expect(document.title).toEqual(SEO().title);
11+
expect((document.head.querySelector('meta[name=description]') as HTMLMetaElement).content).toEqual(SEO().description);
1212
});
1313

1414
test('Should set a custom document title', () => {

components/__tests__/Layout.test.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { render } from 'utils/customTestRender';
22
import Layout from 'components/Layout';
33

4+
jest.mock('next/router', () => ({
5+
useRouter: () => ({
6+
route: '/',
7+
}),
8+
}));
9+
410
describe('Layout', () => {
511
test('Should render a Layout element', () => {
612
const { getByText, getByTestId } = render(

hooks/__tests__/useClientQuery.test.tsx

-30
This file was deleted.

hooks/__tests__/useHasMounted.test.ts

-11
This file was deleted.

hooks/useClientQuery.ts

-16
This file was deleted.

hooks/useHasMounted.ts

-11
This file was deleted.

jest.config.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
'^components(.*)$': '<rootDir>/components/$1',
55
'^design-system(.*)$': '<rootDir>/design-system$1',
66
'^apollo(.*)$': '<rootDir>/apollo$1',
7+
'^operations(.*)$': '<rootDir>/operations$1',
78
'^types(.*)$': '<rootDir>/types$1',
89
'^pages(.*)$': '<rootDir>/pages$1',
910
'^utils(.*)$': '<rootDir>/utils$1',
@@ -20,14 +21,7 @@ module.exports = {
2021
},
2122
},
2223
},
23-
collectCoverageFrom: [
24-
'hooks/**/*.(ts|tsx)',
25-
'components/**/*.(ts|tsx)',
26-
'design-system/**/*.(ts|tsx)',
27-
'utils/**/*.(ts|tsx)',
28-
'!utils/customTestRender.(ts|tsx)',
29-
'!utils/constants.(ts|tsx)',
30-
],
24+
collectCoverageFrom: ['hooks/**/*.(ts|tsx)', 'components/**/*.(ts|tsx)', 'design-system/**/*.(ts|tsx)'],
3125
coverageThreshold: {
3226
global: {
3327
branches: 80,

langs/en.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ export default {
22
greetings: 'Hello {name} !',
33
editingMessage: 'Get started by editing',
44
githubLinkMessage: 'Follow Kirby on github !',
5+
title: 'Kirby Boilerplate',
6+
description: 'This is an opinionated boilerplate with rocking tools for front-end development.',
57
};

langs/fr.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ export default {
22
greetings: 'Bonjour {name} !',
33
editingMessage: 'Commencez par éditer',
44
githubLinkMessage: 'Suivez Kirby sur github !',
5+
title: 'Kirby Boilerplate',
6+
description:
7+
'Kirby-boilerplate est un boilerblate subjectif avec tous les derniers outils pour du developpement front-end.',
58
};

apollo/queries/viewer.ts operations/queries/viewer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { gql } from '@apollo/client';
1+
import { gql } from 'graphql-request';
22

33
export default gql`
4-
query ViewerQuery {
4+
query Viewer {
55
viewer {
66
id
77
name

0 commit comments

Comments
 (0)