Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema query error: SERVER ERROR: Not well formed WOQL JSON-LD #2077

Open
alexander-mart opened this issue Jan 9, 2024 · 5 comments
Open
Labels
bug Something isn't working

Comments

@alexander-mart
Copy link
Contributor

Describe the bug
Schema query error: SERVER ERROR: Not well formed WOQL JSON-LD

To Reproduce

  1. Go to documentation: https://terminusdb.com/docs/schema-queries-with-woql/
  2. Copy example:
let v = Vars("cls");
from("schema")
  .triple(v.cls, "rdf:type", "sys:Class")
  1. Receive error: SERVER ERROR: Not well formed WOQL JSON-LD

Expected behavior

Screenshots

Info (please complete the following information):

  • cloud version: ?

Additional context

@alexander-mart alexander-mart added the bug Something isn't working label Jan 9, 2024
@hoijnet
Copy link

hoijnet commented Jan 10, 2024

Good find. The documentation mentions both triple and quad forms for this query. I think this is a bug indeed, or a client issue. For others seeing this later, check the documentation and use the quad style for now, but there are situations where there are many operations in the schema that really needs the from style!

Great catch @alexander-mart

@GavinMendelGleason
Copy link
Member

GavinMendelGleason commented Jan 10, 2024

This is a client bug, the generated JSON is:

{"@type":"Limit","limit":10,
  "query":{"@type":"And",
  "and":[{"@type":"From"},
              {"@type":"Triple",
               "subject":{"@type":"NodeValue","variable":"cls"},
               "predicate":{"@type":"NodeValue","node":"rdf:type"},
               "object":{"@type":"Value","node":"sys:Class"}}]}} 

Fluent syntax apparently does not work here, You can use the two argument call to from for now, and we can fix the documentation, but it would probably be nice if the fluent syntax worked to generate the right code here.

@hoijnet
Copy link

hoijnet commented Jan 10, 2024

I'd like to just check my understanding so that I interpret the fluent style correctly, the fluent style continuation is from my understanding always an extra appended parameter to the argument list? I was thinking about this for the WOQL-TS client and what was the correct interpretation.

Should thus the below be what should be in the doc link?

let v = Vars("cls");
from("schema", WOQL.triple(v.cls, "rdf:type", "sys:Class"))

With triple being the last argument of from()

@alexander-mart
Copy link
Contributor Author

alexander-mart commented Jan 10, 2024

With triple being the last argument of from()

Yes, for example convention in Ramda (Functional Programming JS-library):

The primary distinguishing features of Ramda are:

  • Ramda emphasizes a purer functional style. Immutability and side-effect free functions are at the heart of its design philosophy. This can help you get the job done with simple, elegant code.
  • Ramda functions are automatically curried. This allows you to easily build up new functions from old ones simply by not supplying the final parameters.
  • The parameters to Ramda functions are arranged to make it convenient for currying. The data to be operated on is generally supplied last.

The last two points together make it very easy to build functions as sequences of simpler functions, each of which transforms the data and passes it along to the next. Ramda is designed to support this style of coding.

Source: https://ramdajs.com/

How is currying work:

These queries should be identical (if from() function was curried):

let v = Vars("cls");
from("schema", WOQL.triple(v.cls, "rdf:type", "sys:Class"))
let v = Vars("cls");
from("schema").triple(v.cls, "rdf:type", "sys:Class")

@alexander-mart
Copy link
Contributor Author

Good find. The documentation mentions both triple and quad forms for this query. I think this is a bug indeed, or a client issue. For others seeing this later, check the documentation and use the quad style for now, but there are situations where there are many operations in the schema that really needs the from style!

Great catch @alexander-mart

For those who are looking for a solution 👍
For now, please use:

WOQL.quad("v:cls", "rdf:type", "sys:Class", "schema")

See: https://terminusdb.com/docs/javascript/#fromgraphrefquery

Instead of

from("schema", triple("v:cls", "rdf:type", "sys:Class"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants