Skip to content

Commit

Permalink
Merge pull request #86 from rwieruch/feat/typegraphql
Browse files Browse the repository at this point in the history
feat/typegraphql
  • Loading branch information
rwieruch authored Apr 19, 2020
2 parents 5ee0df7 + cf99c70 commit 88b697a
Show file tree
Hide file tree
Showing 81 changed files with 1,620 additions and 2,762 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@
"style": true
}
],
"babel-plugin-transform-typescript-metadata",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
}
8 changes: 0 additions & 8 deletions codegen.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
schema: http://localhost:3000/api/graphql

generates:
src/generated/server.ts:
config:
defaultMapper: any
contextType: @typeDefs/resolver#ResolverContext
useIndexSignature: true
plugins:
- typescript
- typescript-resolvers
src/generated/client.tsx:
documents: ./src/queries/*.ts
config:
Expand Down
121 changes: 104 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@sentry/browser": "^5.12.4",
"@sentry/node": "^5.12.4",
"@types/file-saver": "^2.0.1",
"@types/graphql-iso-date": "^3.3.3",
"@types/js-cookie": "^2.2.4",
"@types/lodash.invert": "^4.3.6",
"@types/lodash.omit": "^4.5.6",
Expand All @@ -47,12 +46,13 @@
"b64-to-blob": "^1.2.19",
"babel-plugin-import": "^1.13.0",
"babel-plugin-inline-import": "^3.0.0",
"babel-plugin-transform-typescript-metadata": "^0.3.0",
"class-validator": "^0.11.1",
"dotenv": "^8.2.0",
"file-saver": "^2.0.2",
"firebase": "^7.7.0",
"firebase-admin": "^8.9.1",
"graphql": "^14.5.8",
"graphql-iso-date": "^3.6.1",
"graphql-middleware": "^4.0.2",
"graphql-middleware-sentry": "^3.2.1",
"graphql-shield": "^7.0.9",
Expand Down Expand Up @@ -84,10 +84,12 @@
"reflect-metadata": "^0.1.13",
"stripe": "^8.7.0",
"styled-components": "^5.0.0",
"type-graphql": "^0.18.0-beta.16",
"typeorm": "^0.2.24"
},
"devDependencies": {
"@apollo/react-testing": "^3.1.3",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@graphql-codegen/add": "^1.12.1",
"@graphql-codegen/cli": "^1.12.1",
Expand Down
25 changes: 17 additions & 8 deletions pages/api/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { ApolloServer } from 'apollo-server-micro';
import { buildSchema } from 'type-graphql';
import { applyMiddleware } from 'graphql-middleware';

import cors from 'micro-cors';

import 'reflect-metadata';

import getConnection from '@models/index';
import { AdminConnector } from '@connectors/admin';
import { PartnerConnector } from '@connectors/partner';
import { CourseConnector } from '@connectors/course';
import { CouponConnector } from '@connectors/coupon';
import { ServerRequest, ServerResponse } from '@typeDefs/server';
import { ResolverContext } from '@typeDefs/resolver';
import schema from '@api/schema';
import getMe from '@api/middleware/getMe';

import resolvers from '@api/resolvers';
import meMiddleware from '@api/middleware/global/me';
import sentryMiddleware from '@api/middleware/global/sentry';

import firebaseAdmin from '@services/firebase/admin';

if (process.env.FIREBASE_ADMIN_UID) {
Expand Down Expand Up @@ -41,11 +49,15 @@ export const config = {
export default async (req: ServerRequest, res: ServerResponse) => {
const connection = await getConnection();

const schema = await buildSchema({
resolvers,
dateScalarMode: 'isoDate',
});

const server = new ApolloServer({
schema,
context: async ({ req, res }): Promise<ResolverContext> => {
const me = await getMe(req, res);
schema: applyMiddleware(schema, sentryMiddleware, meMiddleware),

context: async ({ req, res }): Promise<ResolverContext> => {
const adminConnector = new AdminConnector();
const partnerConnector = new PartnerConnector(connection!);
const courseConnector = new CourseConnector(connection!);
Expand All @@ -54,7 +66,6 @@ export default async (req: ServerRequest, res: ServerResponse) => {
return {
req,
res,
me,
adminConnector,
courseConnector,
partnerConnector,
Expand All @@ -67,7 +78,5 @@ export default async (req: ServerRequest, res: ServerResponse) => {
server.createHandler({ path: '/api/graphql' })
);

// await connection.close();

return handler(req, res);
};
34 changes: 0 additions & 34 deletions src/api/authorization/index.ts

This file was deleted.

Loading

0 comments on commit 88b697a

Please sign in to comment.