Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex0007 committed Aug 5, 2022
1 parent dcfed83 commit 121197f
Show file tree
Hide file tree
Showing 7 changed files with 5,221 additions and 0 deletions.
5,090 changes: 5,090 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions package.json
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"
]
}
}
5 changes: 5 additions & 0 deletions src/ExampleResolver.ts
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() {}
47 changes: 47 additions & 0 deletions src/index.ts
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();
16 changes: 16 additions & 0 deletions src/object-types.ts
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;
}
16 changes: 16 additions & 0 deletions src/utils.ts
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;
}
13 changes: 13 additions & 0 deletions tsconfig.json
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"]
}

0 comments on commit 121197f

Please sign in to comment.