当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

express-graphql-mongodb-boilerplate

授权协议 MIT License
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 仲孙夕
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

express-graphql-mongodb-boilerplate

Also express-mongodb-rest-api-boilerplate - REST-API Boilerplate

Authentication from scratch

Sign In, Sign Up, Reset Password, Change Password, Update User

E-mail verification, Multi language, Redis for token blacklisting

Package list

Package Description
bcryptjs Optimized bcrypt in JavaScript with zero dependencies. Compatible to the C++ bcrypt binding on node.js and also working in the browser.
cors CORS is a node.js package for providing a Connect/Express middleware that can be used to enable CORS with various options.
crypto-random-string Generate a cryptographically strong random string
dotenv Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env. Storing configuration in the environment separate from code is based on The Twelve-Factor App methodology.
ejs Embedded JavaScript templates
email-templates Create, preview, and send custom email templates for Node.js. Highly configurable and supports automatic inline CSS, stylesheets, embedded images and fonts, and much more! Made for sending beautiful emails with Lad.
express Fast, unopinionated, minimalist web framework for node.
express-graphql Create a GraphQL HTTP server with any HTTP web framework that supports connect styled middleware, including Connect itself, Express and Restify.
graphql The JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.
graphql-compose GraphQL – is a query language for APIs. graphql-js is the reference implementation of GraphQL for nodejs which introduce GraphQL type system for describing schema (definition over configuration) and executes queries on the server side. express-graphql is a HTTP server which gets request data, passes it to graphql-js and returned result passes to response.
graphql-compose-mongoose This is a plugin for graphql-compose, which derives GraphQLType from your mongoose model. Also derives bunch of internal GraphQL Types. Provide all CRUD resolvers, including graphql connection, also provided basic search via operators ($lt, $gt and so on).
i18next i18next is a very popular internationalization framework for browser or any other javascript environment (eg. node.js).
i18next-express-middleware This is a middleware to use i18next in express.js.
ioredis A robust, performance-focused and full-featured Redis client for Node.js.
jsonwebtoken This was developed against draft-ietf-oauth-json-web-token-08. It makes use of node-jws
module-alias Create aliases of directories and register custom module paths in NodeJS like a boss!
moment A lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.
mongoose Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports both promises and callbacks.
nodemailer Send e-mails from Node.js – easy as cake!
validator A library of string validators and sanitizers.
winston A logger for just about everything.

Redis

Mac (using homebrew):

brew install redis

Linux:

sudo apt-get install redis-server

First, we use yarn - workspaces with lerna

Introducing Yarn Workspaces

cd workspaces/api

COPY .env.example to .env

cp .env.example .env

Note: I highly recommend installing nodemon.

nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.nodemon does not require any additional changes to your code or method of development. nodemon is a replacement wrapper for node, to use nodemon replace the word node on the command line when executing your script.yarn global add nodemon.

API Start

yarn start
yarn start:local # with nodemon

Docker compose

docker-compose up -d --build
docker-compose -f docker-compose.dev.yml up --build # with nodemon

ESlint Start

yarn lint
yarn lint:write # with prefix --fix

API Structure

├─ src
│  ├─ graphql
│  │  ├─ index.js
│  │  ├─ schema.js
│  │  └─ types.js
│  ├─ i18next
│  │  ├─ locales
│  │  │  ├─  en.json
│  │  │  └─  ge.json
│  │  └─ index.js
│  ├─ middleware
│  │  ├─ authentication.js
│  │  ├─ authMiddleware.js
│  │  └─  index.js
│  ├─ module
│  │  ├─ auth
│  │  │  ├─ mail
│  │  │  │  ├─ index.js
│  │  │  │  └─ userMail.js
│  │  │  ├─ service
│  │  │  │  ├─ index.js
│  │  │  │  └─ userService.js
│  │  │  ├─ index.js
│  │  │  ├─ resolvers.js
│  │  │  ├─ types.js
│  │  │  └─ user.js
│  │  └─ index.js
│  ├─ service
│  │  ├─ logger.js
│  │  └─ nodemailer.js
│  ├─ validator
│  │  ├─ index.js
│  │  └─ userValidator.js
│  ├─ view
│  │  └─ template
│  │     ├─ reset-password
│  │     │  └─ html.ejs
│  │     ├─ verify
│  │     │  └─ html.ejs
│  │     └─ verify-request
│  │        └─ html.ejs
│  ├─ index.js
│  ├─ mongoose.js
│  └─ redis.js
├─ .dockerignore
├─ .env.example
├─ .eslintignore
├─ .eslint
├─ .gitignore
├─ Dockerfile
├─ Dockerfile.dev
├─ LICENSE
├─ README.md
├─ docker-compose.dev.yml
├─ docker-compose.yml
└─ package.json

Note: To continue development, you should learn about graphql-compose - this is the library that I use to write the API, you can read about it at the link: docs

Queries

query user {
  user {
    _id
    email
    firstName
    lastName
    locale
    account {
      verification {
        verified
      }
    }
    updatedAt
    createdAt
  }
}

Mutations

mutation signIn($email: String!, $password: String!) {
  signIn(email: $email, password: $password) {
    accessToken
  }
}

mutation signUp($email: String!, $password: String!) {
  signUp(email: $email, password: $password) {
    accessToken
  }
}

mutation logout {
  logout {
    succeed
  }
}

mutation verifyRequest {
  verifyRequest {
    succeed
  }
}

mutation verify($token: String!) {
  verify(token: $token) {
    accessToken
  }
}

mutation resetPassword($email: String!) {
  resetPassword(email: $email) {
    succeed
  }
}

mutation newPassword($token: String!, $newPassword: String!) {
  newPassword(token: $token, newPassword: $newPassword) {
    accessToken
  }
}

mutation changePassword($currentPassword: String!, $newPassword: String!) {
  changePassword(currentPassword: $currentPassword, newPassword: $newPassword) {
    succeed
  }
}

mutation updateUser($email: String!, $firstName: String!, $lastName: String!) {
  updateUser(email: $email, firstName: $firstName, lastName: $lastName) {
    _id
    email
    firstName
    lastName
    locale
    account {
      verification {
        verified
      }
    }
    updatedAt
    createdAt
  }
}

mutation switchLocale($locale: Locale!) {
  switchLocale(locale: $locale) {
    _id
    email
    firstName
    lastName
    locale
    account {
      verification {
        verified
      }
    }
    updatedAt
    createdAt
  }
}

Note: For any question issues

License

This project is an open-source with an MIT License

  • 1、Mongoose模块 (1)是一个对象模型工具,是对Node.js环境下操作MongoDB数据库进行了封装,可以将MongoDB数据库中的数据转换成JavaScript对象供用户使用。 (2)名词:          1️⃣Schema:它是一种以文件形式存储的数据库模型骨架,不具备对数据库操作的能力,仅仅只是数据库在程序片段中的一种表现,可以理解为表结构。         2️⃣Model:

  • 接着上节学习graphql+node+express+mongodb实现增删改查及两表关联。 先定义schema 以集合user为例子: graphql中定义schema(schema.js) type User{ name:String, age:Int, id:String, status:String, msg:String } ty

  • 数据库概念 一个数据库软件中可以包含多个数据仓库,在每个数据仓库中,可以包含多个数据集合,每个数据集合中可以包含多条文档(具体的数据) 术语 解释说明 database 数据库,mongoDB数据库软件中可以建立多个数据库 collection 集合,一组数据的集合,可以理解为JavaScript中的数组 document 文档,一条数据的数据,可以理解为JavaScript中的对象 field

  • 前言: 不会写后端服务的前端不是好销售 环境搭建 node环境的安装 见百度 express : 一个优秀的nojs框架 npm i express -g express-generator: 脚手架工具 用于生成express骨架 npm i express-generator -g nodemon:一款非常实用的工具,用来监控 NodeJS源代码的任何变化和自动重启你的服务器 npm

  • 本文是刨去express的基本使用,对于express框架下重要部分的学习记录 涉及到的知识点主要以下几点: express路由封装使用 请求传值获取 session/cookie使用 ejs模板使用 mongoDB操作封装使用 express路由封装使用 将项目中的各路由中间件拆分各自作用的模块,各模块中使用express路由并实例化,实例化后的对象上使用中间件, 最后通过commonjs规范m

  • 在Express中使用GraphQL主要有以下几步: 1. 安装 graphql 和 express-graphql; 2. 引入express-graphql; 3. 引入自定义的schema,其中定义schema又分为以下几步: (1). 定义查询字段的schema类型; (2). 定义一个根 , 根里面定义调用schema类型的方法; (3). 把根挂载到 GraphQLSchema; 4.

  • mongodb常用语句: ction(“collName”, {size: 20, capped: true, max: 100}); (写限制的为定容量,一般不写 ) db.collName.isCapped(); //判断集合是否为定容量 db.createCollection(‘info’) 创建info集合 db.getCollection(‘info’) 查询 db.getCollect

  • pm2 reload all(刷新) 一、安装monoose(链接数据库) 二、创建models(mongoose创建model实体,通过实体和mongodb关联数据库) models/goods.js var mongoose=require('mongoose') var Schema=mongoose.Schema; var productSchema=new Schema({ "p

  • 测试数据: /* 1 */ { "_id" : ObjectId("5ca0538159aa1df98e31c634"), "numIndex" : 0.0 } /* 2 */ { "_id" : ObjectId("5ca0538159aa1df98e31c635"), "numIndex" : 1.0 } // 写入了三万条这样的numIndex自增1的数据

  • Express框架访问MongoDB数据库 1.npm安装(npm i nodemon/cors/mongoose) 2.检查端口号 1.dao层 ​ ①、config(数据库连接) //1.导入mongoose模块 const Mongoose = require('mongoose') //2.定义mongodb数据库的连接字符串:协议://主机名/主机地址/端口号/数据库名 const

  • 连接MongoDB 首先安装引入mongoose //先引入mongoose模块 var mongoose = require("mongoose"); //连接数据库服务器 mongoose.connect('mongodb://readAndWrite:readAndWrite@localhost:27017/stu',{ useNewUrlParser: true, useUnifi

 相关资料
  • GraphQL HTTP Server Middleware Create a GraphQL HTTP server with any HTTP web framework that supports connect styled middleware, including Connect itself, Express and Restify. Installation npm install

  • express-graphql-boilerplate Express GraphQL API with JWT Authentication and support for sqlite, mysql, and postgresql Authentication via JWT Support for sqlite, mysql, and postgresql Support for graph

  • express-graphql-typescript-boilerplate A GraphQL starter kit for building amazing API's in TypeScript and with Express.js framework. This seed repository has a complete GraphQL starter kit written in

  • Express, GraphQL example How to run the project Install dependencies: yarn# or using npmnpm install Create src/config.ts or rename src/config.example.js and update file with your credentials: export d

  • graphql-to-mongodb If you want to grant your Nodejs GraphQL service a whole lot of the power of the MongoDb database standing behind it with very little hassle, you've come to the right place! Example

  • koa-graphql-mongodb is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial. koa-graphql-mongodb Tutorial how to set up koa with graphql and mongodb