Socket
Socket
Sign inDemoInstall

graphql-mongo-fields

Package Overview
Dependencies
2
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    graphql-mongo-fields

A graphql fields parser to use as mongo select()


Version published
Maintainers
1
Install size
679 kB
Created

Readme

Source

GraphQL Mongo Fields

Convert a GraphlQL fields in a MongoDB select string.

https://nodei.co/npm/graphql-mongo-fields.png?downloads=true&downloadRank=true&stars=true

Example

Consider the following query:

query {
  foo {
    bar {
        foo
    }
  }
}

This module transforms the GraphQL fields into a string to select fields in MongoDB. The output will be:

'foo.bar.foo = 1'

Usage

const parseFields = require('graphql-mongo-fields')

// my awesome handler
const handler = async (_, args, context, info) => {

    users = await models.User.find({}, parseFields(info))

    return users
}

Development

You can use docker to develop in this project. If you run the bin/run_dev command you'll enter in a Docker container with the node:wheezy image and volumes mounted in /opt/app. Then is just start to coding :)

Don't forget to put the tests in the test/ folder and run typing npm run test.

Feel free to contribute

Keywords

FAQs

Last updated on 15 Sep 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc