typedb/typedb-driver-nodejs

Defining a rule fails

Irtazaraza opened this issue · 3 comments

Description

Adding a rule using the client method(putRule) causes an error, while adding the exact same rule via the console is fine.

Environment

  1. OS (where Grakn server runs): Mac OS 10
  2. Grakn version (and platform): Grakn.1.5.2
  3. Grakn client-nodejs version: client-nodejs 1.5.3
  4. Node.js version: v10.15.1

Reproducible Steps

define 

person sub entity,
  plays child,
  plays parent,
  plays grandp,
  plays grandc;

parentship sub relation,
  relates child,
  relates parent;

grandparentship sub relation,
  relates grandp,
  relates grandc;

test sub rule,
when {
(parent: $a, child: $b) isa parentship;
(parent: $b, child: $c) isa parentship;
}, then {
(grandp: $a, grandc: $c) isa grandparentship;
};
transaction.putRule("test", "{(parent: $a, child: $b) isa parentship;(parent: $b, child: $c) isa parentship;}", "{(grandp: $a, grandc: $c) isa grandparentship;)}"

Expected Output

rule defined

Actual Output

error: 2 UNKNOWN: syntax error at line 1: 
{(parent: $a, child: $b) isa parentof; (parent: $b, child: $c) isa parentof;}
                                                                             ^
no viable alternative at input '{(parent: $a, child: $b) isa parentof; (parent: $b, child: $c) isa parentof;}'
syntax error at line 1: 
{(parent: $a, child: $b) isa parentof; (parent: $b, child: $c) isa parentof;}
                                                                             ^
no viable alternative at input '{(parent: $a, child: $b) isa parentof; (parent: $b, child: $c) isa parentof;}'.

Additional notes

@vmax this issue is causing typedb/typedb-studio#142

vmax commented

This example indeed contains a syntax error. Here's how such a rule should be defined (keep a note at how then doesn't have an extraneous closing bracket):

(async function() {
const GraknClient = require('grakn-client');

const client = new GraknClient('localhost:48555');
const session = await client.session('test_keyspace');
const tx = await session.transaction().write();

const label = 'test';
const when = '{ (parent: $a, child: $b) isa parentship; (parent: $b, child: $c) isa parentship; };';
const then = '{ (grandp: $a, grandc: $c) isa grandparentship; };';

const rule = await tx.putRule(label, when, then);
console.log(rule)

})();

@vmax I think you're right, but we need to just make sure that's an issue in workbase before closing this, as workbase still has problems with Rules definition typedb/typedb-studio#142

so maybe worth having a deeper investigation on how these 2 issues are related

Workbase issue has been resolved