-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init demo for MichalLytek/type-graphql#1321
- Loading branch information
Showing
7 changed files
with
5,221 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,34 @@ | ||
{ | ||
"name": "apollo-argstype-bug", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "ts-node-dev --transpile-only src", | ||
"prepare": "npx simple-git-hooks" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"apollo-server-core": "^3.10.0", | ||
"apollo-server-express": "^3.10.0", | ||
"express": "^4.18.1", | ||
"reflect-metadata": "^0.1.13", | ||
"ts-node-dev": "^2.0.0", | ||
"type-graphql": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"lint-staged": "^13.0.3", | ||
"prettier": "^2.7.1", | ||
"simple-git-hooks": "^2.8.0" | ||
}, | ||
"simple-git-hooks": { | ||
"pre-commit": "npx lint-staged" | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts,tsx,css,md}": [ | ||
"prettier --write" | ||
] | ||
} | ||
} |
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 @@ | ||
import { Resolver } from "type-graphql"; | ||
import { makeResolverClass } from "./utils"; | ||
|
||
@Resolver() | ||
export class ExampleResolver extends makeResolverClass() {} |
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 "reflect-metadata"; | ||
import { buildSchema } from "type-graphql"; | ||
import * as express from "express"; | ||
import * as http from "http"; | ||
import { ApolloServer } from "apollo-server-express"; | ||
import { ApolloServerPluginDrainHttpServer } from "apollo-server-core"; | ||
|
||
import { ExampleResolver } from "./ExampleResolver"; | ||
|
||
const port = parseInt(process.env.PORT) || 8080; | ||
|
||
async function bootstrap() { | ||
const app = express(); | ||
const httpServer = http.createServer(app); | ||
|
||
const schema1 = await buildSchema({ | ||
resolvers: [ExampleResolver], | ||
}); | ||
|
||
const schema2 = await buildSchema({ | ||
resolvers: [ExampleResolver], | ||
}); | ||
|
||
const plugins = [ApolloServerPluginDrainHttpServer({ httpServer })]; | ||
|
||
const graphQLServer1 = new ApolloServer({ | ||
plugins, | ||
schema: schema1, | ||
}); | ||
|
||
const graphQLServer2 = new ApolloServer({ | ||
plugins, | ||
schema: schema2, | ||
}); | ||
|
||
await graphQLServer1.start(); | ||
await graphQLServer2.start(); | ||
|
||
graphQLServer1.applyMiddleware({ app, path: "/graphql1" }); | ||
graphQLServer2.applyMiddleware({ app, path: "/graphql2" }); | ||
|
||
httpServer.listen({ port }, () => { | ||
console.log(`API started on port ${port}`); | ||
}); | ||
} | ||
|
||
bootstrap(); |
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 @@ | ||
import { ArgsType, Field, Int, ObjectType } from "type-graphql"; | ||
|
||
@ArgsType() | ||
export class PaginationArgs { | ||
@Field((type) => Int, { defaultValue: 0 }) | ||
offset!: number; | ||
|
||
@Field((type) => Int) | ||
take!: number; | ||
} | ||
|
||
@ObjectType() | ||
export class Response { | ||
@Field() | ||
data: 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,16 @@ | ||
import { Resolver, Query, Args } from "type-graphql"; | ||
import { PaginationArgs, Response } from "./object-types"; | ||
|
||
export function makeResolverClass() { | ||
@Resolver((of) => Response, { isAbstract: true }) | ||
abstract class ExampleResolver { | ||
@Query((returns) => Response) | ||
async exampleQuery(@Args() args: PaginationArgs): Promise<Response> { | ||
return { | ||
data: "first resolver", | ||
}; | ||
} | ||
} | ||
|
||
return ExampleResolver; | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
// "target": "es2018", | ||
// "moduleResolution": "node", | ||
"target": "ES2019", | ||
"module": "commonjs", | ||
"outDir": "dist", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["src"] | ||
} |