All Projects → entria → Graphql Mongoose Loader

entria / Graphql Mongoose Loader

Licence: mit
GraphQL Mongoose Loader helpers

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Graphql Mongoose Loader

Nightcat
个人博客,技术栈:NodeJS + Express + mongoose + GraphQL + Vue 全家桶
Stars: ✭ 97 (-1.02%)
Mutual labels:  graphql, mongoose
Apollo Resolvers
Expressive and composable resolvers for Apollostack's GraphQL server
Stars: ✭ 428 (+336.73%)
Mutual labels:  graphql, resolver
Express Graphql Mongodb Boilerplate
A boilerplate for Node.js apps / GraphQL-API / Authentication from scratch - express, graphql - (graphql compose), mongodb (mongoose).
Stars: ✭ 288 (+193.88%)
Mutual labels:  graphql, mongoose
Hotchocolate
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
Stars: ✭ 3,009 (+2970.41%)
Mutual labels:  graphql, resolver
Typeorm Graphql Loader
A query builder to easily resolve nested fields and relations for TypeORM-based GraphQL servers
Stars: ✭ 47 (-52.04%)
Mutual labels:  graphql, resolver
Blog Service
blog service @nestjs
Stars: ✭ 188 (+91.84%)
Mutual labels:  graphql, mongoose
Nestjs Query
Easy CRUD for GraphQL.
Stars: ✭ 325 (+231.63%)
Mutual labels:  graphql, mongoose
Nest User Auth
A starter build for a back end which implements managing users with MongoDB, Mongoose, NestJS, Passport-JWT, and GraphQL.
Stars: ✭ 145 (+47.96%)
Mutual labels:  graphql, mongoose
Graphql Advanced Projection
Fully customizable Mongoose/MongoDB projection generator.
Stars: ✭ 46 (-53.06%)
Mutual labels:  graphql, mongoose
Graphql Compose Mongoose
Mongoose model converter to GraphQL types with resolvers for graphql-compose https://github.com/nodkz/graphql-compose
Stars: ✭ 543 (+454.08%)
Mutual labels:  graphql, mongoose
Intro To Graphql
[Course] Introduction to GraphQL
Stars: ✭ 175 (+78.57%)
Mutual labels:  graphql, mongoose
Boilerplate Vue Apollo Graphql Mongodb
Start your magical stack journey!
Stars: ✭ 85 (-13.27%)
Mutual labels:  graphql, mongoose
Frisky
🍿 Open Source GraphQL API for Online Shows
Stars: ✭ 161 (+64.29%)
Mutual labels:  graphql, mongoose
Graphql Resolvers
🔌 Resolver composition library for GraphQL.
Stars: ✭ 274 (+179.59%)
Mutual labels:  graphql, resolver
Next Graphql Blog
🖊 A Blog including a server and a client. Server is built with Node, Express & a customized GraphQL-yoga server. Client is built with React, Next js & Apollo client.
Stars: ✭ 152 (+55.1%)
Mutual labels:  graphql, mongoose
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 (+213.27%)
Mutual labels:  graphql, mongoose
Graphql Nodejs Hapi Api
How to set-up a powerful API with Nodejs, GraphQL, MongoDB, Hapi, and Swagger
Stars: ✭ 116 (+18.37%)
Mutual labels:  graphql, mongoose
Apollo2 Subscriptions How To
Apollo Server 2 how to setup subscriptions
Stars: ✭ 125 (+27.55%)
Mutual labels:  graphql, mongoose
Create Graphql
Command-line utility to build production-ready servers with GraphQL.
Stars: ✭ 441 (+350%)
Mutual labels:  graphql, mongoose
Wertik Js
💪 A library that powers your app with GraphQL + Rest API
Stars: ✭ 56 (-42.86%)
Mutual labels:  graphql, mongoose

GraphQL Mongoose Loader CircleCI

Install

npm i @entria/graphql-mongoose-loader --save
yarn add @entria/graphql-mongoose-loader

Mongoose Dataloader Batch

Add batch to your GraphQL resolvers/loaders

Define a mongoose schema for your model

import mongoose from 'mongoose';

const Schema = new mongoose.Schema(
  {
    name: {
      type: String,
    },
    email: {
      type: String,
      required: true,
      index: true,
    },
    password: {
      type: String,
      hidden: true,
    },
  },
  {
    collection: 'User',
  },
);

export default mongoose.model('User', Schema);

Create a Dataloader for it

import { mongooseLoader } from '@entria/graphql-mongoose-loader';
import UserModel from './User';

export const getLoader = () => new DataLoader(ids => mongooseLoader(UserModel, ids));

Connection from Mongoose Cursor

Create a connection from mongoose cursor

import { connectionFromMongoCursor } from '@entria/graphql-mongoose-loader';

export const loadUsers = async (context: GraphQLContext, args: ConnectionArguments) => {
  const where = args.search
    ? {
        name: {
          $regex: new RegExp(`^${args.search}`, 'ig'),
        },
      }
    : {};
  const users = UserModel.find(where, { _id: 1 }).sort({
    createdAt: -1,
  });

  return connectionFromMongoCursor({
    cursor: users,
    context,
    args,
    loader: load,
  });
};

Connection from Mongoose Aggregate

Create a connection from mongoose aggregate

import { connectionFromMongoAggregate } from '@entria/graphql-mongoose-loader';

export const loadUsersThatHaveGroup = async (context: GraphQLContext, args: ConnectionArguments) => {
  const aggregate = GroupModel.aggregate([
    {
      $lookup: {
        from: 'User',
        localField: 'users',
        foreignField: '_id',
        as: 'users',
      },
    },
    {
      // remove empty groups
      $match: { users: { $exists: true, $ne: [] } },
    },
    {
      // promote each user to a new document
      $unwind: '$users',
    },
    {
      $sort: {
        _id: 1,
      },
    },
    {
      $replaceRoot: { newRoot: '$users' },
    },
  ]);

  return connectionFromMongoAggregate({
    aggregate,
    context,
    args,
    loader: load,
  });
};
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].