Exposes immutable useful functions from Lodash to jsonLogic
Unsupported GraphQL keys: ==, ===, !=, !==, >, >=, <, <=, !!, !, %, +, *, -, /
Use any of _eq, _gt, _gte, _lt, _lte etc from Lodash methods
# Yarn
$ yarn add json-logic-js-graphql
# NPM
$ npm install json-logic-js-graphql --saveimport { jsonLogic } from 'json-logic-js-graphql'
const rules = {
_eq: [{ var: 'foo' }, { var: 'bar' }],
}
const data = { foo: 'bar', bar: 'bar' }
jsonLogic.apply(rules, data)
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
_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)Can be found here:
Install dependencies with yarn install and then run the tests yarn test
Inpired from formio utils
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.
The library is available as open source under the terms of the MIT License.
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.
