All Projects → thomasgazzoni → graphql-server-typescript

thomasgazzoni / graphql-server-typescript

Licence: MIT license
GraphQL + MongoDB express server with JWT authorization (in Typescript!)

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to graphql-server-typescript

Chat.io
A Real Time Chat Application built using Node.js, Express, Mongoose, Socket.io, Passport, & Redis.
Stars: ✭ 1,325 (+2660.42%)
Mutual labels:  mongoose, passport
mern-boilerplate
A Full MERN Stack Boilerplate for Web Apps including a local authentication system. Uses React, Express.js, MongoDB, Redux, Passport.js, Webpack, Testing, and more.
Stars: ✭ 211 (+339.58%)
Mutual labels:  mongoose, passport
Mern Boilerplate
Fullstack boilerplate with React, Redux, Express, Mongoose, Passport Local, JWT, Facebook and Google OAuth out of the box.
Stars: ✭ 112 (+133.33%)
Mutual labels:  mongoose, passport
Es6 Express Mongoose Passport Rest Api
Lightweight boilerplate for Node RESTful API, ES6, Express, Mongoose and Passport 🎁
Stars: ✭ 36 (-25%)
Mutual labels:  mongoose, passport
Mern Passport
A boilerplate example of using passport.js for authenticating a MERN application
Stars: ✭ 214 (+345.83%)
Mutual labels:  mongoose, passport
Node Express Mongoose
A boilerplate application for building web apps using node and mongodb
Stars: ✭ 1,221 (+2443.75%)
Mutual labels:  mongoose, passport
Ecommerce Site Template
A beautiful e-commerce template powered by React, Redux and other modern web tech.
Stars: ✭ 167 (+247.92%)
Mutual labels:  mongoose, passport
Nest Angular
NestJS, Angular 6, Server Side Rendering (Angular Universal), GraphQL, JWT (JSON Web Tokens) and Facebook/Twitter/Google Authentication, Mongoose, MongoDB, Webpack, TypeScript
Stars: ✭ 307 (+539.58%)
Mutual labels:  mongoose, passport
Saas
Build your own SaaS business with SaaS boilerplate. Productive stack: React, Material-UI, Next, MobX, WebSockets, Express, Node, Mongoose, MongoDB. Written with TypeScript.
Stars: ✭ 2,720 (+5566.67%)
Mutual labels:  mongoose, passport
Blog Service
blog service @nestjs
Stars: ✭ 188 (+291.67%)
Mutual labels:  mongoose, graphql-server
Node Express Mongoose Demo
A simple demo app using node and mongodb for beginners
Stars: ✭ 4,976 (+10266.67%)
Mutual labels:  mongoose, passport
Builderbook
Open source web application to learn JS stack: React, Material-UI, Next.js, Node.js, Express.js, Mongoose, MongoDB database.
Stars: ✭ 3,015 (+6181.25%)
Mutual labels:  mongoose, passport
Create Graphql
Command-line utility to build production-ready servers with GraphQL.
Stars: ✭ 441 (+818.75%)
Mutual labels:  mongoose, graphql-server
Angular Full Stack
Angular Full Stack project built using Angular, Express, Mongoose and Node. Whole stack in TypeScript.
Stars: ✭ 1,261 (+2527.08%)
Mutual labels:  mongoose, bcrypt
Meantorrent
meanTorrent - MEAN.JS BitTorrent Private Tracker - Full-Stack JavaScript Using MongoDB, Express, AngularJS, and Node.js, A BitTorrent Private Tracker CMS with Multilingual, and IRC announce support, CloudFlare support. Demo at:
Stars: ✭ 438 (+812.5%)
Mutual labels:  mongoose, passport
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (+204.17%)
Mutual labels:  mongoose, passport
Quora
Building An Exclusive Community of PEC Graduates and Students.The main features of the website are “PEC Quora” and “PEC Connect”
Stars: ✭ 26 (-45.83%)
Mutual labels:  mongoose, bcrypt
Jianshu
仿简书nx+nodejs+nestjs6+express+mongodb+angular8+爬虫
Stars: ✭ 296 (+516.67%)
Mutual labels:  mongoose, passport
Lad
👦 Lad is the best Node.js framework. Made by a former Express TC and Koa team member.
Stars: ✭ 2,112 (+4300%)
Mutual labels:  mongoose, passport
Typescript Express Starter
🚀 TypeScript Express Starter
Stars: ✭ 238 (+395.83%)
Mutual labels:  mongoose, bcrypt

GraphQL + MongoDB express server (in Typescript)

This is just a starter example on how to build a GraphQL server with MongoDB database in Typescript.

The advanage of this solution is a strong type checking, thanks to Typescript, and a easy GraphQL schema definition using GraphQLSchema and GraphQLObjectType.

The logic for the database models are inside the src/db folder while for the GraphQL types, query and mutation are inside the src/schema folder. The schema is then built in the src/schema/index.ts file.

For the authetication the method setupPassportAuth in the file src/authetication.ts will handle all the routes and access to the user table.

More details

  • Using Express and GraphQL HTTP Server to set up a graphql server.
  • Using Passport and Passport JSON Web Token for user authentication with bcrypt for hashing the password during user creation.
  • Using Mongoose to interact with MongoDB and take advantage of easy model definitions and support for Typescript.
  • Using GraphQL.js dynamically create a GraphQLSchema with types, query and mutation.
  • Using Typescript type checking compilation for development and production.

Install

The main Express App entry point is src/server.ts, it can be launch with the following commands:

For development (with live reload)

npm start

For production (app served from dist folder)

npm run build

Usage

In this example we open a MongoDB connection on mongodb://localhost:27017 and open the heros database, so we need to make sure mongod service is running and the default port is set to 27017 (or you can adjust the parameters in the src/server.ts file).

Run the express server (with npm start or npm build).

We need then to create a user to login with, we can create an admin user by visiting the debug url http://localhost:3000/add-admin-user.

We can then login from the auth form by visiting http://localhost:3000/auth (default username: admin, password: admin).

The login page will respond with an auth token, if you use a client we can save it and set it in the headers for the following requests, if you use a Browser you can use an extension (like this for Chrome) to set the Authorization header with the token (the token need to be preceded by JWT like JWT eyJhbGcixxxxxxxxx.

Now you are ready to open the GraphQL inspector by visiting http://localhost:3000/graphql and browse the schema and do query, mutation, etc.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].