-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples): clean up examples (#17)
- Loading branch information
1 parent
7ec77b7
commit 1575329
Showing
28 changed files
with
4,357 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Example 1 - User | ||
|
||
## Setup | ||
|
||
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 | ||
|
||
## Example Queries/Mutations | ||
|
||
You can find some examples in [examples.gql](./examples.gql) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "example1", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"//": "make sure to install top-level packages, too", | ||
"bootstrap": "cd ../.. && yarn && cd - && yarn && yarn db:create", | ||
"db:create": "createdbjs $(dotenv -p TYPEORM_DATABASE) 2>&1 || :", | ||
"db:drop": "dropdbjs $(dotenv -p TYPEORM_DATABASE) 2>&1 || :", | ||
"playground:open": "open http://localhost:$(dotenv -p APP_PORT)/graphql", | ||
"start": "npm-run-all --parallel start:ts playground:open", | ||
"start:ts": "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", | ||
"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$" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
query { | ||
users(orderBy: createdAt_DESC) { | ||
id | ||
lastName | ||
createdAt | ||
} | ||
} | ||
|
||
mutation { | ||
createUser(data: { firstName: "Test", email: "test@fakeemail.com" }) { | ||
id | ||
firstName | ||
lastName | ||
createdAt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'reflect-metadata'; | ||
import * as dotenv from 'dotenv'; | ||
import { Container } from 'typedi'; | ||
|
||
dotenv.config(); | ||
|
||
import { App } from '../../../src/'; | ||
|
||
async function bootstrap() { | ||
const app = new App( | ||
// Path written in generated classes | ||
{ | ||
container: Container, | ||
warthogImportPath: '../../../src' | ||
}, | ||
{ | ||
cache: true, | ||
synchronize: true | ||
} | ||
); | ||
|
||
await app.start(); | ||
} | ||
|
||
bootstrap().catch((error: Error) => { | ||
console.error(error); | ||
if (error.stack) { | ||
console.error(error.stack!.split('\n')); | ||
} | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { BaseModel, EmailField, Model, StringField } from '../../../src'; | ||
|
||
@Model() | ||
export class User extends BaseModel { | ||
@StringField() | ||
firstName?: string; | ||
|
||
@StringField({ nullable: true }) | ||
lastName?: string; | ||
|
||
@EmailField() | ||
email?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
import { Arg, Args, Ctx, Mutation, Query, Resolver } from 'type-graphql'; | ||
import { Repository } from 'typeorm'; | ||
import { InjectRepository } from 'typeorm-typedi-extensions'; | ||
|
||
import { BaseResolver, Context, StandardDeleteResponse } from '../../../src'; | ||
import { UserCreateInput, UserUpdateArgs, UserWhereArgs, UserWhereInput, UserWhereUniqueInput } from '../generated'; | ||
|
||
import { User } from './user.entity'; | ||
|
||
// Note: we have to specify `User` here instead of (of => User) because for some reason this | ||
// changes the object reference when it's trying to add the FieldResolver and things break | ||
@Resolver(User) | ||
export class UserResolver extends BaseResolver<User> { | ||
constructor(@InjectRepository(User) private readonly userRepository: Repository<User>) { | ||
super(User, userRepository); | ||
} | ||
|
||
@Query(returns => [User]) | ||
async users( | ||
@Args() { where, orderBy, limit, offset }: UserWhereArgs, | ||
@Ctx() ctx: Context, | ||
info: GraphQLResolveInfo | ||
): Promise<User[]> { | ||
return this.find<UserWhereInput>(where, orderBy, limit, offset); | ||
} | ||
|
||
@Query(returns => User) | ||
async user(@Arg('where') where: UserWhereUniqueInput): Promise<User> { | ||
return this.findOne<UserWhereUniqueInput>(where); | ||
} | ||
|
||
@Mutation(returns => User) | ||
async createUser(@Arg('data') data: UserCreateInput, @Ctx() ctx: Context): Promise<User> { | ||
return this.create(data, ctx.user.id); | ||
} | ||
|
||
@Mutation(returns => User) | ||
async updateUser(@Args() { data, where }: UserUpdateArgs, @Ctx() ctx: Context): Promise<User> { | ||
return this.update(data, where, ctx.user.id); | ||
} | ||
|
||
@Mutation(returns => StandardDeleteResponse) | ||
async deleteUser(@Arg('where') where: UserWhereUniqueInput, @Ctx() ctx: Context): Promise<StandardDeleteResponse> { | ||
return this.delete(where, ctx.user.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
APP_HOST=localhost | ||
APP_PORT=4100 | ||
TYPEORM_DATABASE=example1 | ||
TYPEORM_USERNAME=postgres | ||
TYPEORM_PASSWORD= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
generated/* | ||
!generated/index.ts | ||
!generated/schema.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './classes'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowSyntheticDefaultImports": true, | ||
"baseUrl": "src", | ||
"lib": ["dom", "es5", "es6", "es7", "esnext", "esnext.asynciterable"], | ||
"target": "es5", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"sourceMap": true, | ||
"keyofStringsOnly": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noUnusedLocals": false, // Avoid noise in our resolvers when we use DI | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"types": ["jest", "isomorphic-fetch", "node"] | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules/**/*"] | ||
} |
Oops, something went wrong.