Can connect to bootstrap with express.js but error on client.query() from POST request

Hey posting my devlog here now since I think it might be better than in the Docs subforum. So after reading the docs that were hidden by the Jekyl bug, and realizing that the console queries were also WOQL.js (I figured it out by looking at the dropdown, but I didn’t see anywhere in the docs that I was writing WOQL.js) I’ve tried to create an express route. I’ll include the code below but I’m getting an error and I don’t know what I’m doing wrong. I really think this could’ve been avoided by just providing a simple example in README.md about how to send client.query() which is basically all you need.

My Express code:

const express = require("express");
const app = express();
const port = 3000;

const TerminusClient = require("@terminusdb/terminusdb-client");

//Create a new instance of terminusDB client
const client = new TerminusClient.WOQLClient("https://127.0.0.1:6363/", {
  dbid: "banker",
  user: "admin",
  key: "root",
});

//use async/await.
async function getCapabilities() {
  try {
    const response = await client.connect();
    console.log(response);
    return response;
  } catch (err) {
    console.error(err);
  }
}

app.post("/account", (req, res) => {
  const WOQL = TerminusClient.WOQL;
  const query = WOQL.and(
    WOQL.add_triple("doc:illuminati", "type", "scm:BankAccount"),
    WOQL.add_triple("doc:illuminati", "owner", "illuminati"),
    WOQL.add_triple("doc:illuminati", "balance", 223)
  );
  client
    .query(query, "commit yo")
    .then((response) => {
      console.log(response);
    })
    .catch((err) => {
      console.log("error", err);
    });
  res.send("express is good");
});

app.listen(port, () => {
  console.log(`Backend Server listening at http://localhost:${port}`);
  client
    .connect()
    .then(function (response) {
      // handle success
      console.log(response);
    })
    .catch(function (error) {
      // handle error
      console.log(error);
    });
});

Starting express with $ npm start gives the following in the terminal:

Backend Server listening at http://localhost:3000
{
  '@context': {
    api: 'http://terminusdb.com/schema/api#',
    doc: 'terminusdb:///system/data/',
    layer: 'http://terminusdb.com/schema/layer#',
    owl: 'http://www.w3.org/2002/07/owl#',
    rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
    rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
    ref: 'http://terminusdb.com/schema/ref#',
    repo: 'http://terminusdb.com/schema/repository#',
    system: 'http://terminusdb.com/schema/system#',
    terminus: 'http://terminusdb.com/schema/system#',
    vio: 'http://terminusdb.com/schema/vio#',
    woql: 'http://terminusdb.com/schema/woql#',
    xdd: 'http://terminusdb.com/schema/xdd#',
    xsd: 'http://www.w3.org/2001/XMLSchema#'
  },
  '@id': 'doc:admin',
  '@type': 'system:User',
  'rdfs:comment': {
    '@language': 'en',
    '@value': 'This is the server super user account'
  },
  'rdfs:label': { '@language': 'en', '@value': 'Server Admin User' },
  'system:agent_name': { '@type': 'xsd:string', '@value': 'admin' },
  'system:role': {
    '@id': 'doc:admin_role',
    '@type': 'system:Role',
    'rdfs:comment': {
      '@language': 'en',
      '@value': 'Role providing admin capabilities'
    },
    'rdfs:label': { '@language': 'en', '@value': 'Admin Role' },
    'system:capability': {
      '@id': 'doc:server_access',
      '@type': 'system:Capability',
      'rdfs:comment': [Object],
      'rdfs:label': [Object],
      'system:action': [Array],
      'system:capability_scope': [Array]
    }
  },
  'system:user_key_hash': ''
}

And my error when hitting POST /account:

error Error: API Error @type api:WoqlErrorResponse api:message The following descriptor could not be resolved to a resource: 'false/false/local/branch/main' api:status api:failure Code: 404 url: https://127.0.0.1:6363/api/woql/false/false/local/branch/main
    at /home/harman/Desktop/endgame/backend/node_modules/@terminusdb/terminusdb-client/lib/dispatchRequest.js:132:31
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  data: {
    '@type': 'api:WoqlErrorResponse',
    'api:error': {
      '@type': 'api:UnresolvableAbsoluteDescriptor',
      'api:absolute_descriptor': 'false/false/local/branch/main'
    },
    'api:message': "The following descriptor could not be resolved to a resource: 'false/false/local/branch/main'",
    'api:status': 'api:failure'
  }
}

I’m guessing I gotta do something like

await client.connect()
client.query(query, 'hello world commit'
//or
client.connect().then((response_unused) => {
  client.query(query, 'hello world commit')
}

But I found no guidance or examples in the docs and thats unfortunate. I’ll try to fix my error with the above approaches. Or is it something else I’m missing?

1 Like