weaviate / typescript-client

Official Weaviate TypeScript Client
https://www.npmjs.com/package/weaviate-client
BSD 3-Clause "New" or "Revised" License
57 stars 21 forks source link

client.data.checker() returns a function instead of a boolean #63

Open dandv opened 1 year ago

dandv commented 1 year ago
const client = weaviate.client({
  scheme: 'https',
  host: 'edu-demo.weaviate.network',
  apiKey: new weaviate.ApiKey('learn-weaviate'),
});

const id = '00ff6900-e64f-5d94-90db-c8cfa3fc851b';

result = await client.data
  .checker()
  .withClassName('JeopardyQuestion')
  .withId(id)
  .do();

console.log(typeof result, `result: ${result}`, JSON.stringify(result));

The output will be this,

function result: t=>{if(t.status>=400)return t.text().then(e=>{let r;try{r=JSON.stringify(JSON.parse(e))}catch{r=e}return Promise.reject(new Error(usage error (${t.status}): ${r}))});if(i)return t.json()} undefined

The object does exist,

result = await client.data
  .getterById()
  .withClassName('JeopardyQuestion')
  .withId(id)
  .do();

console.log(JSON.stringify(result, null, 2));

BTW the tests for checker() lack .withClassName(), which results in a warning, "Usage of objects paths without className is deprecated in Weaviate 1.19.6. Please provide className parameter".

tsmith023 commented 1 year ago

@dandv, this seems to be a multi-faceted issue. The core problem you're seeing is that the learn-weaviate API key in fact lacks the permissions necessary to use the .checker() method on the https://edu-demo.weaviate.network URL. This is because .checker() makes an HTTP HEAD request under-the-hood and this apparently requires elevated access.

You were unable to see this error in the client, however, due to the issue that you raised with regards to the return type in your MRE. A solution to this is open in a PR: https://github.com/weaviate/typescript-client/pull/71, but the fundamental problem will remain: the demo API key cannot make HEAD requests so cannot use the .checker() method.

To see this for yourself, you can use POSTman or Insomnia to make a HEAD request to https://edu-demo.weaviate.network/v1/objects/WikiCity/00008ad0-f7f1-5fd8-8fd6-a03a203bd428 with an Authorization header of Bearer learn-weaviate and you will receive a 403 Forbidden error. On the other hand, if you remove this Authorization header entirely, you will receive a 401 Unauthorized header signifying that the API key is genuine but lacks the required permissions.