Repository: braydenwerner/Wern-Fullstack-Template Branch: master Commit: 32d7b7111699 Files: 69 Total size: 48.3 KB Directory structure: gitextract_cbg5532v/ ├── .prettierrc.js ├── LICENSE ├── README.md ├── client/ │ ├── .babelrc │ ├── .eslintignore │ ├── .eslintrc.js │ ├── .gitignore │ ├── codegen.yml │ ├── next-env.d.ts │ ├── package.json │ ├── src/ │ │ ├── components/ │ │ │ ├── Components.txt │ │ │ ├── elements/ │ │ │ │ ├── Nav/ │ │ │ │ │ └── Nav.tsx │ │ │ │ ├── ThemeToggle/ │ │ │ │ │ ├── ThemeToggle.styled.ts │ │ │ │ │ └── ThemeToggle.tsx │ │ │ │ └── index.ts │ │ │ └── modules/ │ │ │ └── index.ts │ │ ├── config/ │ │ │ └── config.ts │ │ ├── generated/ │ │ │ └── graphql.tsx │ │ ├── graphql/ │ │ │ ├── mutations/ │ │ │ │ └── createUser.graphql │ │ │ └── queries/ │ │ │ ├── getUser.graphql │ │ │ └── getUsers.graphql │ │ ├── hooks/ │ │ │ └── useMediaQuery.ts │ │ ├── pages/ │ │ │ ├── 404.tsx │ │ │ ├── _app.tsx │ │ │ ├── _document.tsx │ │ │ ├── api/ │ │ │ │ └── hello.ts │ │ │ └── index.tsx │ │ ├── providers/ │ │ │ └── AppProvider.tsx │ │ ├── styles/ │ │ │ ├── constantStyles.ts │ │ │ ├── global.ts │ │ │ ├── index.ts │ │ │ ├── styled.d.ts │ │ │ └── theme.ts │ │ └── util/ │ │ ├── createURQLClient.ts │ │ └── isServer.ts │ └── tsconfig.json └── server/ ├── .dockerignore ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── Dockerfile ├── dist/ │ ├── config.js │ ├── entities/ │ │ ├── UserAccount.js │ │ └── index.js │ ├── index.js │ ├── middleware/ │ │ └── isAuth.js │ ├── migrations/ │ │ ├── 1622333914717-initDB.js │ │ └── 1622348668437-MockUsers.js │ ├── resolvers/ │ │ ├── UserAccount.js │ │ ├── index.js │ │ └── userInput.js │ ├── types.js │ └── utils/ │ └── validateRegister.js ├── ormconfig.json ├── package.json ├── src/ │ ├── config.ts │ ├── entities/ │ │ ├── UserAccount.ts │ │ └── index.ts │ ├── env.d.ts │ ├── index.ts │ ├── middleware/ │ │ └── isAuth.ts │ ├── migrations/ │ │ ├── 1622333914717-initDB.ts │ │ └── 1622348668437-MockUsers.ts │ ├── resolvers/ │ │ ├── UserAccount.ts │ │ ├── index.ts │ │ └── userInput.ts │ ├── types.ts │ └── utils/ │ └── validateRegister.ts └── tsconfig.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .prettierrc.js ================================================ module.exports = { trailingComma: 'es5', tabWidth: 2, singleQuote: true, arrowParens: 'always', useTabs: false, semi: false, } ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2020 Brayden Werner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================

phone-rig-image

### This repo is inspired by https://github.com/benawad/lireddit
## Features Include: - Server-side rendered data from postgres - Create user graphql mutation with password encryption - Get users/user graphql query - Light/dark theme support and switch component
## Uses the following technologies: - React - Next.js - MaterialUI - Styled-Components - TypeGraphQL - URQL - ApolloServer(express) - TypeORM - PostgresSQL - Node.js - TypeScript
## Running Locally: ### Client: ``` npm install npm run dev ``` ### Server: (You must have a postgreSQL database running and update the DATABASE_URL in server/.env if you wish to add database functionality) ### A migration to create the users table can be found in server/src/migrations. To run it, uncomment the following line in server/src/index.ts
``` await conn.runMigrations() ``` ``` npm install npm run build npm run dev2 ```
## Folder Structure ```bash ├── client │   └── src │   ├── components │   │   ├── elements │   │   └── modules │   ├── config │   ├── generated │   ├── graphql │   │   ├── fragments │   │   ├── mutations │   │   └── queries │   ├── hooks │   ├── pages │   │   └── api │   ├── providers │   ├── public │   │   ├── fonts │   │   └── images │   ├── styles │   └── util └── server ├── dist │   ├── entities │   ├── middleware │   ├── resolvers │   └── utils └── src ├── entities ├── middleware ├── migrations ├── resolvers └── utils ``` ## Hosting: ### Client: Hosted with vercel ### Server: Hosted with Heroku using PostgreSQL plugin ================================================ FILE: client/.babelrc ================================================ { "presets": ["next/babel"], "plugins": [["styled-components", { "ssr": true }]] } ================================================ FILE: client/.eslintignore ================================================ node_modules/ ================================================ FILE: client/.eslintrc.js ================================================ module.exports = { env: { browser: true, es2021: true, }, extends: [ 'eslint:recommended', 'plugin:react/recommended', 'plugin:@typescript-eslint/recommended', ], parser: '@typescript-eslint/parser', parserOptions: { ecmaFeatures: { jsx: true, }, ecmaVersion: 12, sourceType: 'module', }, plugins: ['react', '@typescript-eslint'], rules: { 'comma-dangle': 'never', 'react/react-in-jsx-scope': 'off', 'react/prop-types': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-empty-interface': 'off', }, } ================================================ FILE: client/.gitignore ================================================ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies /node_modules /.pnp .pnp.js # testing /coverage # next.js /.next/ /out/ # production /build # misc .DS_Store *.pem # debug npm-debug.log* yarn-debug.log* yarn-error.log* # local env files .env.local .env.development.local .env.test.local .env.production.local # vercel .vercel ================================================ FILE: client/codegen.yml ================================================ overwrite: true schema: 'http://localhost:4000' documents: 'src/graphql/**/*.graphql' generates: src/generated/graphql.tsx: plugins: - 'typescript' - 'typescript-operations' - 'typescript-urql' ================================================ FILE: client/next-env.d.ts ================================================ /// /// ================================================ FILE: client/package.json ================================================ { "name": "client", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "gen": "graphql-codegen --config codegen.yml" }, "dependencies": { "@material-ui/core": "^4.11.4", "graphql": "^15.5.0", "next": "10.2.2", "next-urql": "^3.1.0", "react": "17.0.2", "react-dom": "17.0.2", "react-icons": "^4.2.0", "react-switch": "^6.0.0", "styled-components": "^5.3.0", "urql": "^2.0.3" }, "devDependencies": { "@graphql-codegen/cli": "1.21.4", "@graphql-codegen/typescript": "1.22.0", "@graphql-codegen/typescript-operations": "^1.17.16", "@graphql-codegen/typescript-urql": "^2.0.6", "@types/styled-components": "^5.1.9", "@typescript-eslint/eslint-plugin": "^4.24.0", "@typescript-eslint/parser": "^4.24.0", "babel-plugin-styled-components": "^1.12.0", "eslint": "^7.27.0", "eslint-config-standard": "^16.0.2", "eslint-plugin-import": "^2.23.3", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.3.1", "eslint-plugin-react": "^7.23.2", "typescript": "^4.2.4" } } ================================================ FILE: client/src/components/Components.txt ================================================ I like to break my components up into elements and modules. An element is an invidual component that may be used in multiple places in the app. Ex: A button A module is a larger component generally consists of several elements. Ex: A navbar containing button components ================================================ FILE: client/src/components/elements/Nav/Nav.tsx ================================================ import { AppBar, Toolbar, Typography } from '@material-ui/core' export const Nav: React.FC = () => { return ( Wern Fullstack Template ) } ================================================ FILE: client/src/components/elements/ThemeToggle/ThemeToggle.styled.ts ================================================ import styled from 'styled-components' export const SwitchContainer = styled.div` position: fixed; top: 1%; right: 1%; margin: 10px 0px 0px 0px; z-index: 1; ` ================================================ FILE: client/src/components/elements/ThemeToggle/ThemeToggle.tsx ================================================ import { useContext } from 'react' import { FaMoon, FaSun } from 'react-icons/fa' import Switch from 'react-switch' import { ThemeContext } from '../../../providers/AppProvider' import { SwitchContainer } from './ThemeToggle.styled' export const ThemeToggle: React.FC = () => { const { toggleTheme, themeMode } = useContext(ThemeContext) const handleThemeChange = () => { toggleTheme() } return ( } uncheckedIcon={ } onChange={handleThemeChange} /> ) } ================================================ FILE: client/src/components/elements/index.ts ================================================ export { Nav } from './Nav/Nav' export { ThemeToggle } from './ThemeToggle/ThemeToggle' ================================================ FILE: client/src/components/modules/index.ts ================================================ export {} ================================================ FILE: client/src/config/config.ts ================================================ const dev = process.env.NODE_ENV !== 'production' export const URL = dev ? 'http://localhost:3000/api' : 'https://fullstack-wern-boilerplate.vercel.app/api' export const serverURL = dev ? 'http://localhost:4000' : 'https://wern-fullstack-template.herokuapp.com/' ================================================ FILE: client/src/generated/graphql.tsx ================================================ import gql from 'graphql-tag'; import * as Urql from 'urql'; export type Maybe = T | null; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type Omit = Pick>; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: string; String: string; Boolean: boolean; Int: number; Float: number; }; export type FieldError = { __typename?: 'FieldError'; field: Scalars['String']; message: Scalars['String']; }; export type Mutation = { __typename?: 'Mutation'; createUser: UserResponse; }; export type MutationCreateUserArgs = { options: UserInput; }; export type Query = { __typename?: 'Query'; user?: Maybe; users?: Maybe>; }; export type QueryUserArgs = { id: Scalars['String']; }; export type UserAccount = { __typename?: 'UserAccount'; id: Scalars['Float']; username: Scalars['String']; email: Scalars['String']; createdAt: Scalars['String']; updatedAt: Scalars['String']; }; export type UserInput = { email: Scalars['String']; username: Scalars['String']; password: Scalars['String']; }; export type UserResponse = { __typename?: 'UserResponse'; errors?: Maybe>; user?: Maybe; }; export type CreateUserMutationVariables = Exact<{ username: Scalars['String']; email: Scalars['String']; password: Scalars['String']; }>; export type CreateUserMutation = ( { __typename?: 'Mutation' } & { createUser: ( { __typename?: 'UserResponse' } & { errors?: Maybe )>>, user?: Maybe<( { __typename?: 'UserAccount' } & Pick )> } ) } ); export type GetUserQueryVariables = Exact<{ id: Scalars['String']; }>; export type GetUserQuery = ( { __typename?: 'Query' } & { user?: Maybe<( { __typename?: 'UserAccount' } & Pick )> } ); export type GetUsersQueryVariables = Exact<{ [key: string]: never; }>; export type GetUsersQuery = ( { __typename?: 'Query' } & { users?: Maybe )>> } ); export const CreateUserDocument = gql` mutation CreateUser($username: String!, $email: String!, $password: String!) { createUser(options: {username: $username, email: $email, password: $password}) { errors { field message } user { id username } } } `; export function useCreateUserMutation() { return Urql.useMutation(CreateUserDocument); }; export const GetUserDocument = gql` query getUser($id: String!) { user(id: $id) { id username email } } `; export function useGetUserQuery(options: Omit, 'query'> = {}) { return Urql.useQuery({ query: GetUserDocument, ...options }); }; export const GetUsersDocument = gql` query getUsers { users { id username email } } `; export function useGetUsersQuery(options: Omit, 'query'> = {}) { return Urql.useQuery({ query: GetUsersDocument, ...options }); }; ================================================ FILE: client/src/graphql/mutations/createUser.graphql ================================================ mutation CreateUser($username: String!, $email: String!, $password: String!) { createUser( options: { username: $username, email: $email, password: $password } ) { errors { field message } user { id username } } } ================================================ FILE: client/src/graphql/queries/getUser.graphql ================================================ query getUser($id: String!) { user(id: $id) { id username email } } ================================================ FILE: client/src/graphql/queries/getUsers.graphql ================================================ query getUsers { users { id username email } } ================================================ FILE: client/src/hooks/useMediaQuery.ts ================================================ import { useState, useEffect } from 'react' export function useMediaQuery(query: string) { const [matches, setMatches] = useState(false) useEffect(() => { const media = window.matchMedia(query) if (media.matches !== matches) { setMatches(media.matches) } const listener = () => setMatches(media.matches) media.addEventListener('change', listener) return () => media.removeEventListener('change', listener) }, [matches, query]) return matches } ================================================ FILE: client/src/pages/404.tsx ================================================ const Error: React.FC = () => { return
404 Error
} export default Error ================================================ FILE: client/src/pages/_app.tsx ================================================ import Head from 'next/head' import type { AppProps } from 'next/app' import { AppProvider } from '../providers/AppProvider' function MyApp({ Component, pageProps }: AppProps) { return ( <> Wern Template ) } export default MyApp ================================================ FILE: client/src/pages/_document.tsx ================================================ import React from 'react' import Document, { Html, Head, Main, NextScript } from 'next/document' import { ServerStyleSheets } from '@material-ui/core/styles' export default class MyDocument extends Document { render() { return (
) } } MyDocument.getInitialProps = async (ctx) => { const sheets = new ServerStyleSheets() const originalRenderPage = ctx.renderPage ctx.renderPage = () => originalRenderPage({ enhanceApp: (App) => (props) => sheets.collect(), }) const initialProps = await Document.getInitialProps(ctx) return { ...initialProps, styles: [ ...React.Children.toArray(initialProps.styles), sheets.getStyleElement(), ], } } ================================================ FILE: client/src/pages/api/hello.ts ================================================ export default (req: any, res: any) => { console.log(req) res.status(200).json({ name: 'John Doe' }) } ================================================ FILE: client/src/pages/index.tsx ================================================ import { withUrqlClient } from 'next-urql' import styled from 'styled-components' import { /*useGetUserQuery*/ useGetUsersQuery } from '../generated/graphql' import { Nav, ThemeToggle } from '../components/elements/index' import { createUrqlClient } from '../util/createURQLClient' import { CenterContainer, StyledGridContainer, StyledHeaderText, StyledSubText, } from '../styles/constantStyles' import { useMediaQuery } from '../hooks/useMediaQuery' const Home: React.FC = () => { const [{ data }] = useGetUsersQuery() // example query with id parameter // const [user] = useGetUserQuery({ variables: { id: '1' } }) const largerThan500px = useMediaQuery('(min-width: 775px)') return ( <>