TriplyDB / Yasgui

Yet Another Sparql GUI
https://yasgui.triply.cc
MIT License
185 stars 55 forks source link

Configuration instructions not working #138

Closed shawnhind closed 4 years ago

shawnhind commented 4 years ago

I'm trying to update our YASGUI to use the new mono repo instead of the separate components. I'm following the instructions on your documentation page at: https://triply.cc/docs/yasgui-api#yasgui-config but I think I must be missing a step or misunderstanding.

The problem is that even when using the yasgui initialization line you gave as an example it still queries dbpedia rather than example.com/sparql.

Here's the initialization line that I'm trying from the docs:

const yasgui = new Yasgui(document.getElementById("yasgui"), {
  yasqe: { requestOpts: { endpoint: "http://example.com/sparql" } }
});

However after clicking the query button in yasqe this is still querying dbpedia rather than example.com/sparql.

And here's the config object of YASGUI after initialization:

{
   "autofocus":true,
   "tabName":"Query",
   "persistencyExpire":2592000,
   "persistenceLabelResponse":"response",
   "persistenceLabelConfig":"config",
   "yasqe":{
      "mode":"sparql11",
      "value":"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nSELECT * WHERE {\n  ?sub ?pred ?obj .\n} LIMIT 10",
      "highlightSelectionMatches":{
         "showToken":{

         }
      },
      "tabMode":"indent",
      "lineNumbers":true,
      "lineWrapping":true,
      "foldGutter":{

      },
      "collapsePrefixesOnLoad":false,
      "gutters":[
         "gutterErrorBar",
         "CodeMirror-linenumbers",
         "CodeMirror-foldgutter"
      ],
      "matchBrackets":true,
      "fixedGutter":true,
      "syntaxErrorCheck":true,
      "autocompleters":[
         "variables",
         "prefixes",
         "property",
         "class"
      ],
      "extraKeys":{

      },
      "pluginButtons":null,
      "createShortLink":null,
      "persistencyExpire":2592000,
      "showQueryButton":true,
      "requestOpts":{
         "endpoint":"http://example.com/sparql",
         "method":"POST",
         "acceptHeaderGraph":"text/turtle,*/*;q=0.9",
         "acceptHeaderSelect":"application/sparql-results+json,*/*;q=0.9",
         "acceptHeaderUpdate":"text/plain,*/*;q=0.9",
         "namedGraphs":[

         ],
         "defaultGraphs":[

         ],
         "args":[

         ],
         "headers":{

         },
         "withCredentials":false,
         "adjustQueryBeforeRequest":null
      },
      "hintConfig":{
         "container":{

         }
      },
      "resizeable":true,
      "editorHeight":"300px"
   },
   "yasr":{
      "persistencyExpire":2592000,
      "persistenceLabelResponse":"response",
      "persistenceLabelConfig":"config",
      "maxPersistentResponseSize":100000,
      "prefixes":{

      },
      "plugins":{
         "table":{
            "enabled":true
         },
         "boolean":{
            "enabled":true
         },
         "response":{
            "enabled":true
         },
         "error":{
            "enabled":true
         }
      },
      "pluginOrder":[
         "table",
         "response"
      ],
      "defaultPlugin":"table"
   },
   "endpoint":"https://dbpedia.org/sparql",
   "endpointCatalogueOptions":{
      "keys":[
         "endpoint"
      ]
   },
   "copyEndpointOnNewTab":true,
   "populateFromUrl":true,
   "autoAddOnInit":true,
   "requestConfig":{
      "endpoint":"https://dbpedia.org/sparql",
      "method":"POST",
      "acceptHeaderGraph":"text/turtle,*/*;q=0.9",
      "acceptHeaderSelect":"application/sparql-results+json,*/*;q=0.9",
      "acceptHeaderUpdate":"text/plain,*/*;q=0.9",
      "namedGraphs":[

      ],
      "defaultGraphs":[

      ],
      "args":[

      ],
      "headers":{

      },
      "withCredentials":false,
      "adjustQueryBeforeRequest":null
   }
}
LaurensRietveld commented 4 years ago

I've updated the documentation, could you check whether that works for you?

shawnhind commented 4 years ago

@LaurensRietveld thanks for the response.

I just tried copying the updated line from the docs:

const yasgui = new Yasgui(document.getElementById("yasgui"), {
                requestOpts: { endpoint: "http://example.com/sparql" },
                copyEndpointOnNewTab: false  
            });

I emptied local storage, did an empty cache and hard refresh and it's still querying dbpedia rather than example.com/sparql.

LaurensRietveld commented 4 years ago

@shawnhind Was hoping you were a bit slower as I pushed another commit fixing a typo. The snippet should be:

const yasgui = new Yasgui(document.getElementById("yasgui"), {
  requestConfig: { endpoint: "http://example.com/sparql" },
  copyEndpointOnNewTab: false  
});

Could you try that one?

shawnhind commented 4 years ago

@LaurensRietveld that works now. Thanks a lot for responding so quickly. Would you be able to clarify if the requestConfig object is also where I should set my headers?

LaurensRietveld commented 4 years ago

Yes, that's correct. I've added a bit more documentation about the request configuration

shawnhind commented 4 years ago

Awesome, thanks again!

shawnhind commented 4 years ago

@LaurensRietveld how would I go about changing headers after initialization?

yasgui.config.requestConfig.headers = {
                    "X-CSRF-TOKEN": "somevalue",
                    "X-ACCOUNT-ID": "othervalue"
                }

This does change the headers in the object but then when the request is sent the server is still receiving the initial headers. Is there a setter method I need to call to have it propagate properly?