Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information...
goldcaddy77 committed Jul 26, 2018
0 parents commit 760602d46d950789592cc1b5caae01b53df048e2
Showing with 15,035 additions and 0 deletions.
  1. +29 −0 .circleci/config.yml
  2. +15 −0 .editorconfig
  3. +17 −0 .gitignore
  4. +14 −0 .markdownlint.json
  5. +1 −0 .npmrc
  6. +1 −0 .nvmrc
  7. +28 −0 .vscode/launch.json
  8. +18 −0 .vscode/settings.json
  9. +20 −0 .vscode/tasks.json
  10. +21 −0 LICENSE
  11. +38 −0 README.md
  12. +5 −0 examples/1-simple-seed/.env
  13. +3 −0 examples/1-simple-seed/.gitignore
  14. +14 −0 examples/1-simple-seed/.graphqlconfig.yml
  15. +20 −0 examples/1-simple-seed/README.md
  16. +1 −0 examples/1-simple-seed/generated/index.ts
  17. +12 −0 examples/1-simple-seed/generated/schema.ts
  18. +52 −0 examples/1-simple-seed/package.json
  19. +23 −0 examples/1-simple-seed/src/app.ts
  20. +84 −0 examples/1-simple-seed/src/index.test.ts
  21. +16 −0 examples/1-simple-seed/src/index.ts
  22. +22 −0 examples/1-simple-seed/src/modules/user/user.entity.ts
  23. +60 −0 examples/1-simple-seed/src/modules/user/user.resolver.ts
  24. +56 −0 examples/1-simple-seed/tools/seed.ts
  25. +23 −0 examples/1-simple-seed/tsconfig.json
  26. +4,363 −0 examples/1-simple-seed/yarn.lock
  27. +3 −0 examples/README.md
  28. +137 −0 package.json
  29. +59 −0 src/core/BaseObject.ts
  30. +17 −0 src/core/Context.ts
  31. +146 −0 src/core/app.ts
  32. +61 −0 src/core/binding.ts
  33. +5 −0 src/core/index.ts
  34. +2 −0 src/core/logger.ts
  35. +20 −0 src/core/types.ts
  36. +20 −0 src/decorators/EmailField.ts
  37. +14 −0 src/decorators/EntityObject.ts
  38. +9 −0 src/decorators/ForeignKeyField.ts
  39. +40 −0 src/decorators/StringField.ts
  40. +4 −0 src/decorators/index.ts
  41. +5 −0 src/index.test.ts
  42. +7 −0 src/index.ts
  43. +45 −0 src/middleware/DataLoaderMiddleware.ts
  44. +30 −0 src/middleware/ErrorMiddleware.ts
  45. +6 −0 src/middleware/HealthMiddleware.ts
  46. +3 −0 src/middleware/index.ts
  47. +64 −0 src/schema/SchemaGenerator.ts
  48. +319 −0 src/schema/TypeORMConverter.ts
  49. +1 −0 src/schema/index.ts
  50. +194 −0 src/tgql/BaseResolver.ts
  51. +53 −0 src/tgql/BaseWhereInput.ts
  52. +19 −0 src/tgql/DeleteResponse.ts
  53. +17 −0 src/tgql/PaginationArgs.ts
  54. +17 −0 src/tgql/authChecker.ts
  55. +7 −0 src/tgql/index.ts
  56. +47 −0 src/torm/EverythingSubscriber.ts
  57. +42 −0 src/torm/SnakeNamingStrategy.ts
  58. +41 −0 src/torm/createConnection.ts
  59. +3 −0 src/torm/index.ts
  60. 0 src/torm/ormconfig.ts
  61. +9 −0 src/utils/EntityCreator.ts
  62. +21 −0 src/utils/decoratorComposer.ts
  63. +2 −0 src/utils/index.ts
  64. +25 −0 tsconfig.json
  65. +24 −0 tsconfig.test.json
  66. +26 −0 tslint.json
  67. +8,515 −0 yarn.lock
@@ -0,0 +1,29 @@
version: 2
references:
yarn_cache_key: &yarn_cache_key
yarn-v1-{{ checksum "yarn.lock" }}
jobs:
build:
docker:
- image: circleci/node:10.7
steps:
- checkout
- restore_cache:
keys:
- *yarn_cache_key
- yarn-v1-
- run:
name: dependencies
command: yarn install --frozen-lockfile
- run:
name: build
command: yarn build
- run:
name: test
command: yarn test
- run:
name: deploy
command: yarn run semantic-release || true
- save_cache:
key: *yarn_cache_key
paths: ~/circleci/node_modules
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 120

# markdown files require trailing double whitespace for newline
[*.md]
max_line_length = off
trim_trailing_whitespace = false
@@ -0,0 +1,17 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Coverage directory used by tools like istanbul
coverage

# Dependency directories
node_modules/

# Yarn Integrity file
.yarn-integrity

dist
@@ -0,0 +1,14 @@
{
"MD009": {
"br_spaces": 2
},
"MD013": {
"code_blocks": false
},
"MD026": {
"punctuation": ".,;:"
},
"MD029": {
"style": "ordered"
}
}
1 .npmrc
@@ -0,0 +1 @@
registry=https://registry.npmjs.org
1 .nvmrc
@@ -0,0 +1 @@
10
@@ -0,0 +1,28 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Jest",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js",
"stopOnEntry": false,
"args": ["--runInBand", "${file}"],
"cwd": "${workspaceRoot}",
"protocol": "legacy",
"runtimeArgs": ["--nolazy"],
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/dist/**/*.js"]
},
{
"name": "Run from index.ts",
"type": "node",
"request": "launch",
"args": ["src/index.ts"],
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector"
}
]
}
@@ -0,0 +1,18 @@
{
"prettier.printWidth": 120,
"prettier.singleQuote": true,
"typescript.tsdk": "./node_modules/typescript/lib",
"search.exclude": {
"dist/": true,
"node_modules/": true
},
"[javascript]": {
"editor.formatOnSave": true
},
"[json]": {
"editor.formatOnSave": true
},
"[typescript]": {
"editor.formatOnSave": true
}
}
@@ -0,0 +1,20 @@
{
"version": "2.0.0",
"tasks": [
{
"command": "source tools/environment_setup.sh",
"type": "shell",
"label": "setupEnvironment"
},
{
"label": "build",
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": ["$tsc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
21 LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Dan Caddigan

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.
@@ -0,0 +1,38 @@
# warthog

[![npm version](https://img.shields.io/npm/v/warthog.svg)](https://www.npmjs.org/package/warthog)
[![CircleCI](https://circleci.com/gh/goldcaddy77/warthog/tree/master.svg?style=shield)](https://circleci.com/gh/goldcaddy77/warthog/tree/master)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](#badge)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

## Warthog

Opinionated framework for building GraphQL APIs with strong conventions.

## Install

```bash
yarn add warthog
```

## Usage

Check out the [examples folder](https://github.com/goldcaddy77/warthog/tree/v1/examples)
to see how to use Warthog in a project or check out the
[warthog example](https://github.com/goldcaddy77/warthog-example) project.


## Contribute

PRs accepted, fire away! Or add issues if you have use cases Warthog doesn't cover.

## License

MIT © Dan Caddigan

- Apollo Server 2 (running express)
- TypeORM
- TypeGraphQL
- GraphQL Bindings

Note: requires use of Postgres currently
@@ -0,0 +1,5 @@
APP_HOST=localhost
APP_PORT=4100
TYPEORM_DATABASE=example1
TYPEORM_USERNAME=postgres
TYPEORM_PASSWORD=
@@ -0,0 +1,3 @@
generated/*
!generated/index.ts
!generated/schema.ts
@@ -0,0 +1,14 @@
schemaPath: generated/schema.graphql
extensions:
endpoints:
default:
url: http://${env:APP_HOST}/graphql
headers:
Authorization: "Bearer ${env:GITHUB_TOKEN}"
codegen:
generator: graphql-binding
language: typescript
input:
schema: generated/schema.js
output:
binding: generated/generated-binding.ts
@@ -0,0 +1,20 @@
# Example 1 - User

## TLDR

Run `yarn bootstrap && yarn start`

## Bootstrapping the App

Running `yarn bootstrap` will do the following:

- Install packages
- Create the example DB
- Seed the database with test data

## Running the App

To run the project, run `yarn start`. This will:

- Run the API server
- Open GraphQL Playground
@@ -0,0 +1 @@
export * from './classes';
@@ -0,0 +1,12 @@
import * as fs from 'fs';
import { makeExecutableSchema } from 'graphql-tools';
import { GraphQLSchema } from 'graphql';

const schema: GraphQLSchema = makeExecutableSchema({
typeDefs: fs.readFileSync(__dirname + '/schema.graphql', 'utf-8'),
resolverValidationOptions: {
requireResolversForResolveType: false
}
});

export default schema;
@@ -0,0 +1,52 @@
{
"name": "example1",
"version": "0.0.0",
"scripts": {
"//": "make sure to install top-level packages, too",
"bootstrap": "cd ../.. && yarn && cd - && yarn && yarn db:create && yarn generate:binding && yarn db:seed:dev",
"db:create": "createdbjs $(dotenv -p TYPEORM_DATABASE) 2>&1 || :",
"db:drop": "dropdbjs $(dotenv -p TYPEORM_DATABASE) 2>&1 || :",
"db:seed:dev": "dotenv -- ts-node tools/seed.ts",
"generate:binding": "yarn graphql-binding --input generated/schema.ts --language typescript --outputBinding generated/binding.ts",
"playground:open": "open http://localhost:$(dotenv -p APP_PORT)/playground",
"start": "npm-run-all --parallel start:ts playground:open",
"start:debug": "yarn start:ts --inspect",
"start:ts": "ts-node --type-check src/index.ts",
"typeorm:cli": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js -f ./ormconfig",
"test": "dotenv -- jest",
"watch:ts": "nodemon -e ts,graphql -x ts-node --type-check src/index.ts"
},
"dependencies": {
"pgtools": "^0.3.0",
"reflect-metadata": "^0.1.12",
"typescript": "^3.2.2"
},
"devDependencies": {
"@types/express": "^4.16.0",
"@types/faker": "^4.1.4",
"@types/isomorphic-fetch": "^0.0.34",
"@types/jest": "^23.3.11",
"@types/node": "^10.12.18",
"dotenv-cli": "^1.4.0",
"faker": "^4.1.0",
"graphql-binding": "^2.3.8",
"jest": "^23.6.0",
"npm-run-all": "^4.1.5",
"ts-jest": "^23.10.5",
"ts-node": "^7.0.1"
},
"jest": {
"transform": {
".ts": "ts-jest"
},
"testRegex": "\\.test\\.ts$",
"moduleFileExtensions": [
"ts",
"js"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"\\.test\\.ts$"
]
}
}
@@ -0,0 +1,23 @@
import 'reflect-metadata';

import { Container } from 'typedi';
import { App, AppOptions } from '../../../src/';

// import { User } from './modules/user/user.entity';

export function getApp(appOptions: Partial<AppOptions> = {}, dbOptions: any = {}) {
return new App(
// Path written in generated classes
{
container: Container,
warthogImportPath: '../../../src',
...appOptions
},
{
cache: true,
synchronize: true,
// dropSchema: true,
...dbOptions
}
);
}

0 comments on commit 760602d

Please sign in to comment.
You can’t perform that action at this time.