Newts Parading Majestically

    json-logic-js-graphql

    1.2.4 • Public • Published

    jsonLogic GraphQL Query Keys

    NPM

    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.

    License

    The library is available as open source under the terms of the MIT License.

    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.

    Install

    npm i json-logic-js-graphql

    DownloadsWeekly Downloads

    26

    Version

    1.2.4

    License

    MIT

    Unpacked Size

    31.8 kB

    Total Files

    11

    Last publish

    Collaborators

    • msroot