All Projects → Soluto → Graphql To Mongodb

Soluto / Graphql To Mongodb

Allows for generic run-time generation of filter types for existing graphql types and parsing client requests to mongodb find queries

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Graphql To Mongodb

Queryql
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string!
Stars: ✭ 76 (-70.88%)
Mutual labels:  sort, query, filter, pagination
express-mquery
Expose mongoose query API through HTTP request.
Stars: ✭ 37 (-85.82%)
Mutual labels:  pagination, query, filter, sort
Typegql
Create GraphQL schema with TypeScript classes.
Stars: ✭ 415 (+59%)
Mutual labels:  graphql, graphql-server, graphql-js
Graphql Cost Analysis
A Graphql query cost analyzer.
Stars: ✭ 527 (+101.92%)
Mutual labels:  graphql, graphql-server, graphql-js
spring-boot-jpa-rest-demo-filter-paging-sorting
Spring Boot Data JPA with Filter, Pagination and Sorting
Stars: ✭ 70 (-73.18%)
Mutual labels:  pagination, filter, sort
Parse Server
API server module for Node/Express
Stars: ✭ 19,165 (+7242.91%)
Mutual labels:  graphql, graphql-server, mongodb
React Query
⚛️ Hooks for fetching, caching and updating asynchronous data in React
Stars: ✭ 24,427 (+9259%)
Mutual labels:  graphql, update, query
Graphql Log
Add logging to your GraphQL resolvers so you know what's going on in your app.
Stars: ✭ 94 (-63.98%)
Mutual labels:  graphql, graphql-server, graphql-js
Hangzhou Graphql Party
杭州 GraphQLParty 往期记录(slide,照片,预告,视频等)
Stars: ✭ 142 (-45.59%)
Mutual labels:  graphql, graphql-server, graphql-js
Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (-30.65%)
Mutual labels:  graphql, graphql-server, graphql-js
Gqlify
[NOT MAINTAINED]An API integration framework using GraphQL
Stars: ✭ 182 (-30.27%)
Mutual labels:  graphql, graphql-server, mongodb
Create Graphql Server
Generate your GraphQL server one type at a time
Stars: ✭ 321 (+22.99%)
Mutual labels:  graphql, graphql-server, mongodb
Grial
A Node.js framework for creating GraphQL API servers easily and without a lot of boilerplate.
Stars: ✭ 194 (-25.67%)
Mutual labels:  graphql, graphql-server, graphql-js
Walkable
A Clojure(script) SQL library for building APIs: Datomic® (GraphQL-ish) pull syntax, data driven configuration, dynamic filtering with relations in mind
Stars: ✭ 384 (+47.13%)
Mutual labels:  graphql, query, filter
Laravel Api Handler
Package providing helper functions for a Laravel REST-API
Stars: ✭ 150 (-42.53%)
Mutual labels:  sort, query, filter
Pup
The Ultimate Boilerplate for Products.
Stars: ✭ 563 (+115.71%)
Mutual labels:  graphql, graphql-server, mongodb
Gridjs
Advanced table plugin
Stars: ✭ 3,231 (+1137.93%)
Mutual labels:  sort, filter, pagination
Sieve
⚗️ Clean & extensible Sorting, Filtering, and Pagination for ASP.NET Core
Stars: ✭ 560 (+114.56%)
Mutual labels:  sort, filter, pagination
Searchobjectgraphql
GraphQL plugin for SearchObject gem
Stars: ✭ 118 (-54.79%)
Mutual labels:  graphql, graphql-server, filter
Blog Service
blog service @nestjs
Stars: ✭ 188 (-27.97%)
Mutual labels:  graphql, graphql-server, mongodb

graphql-to-mongodb

Build Status

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!

Examples

Change Log

Blog Post

Lets take a look at the most common use case, getMongoDbQueryResolver and getGraphQLQueryArgs:

Given a simple GraphQL type:

new GraphQLObjectType({
    name: 'PersonType',
    fields: () => ({
        age: { type: GraphQLInt },
        name: { type: new GraphQLObjectType({
            name: 'NameType',
            fields: () => ({
                first: { type: GraphQLString },
                last: { type: GraphQLString }
            })
        }),
        fullName: {
            type: GraphQLString,
            resolve: (obj, args, { db }) => `${obj.name.first} ${obj.name.last}`
        }
    })
})

An example GraphQL query supported by the package:

Queries the first 50 people, oldest first, over the age of 18, and whose first name is John.

{
    people (
        filter: {
            age: { GT: 18 },
            name: { 
                first: { EQ: "John" } 
            }
        },
        sort: { age: DESC },
        pagination: { limit: 50 }
    ) {
        fullName
        age
    }
}

To implement, we'll define the people query field in our GraphQL scheme like so:

people: {
    type: new GraphQLList(PersonType),
    args: getGraphQLQueryArgs(PersonType),
    resolve: getMongoDbQueryResolver(PersonType,
        async (filter, projection, options, obj, args, context) => {
            return await context.db.collection('people').find(filter, projection, options).toArray();
        })
}

You'll notice that integrating the package takes little more than adding some fancy middleware over the resolve function. The filter, projection, options added as the first paraneters of the callback, can be sent directly to the MongoDB find function as shown. The rest of the parameter are the standard recieved from the GraphQL api.

  • Additionally, resolve fields' dependencies should be defined in the GraphQL type like so:
    fullName: {
        type: GraphQLString,
        resolve: (obj, args, { db }) => `${obj.name.first} ${obj.name.last}`,
        dependencies: ['name'] // or ['name.first', 'name.Last'], whatever tickles your fancy
    }
    
    This is needed to ensure that the projection does not omit any neccessary fields. Alternatively, if throughput is of no concern, the projection can be replaced with an empty object.
  • As of mongodb package version 3.0, you should implement the resolve callback as:
    return await context.db.collection('people').find(filter, options).toArray();
    

That's it!

The following field is added to the schema (copied from graphiQl):

people(
    filter: PersonFilterType
    sort: PersonSortType
    pagination: GraphQLPaginationType
): [PersonType]

PersonFilterType:

age: IntFilter
name: NameObjectFilterType
OR: [PersonFilterType]
AND: [PersonFilterType]
NOR: [PersonFilterType]

* Filtering is possible over every none resolve field!

NameObjectFilterType:

first: StringFilter
last: StringFilter
opr: OprExists

OprExists enum tyoe can be EXISTS or NOT_EXISTS, and can be found in nested objects and arrays

StringFilter:

EQ: String
GT: String
GTE: String
IN: [String]
LT: String
LTE: String
NEQ: String
NIN: [String]
NOT: [StringFNotilter]

PersonSortType:

age: SortType

SortType enum can be either ASC or DESC

GraphQLPaginationType:

limit: Int
skip: Int

Functionality galore! Also permits update, insert, and extensiable custom fields.

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].