Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/graphql support #2

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"build": "rimraf build && tsc -p tsconfig.json"
},
"dependencies": {
"@apollo/server": "^4.9.5",
"@prisma/client": "^5.3.1",
"@types/bcryptjs": "^2.4.4",
"@types/nodemailer": "^6.4.11",
Expand All @@ -29,6 +30,8 @@
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-rate-limit": "^7.0.2",
"graphql": "^16.8.1",
"graphql-tag": "^2.12.6",
"helmet": "^7.0.0",
"http-status": "^1.7.0",
"joi": "^17.10.2",
Expand Down
8 changes: 6 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import passport from 'passport';

import config from './core/config';
import morgan from './core/morgan';
import routes from './routes/v1';
import { startApolloServer } from './core/graphql/apollo';
import JwtStrategy from './core/passport';
import { NotFound } from './utils/ApiError';
import { errorConverter, errorHandler } from './core/middlewares/error';

import routes from './routes/v1';
import { NotFound } from './utils/ApiError';

const app = express();

if (config.environment !== 'test') {
Expand All @@ -35,6 +37,8 @@ app.use((req, res, next) => {
app.use(errorConverter);
app.use(errorHandler);

startApolloServer();

app.use('/v1', routes);

export default app;
13 changes: 13 additions & 0 deletions src/core/graphql/apollo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import typeDefs from './typeDefs';
import logger from '../logger';

const startApolloServer = async () => {
const server = new ApolloServer({ typeDefs });
const { url } = await startStandaloneServer(server);

logger.info(`Apollo server running at: ${url}`);
};

export { startApolloServer };
25 changes: 25 additions & 0 deletions src/core/graphql/typeDefs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import gql from 'graphql-tag';

const typeDefs = gql`
input UserRequest {
uuid: String
}

type UserResponse {
uuid: String!
email: String
name: String!
created: DateTime!
}

type ApiError {
statusCode: Int!
message: String!
}

type Query {
userDetails(request: UserRequest): UserResponse
}
`;

export default typeDefs;
Loading