Skip to content

Instantly share code, notes, and snippets.

@statico
Created March 4, 2020 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statico/c4caf12561c4b65b9f31a44349a0b467 to your computer and use it in GitHub Desktop.
Save statico/c4caf12561c4b65b9f31a44349a0b467 to your computer and use it in GitHub Desktop.
TypeScript + Apollo monorepo config
.DS_Store
.env
.vscode
Dockerfile
docker-compose.yml
frontend/.next
frontned/out/
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
schema:
- ./schema.graphql
# Apollo-Server puts Upload in the schema, but it can't be in the .graphql file.
# https://github.com/dotansimha/graphql-code-generator/issues/1073
- |
scalar Upload
overwrite: true
header: &header "\n
/****************************************************/\n
/*********** GENERATED FILE - DO NOT EDIT ***********/\n
/****************************************************/\n
\n
// tslint:disable: interface-over-type-literal array-type no-implicit-dependencies"
generates:
./backend/types.ts:
plugins:
- add: *header
- typescript
- typescript-resolvers
./frontend/types.tsx:
documents:
- ./frontend/{components,lib,pages}/**/*.{ts,tsx}
plugins:
- add: *header
- typescript
- typescript-operations
- typescript-react-apollo
config:
skipTypename: true
version: '3.7'
services:
backend:
build:
context: .
target: backend
env_file: .env
ports:
- '5000:5000'
restart: always
frontend:
build:
context: .
target: frontend
env_file: .env
ports:
- '8080:8080'
restart: always
# Remember that additional env vars can be in a .env, which docker-compose
# uses when building the image.
FROM node:12-alpine AS base
VOLUME /usr/local/share/.cache/yarn
COPY ./ /app/
WORKDIR /app/
RUN npm install --silent --global yarn
RUN yarn install --pure-lockfile --non-interactive
FROM base AS frontend
ENV NODE_ENV=production
WORKDIR /app/frontend/
RUN yarn global add http-server
RUN yarn run build
EXPOSE 8080/tcp
CMD cd out && http-server
FROM base AS backend
ENV NODE_ENV=production
WORKDIR /app/backend/
CMD yarn run start
EXPOSE 5000/tcp
{
"private": true,
"workspaces": [
"backend",
"frontend",
"common"
],
"scripts": {
"lint": "tslint --project .",
"lint:fix": "tslint --fix --project .",
"build-types": "gql-gen",
"watch-types": "nodemon -e graphql,yml,ts -w schema.graphql -w codegen.yml -w frontend/lib -x gql-gen"
},
"dependencies": {
"@graphql-codegen/add": "^1",
"@graphql-codegen/cli": "^1",
"@graphql-codegen/typescript": "^1",
"@graphql-codegen/typescript-operations": "^1",
"@graphql-codegen/typescript-react-apollo": "^1",
"@graphql-codegen/typescript-resolvers": "^1",
"graphql": "^14",
"graphql-tag": "^2.10.1",
"ts-node": "^8",
"typescript": "^3.6"
},
"devDependencies": {
"@types/graphql": "^14.5.0",
"husky": "^3.0.4",
"lint-staged": "^9.2.5",
"nodemon": "*",
"prettier": "^1.18.2",
"tslint": "^5.19.0",
"tslint-config-prettier": "^1.18.0"
},
"husky": {
"hooks": {
"pre-commit": "tsc --noEmit && lint-staged"
}
},
"lint-staged": {
"*.{js,json,css,md}": [
"prettier --write",
"git add"
],
"*.{ts,tsx}": [
"tslint --fix",
"prettier --write --parser=typescript",
"git add"
]
}
}
type User {
id: ID!
username: String!
}
type LogInResponse {
success: Boolean!
error: String
token: String
}
type Query {
me: User
}
type Mutation {
login(username: String!, password: String!): LogInResponse
}
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"jsx": "react",
"strict": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"exclude": ["node_modules", "frontend/node_modules", "backend/node_modules"]
}
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"interface-name": [true, "never-prefix"],
"object-literal-sort-keys": false,
"no-implicit-dependencies": [true, "dev"],
"no-submodule-imports": false,
"max-classes-per-file": false
},
"linterOptions": {
"exclude": [
"node_modules/**",
"**/node_modules/**",
"**/*.d.ts",
"**/*.json",
"graphql/generated/types.ts"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment