m-ld / m-ld-js

m-ld Javascript engine
https://js.m-ld.org
MIT License
37 stars 2 forks source link

Strange behaviour of `get` and `@construct` with missing properties #131

Closed gsvarovsky closed 1 year ago

gsvarovsky commented 1 year ago

If a requested property is missing but the subject does exist, these queries do not return the subject.

Tests (MeldClone/basic reads):

    test('gets if any available property', async () => {
      await api.write<Subject>({ '@id': 'fred', name: 'Fred' });
      await expect(api.get('fred', 'age', 'name'))
        .resolves.toEqual({ '@id': 'fred', name: 'Fred' });
    });

=> Received: undefined

    test('constructs with missing property', async () => {
      await api.write<Subject>({ '@id': 'fred', name: 'Fred', age: undefined });
      await expect(api.read<Construct>({
        '@construct': { '@id': 'fred', name: '?', age: '?' }
      })).resolves.toMatchObject([{
        '@id': 'fred', name: 'Fred'
      }]);
    });

=> Received: SubjectGraph []

gsvarovsky commented 1 year ago

This is SPARQL's must-match behaviour for variables.

Possible fix: make ConstructTemplate.pattern create a UNION. However this is complicated by nested subjects.