Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@entria/graphql-mongo-helpers

Package Overview
Dependencies
Maintainers
11
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@entria/graphql-mongo-helpers

Mongo helpers to be used when building a GraphQL API

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-56.25%
Maintainers
11
Weekly downloads
 
Created
Source

GraphQL Mongo Helpers

npm CircleCI (all branches)

  1. What is this?
  2. Install
  3. Usage

What is this?

It's a package with some (currently one to be exact) tools to use when building a GraphQL API and using MongoDB.

Install

yarn add @entria/graphql-mongo-helpers

Usage

The most updated source of documentation are the test files, check the files in src/__tests__/.

I've written a post about some of those helpers:

buildMongoConditionsFromFilters`(filterArgs, mapping, context)

This helper transforms given object, which is going to be a argument supplied to some resolver, and returns a matching object to be consumed by MongoDB. The object will have a conditions and pipeline property.

input MyResolverFilter {
  # filter field name, can add a suffix which is going to act as a modifier
  # in this case using all
  tags_all: [String!]!
  title: String
}
// some mapping, mappins are optional, the default behavior
// is the filter be a MATCH_1_TO_1 with key identical to the one supplied
const filterMapping = {
  tags: {
    type: FILTER_CONDITION_TYPE.MATCH_1_TO_1,
    key: 'my.nested.tags',
  },
  title: {
    type: FILTER_CONDITION_TYPE.MATCH_1_TO_1,
    // format function can be used to transform the value before creatig the condition
    format: (val) => new RegExp(`^${escapeRegex(val)}`),
  }
}

Then inside the resolver:

const filterResult = buildMongoConditionsFromFilters(args.filter, filterMapping);

if client supplied something like:

{
  tags_all: ['a', 'b'],
  title: 'Blah',
};

the filterResult value will be:

{
  conditions: {
    'my.nested.tags': { $all: ['a', 'b'] },
    title: /^Blah/,
  },
  pipeline: [],
}
Available comparison operators
'gt', 'gte', 'lt', 'lte', 'in', 'nin', 'ne', 'all'

where in, nin and all expect the value of the respective filter to be an array.

FAQs

Package last updated on 30 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc