RoamJS / developer

MIT License
2 stars 1 forks source link

Unknown error occured when querying #12

Closed rcvd closed 1 year ago

rcvd commented 1 year ago

I'm trying to run a SPARQL Import. While I get the dialog and can select the correct entry (Niklas Luhmann for example), I just get this after pressing import:

The error message says: Unknown error occured when querying. Contact support@roamjs.com for help!

The console says: TypeError: Cannot read properties of undefined (reading 'bindings')

Let me know if you need more information.

rcvd commented 1 year ago

Looks like I fixed the problem with adding JSON.parse to the result of the api call:

export const runSparqlQuery = ({
  query,
  source,
  parentUid,
  outputFormat,
}: {
  parentUid: string;
} & RenderProps["queriesCache"][string]): Promise<void> =>
  apiGet<{
    results: {
      bindings: {
        [k: string]: { value: string; type: string };
      }[];
    };
    head: {
      vars: string[];
    };
  }>({ href: `${source}${encodeURIComponent(query)}`, anonymous: true }).then(
    (r) => {
      const data = JSON.parse(r.data).results.bindings;
      if (data.length) {
        const head = JSON.parse(r.data).head.vars as string[];
mdroidian commented 1 year ago

🔥