-
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(common): refactoring adapter and centralize code
- Loading branch information
Showing
37 changed files
with
541 additions
and
428 deletions.
There are no files selected for viewing
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
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
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
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
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
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,46 @@ | ||
import {$log} from "@tsed/common"; | ||
import {PlatformExpress} from "@tsed/platform-express"; | ||
import session from "express-session"; | ||
import {Server} from "./Server"; | ||
import bodyParser from "body-parser"; | ||
import cookieParser from "cookie-parser"; | ||
import compress from "compression"; | ||
import methodOverride from "method-override"; | ||
|
||
if (process.env.NODE_ENV !== "test") { | ||
async function bootstrap() { | ||
try { | ||
const platform = await PlatformExpress.bootstrap(Server, { | ||
port: 8082, | ||
middlewares: [ | ||
bodyParser.urlencoded({ | ||
extended: true | ||
}), | ||
bodyParser.json(), | ||
cookieParser(), | ||
compress({}), | ||
methodOverride(), | ||
session({ | ||
secret: "mysecretkey", | ||
resave: true, | ||
saveUninitialized: true, | ||
// maxAge: 36000, | ||
cookie: { | ||
path: "/", | ||
httpOnly: true, | ||
secure: false | ||
} | ||
}) | ||
] | ||
}); | ||
|
||
await platform.listen(); | ||
$log.debug("Server initialized"); | ||
} catch (er) { | ||
console.error(er); | ||
$log.error(er); | ||
} | ||
} | ||
|
||
bootstrap(); | ||
} |
9 changes: 7 additions & 2 deletions
9
...ges/graphql/typegraphql/test/app/index.ts → ...graphql/typegraphql/test/app/index.koa.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
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,73 @@ | ||
import {ApolloServer, gql} from "apollo-server-koa"; | ||
import {ApolloServerPluginDrainHttpServer} from "apollo-server-core"; | ||
import Koa from "koa"; | ||
import KoaRouter from "@koa/router"; | ||
import http from "http"; | ||
|
||
const app = new Koa(); | ||
const mainRouter = new KoaRouter(); | ||
const httpServer = http.createServer(); | ||
|
||
async function startApolloServer({typeDefs, resolvers}) { | ||
const server = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
plugins: [ApolloServerPluginDrainHttpServer({httpServer})] | ||
}); | ||
|
||
await server.start(); | ||
|
||
const router = new KoaRouter(); | ||
const middlewares = server.getMiddleware({path: "/graphql", app: router}); | ||
|
||
return {server, middlewares: middlewares}; | ||
} | ||
|
||
const books = [ | ||
{ | ||
title: "The Awakening", | ||
author: "Kate Chopin" | ||
}, | ||
{ | ||
title: "City of Glass", | ||
author: "Paul Auster" | ||
} | ||
]; | ||
|
||
const resolvers = { | ||
Query: { | ||
books: () => books | ||
} | ||
}; | ||
|
||
const typeDefs = gql` | ||
# Comments in GraphQL strings (such as this one) start with the hash (#) symbol. | ||
# This "Book" type defines the queryable fields for every book in our data source. | ||
type Book { | ||
title: String | ||
author: String | ||
} | ||
# The "Query" type is special: it lists all of the available queries that | ||
# clients can execute, along with the return type for each. In this | ||
# case, the "books" query returns an array of zero or more Books (defined above). | ||
type Query { | ||
books: [Book] | ||
} | ||
`; | ||
|
||
startApolloServer({ | ||
typeDefs, | ||
app, | ||
resolvers | ||
}).then(async ({middlewares, server}) => { | ||
app.use(middlewares); | ||
app.listen(3000); | ||
|
||
httpServer.on("request", app.callback()); | ||
|
||
await new Promise((resolve) => httpServer.listen({port: 4000}, resolve)); | ||
|
||
console.log(`🚀 Server ready at http://localhost:3000${server.graphqlPath}`); | ||
}); |
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,6 @@ | ||
{ | ||
"type": "module", | ||
"scripts": { | ||
"start:koa": "node koa.js" | ||
} | ||
} |
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
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
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
21 changes: 0 additions & 21 deletions
21
packages/platform/common/src/interfaces/PlatformAdapter.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.