JSON-logic-js-Graphql: JSON-logic-js support for GraphQL Query keys

jsonLogic GraphQL Query Keys

Exposes immutable useful functions from Lodash to jsonLogic

The Problem

Unsupported GraphQL keys: ==, ===, !=, !==, >, >=, <, <=, !!, !, %, +, *, -, /

The Solution

Use any of _eq, _gt, _gte, _lt, _lte etc from Lodash methods

Installation

# Yarn
$ yarn add json-logic-js-graphql

# NPM
$ npm install json-logic-js-graphql --save

Usage


import { jsonLogic } from 'json-logic-js-graphql'

const rules = {
  _eq: [{ var: 'foo' }, { var: 'bar' }],
}
const data = { foo: 'bar', bar: 'bar' }

jsonLogic.apply(rules, data)
 

GraphQL

jsonLogic's equal operator is "===" so it can't be used as a GraphQL key. We expose the eq lodash method as _eq to jsonLogic.

mutation {
  updateResource(
    id: "609ce9dbec9fb60004087784"
    logic: { _eq: [{ var: "foo" }, "bar"] }
  ) {
    id
  }
}

All Lodash methods exposed with the _ namespace to avoid overwriting the default jsonLogic's functionality

Date functions using momentJs

_gteDate, _gtDate, _lteDate, _ltDate, _eqDate, _getDate

example:

const rules = {
  _gteDate: [
    [{ var: 'from' }, { var: 'to' }],
    [364, 'days'],
  ],
}
const data = { from: '2020-10-01', to: '2021-10-01' }

jsonLogic.apply(rules, data)

Supported Lodash functions:

Can be found here:

Tests

Install dependencies with yarn install and then run the tests yarn test

Inpired

Inpired from formio utils

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/msroot/json-logic-js-graphql. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Code of Conduct

Everyone interacting in the json-logic-js-graphql project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.


Download Details:

Author: msroot
Source Code: https://github.com/msroot/json-logic-js-graphql 
License:  MIT License.

#graphql #json #query #keys 

JSON-logic-js-Graphql: JSON-logic-js support for GraphQL Query keys
1.40 GEEK