Skip to content

Conversation

@white-gecko
Copy link
Member

@white-gecko white-gecko commented Oct 8, 2020

Fixes issue of POST requests in combination with default-graph as introduced in #1022 and #1175.

Proposed Changes

  • Introduce method POST_FORM besides POST to let the user control whether to use query via URL-encoded POST or query via POST directly as per the SPARQL 1.1 Protocol for query operations (https://www.w3.org/TR/sparql11-protocol/#query-operation)
  • Set the default-graph parameters accordingly

Test

A unit test is still needed for this behavior.

I have written the following test case (also committed here: https://github.com/white-gecko/rdflib/tree/fix_sparqlstore_post_sketchtest), but it requires a context aware SPARQL endpoint at http://localhost:5000/sparql with the following data loaded. This can be achieved on a local setup with a QuitStore or maybe also Virtuoso. Unfortunately the fuseki included is not context aware afaik.

graph <http://example.org/> {
    <http://example.org/ExampleInstance> a <http://example.org/Example>
}
graph <http://othergraph.org/> {
    <http://example.org/OtherInstance> a <http://example.org/Example>
}
class SPARQLStoreQuitStoreTestCase(unittest.TestCase):
    store_name = "SPARQLStore"
    path = "http://localhost:5000/sparql"
    create = False

    def test_query_via_get(self):
        store = SPARQLStore(query_endpoint=self.path, method="GET")
        self.execute_query_with_store(store)

    def test_query_via_post(self):
        store = SPARQLStore(query_endpoint=self.path, method="POST")
        self.execute_query_with_store(store)

    def test_query_via_post_form(self):
        store = SPARQLStore(query_endpoint=self.path, method="POST_FORM")
        self.execute_query_with_store(store)

    def execute_query_with_store(self, store):
        conjunctivegraph = ConjunctiveGraph(store=store)
        graph = conjunctivegraph.get_context(URIRef("http://example.org/"))
        query = "select distinct ?inst where {?inst a <http://example.org/Example>}"
        res = graph.query(query, initNs={})
        assert len(res) == 1
        for i in res:
            assert type(i[0]) == URIRef, i[0].n3()
            assert i[0] == URIRef("http://example.org/ExampleInstance"), i[0].n3()

@coveralls
Copy link

coveralls commented Oct 8, 2020

Coverage Status

Coverage increased (+0.03%) to 75.455% when pulling 647f34a on white-gecko:fix_sparqlstore_post into 7a53c61 on RDFLib:master.

white-gecko added a commit to white-gecko/rdflib that referenced this pull request Oct 8, 2020
@nicholascar
Copy link
Member

@ashleysommer a final check from you please!

(thanks for adding this @white-gecko: I'm keen to sort out all our SPARQLStore issues as I'm using it a lot now)

@nicholascar nicholascar merged commit 7e2c8e3 into RDFLib:master Dec 27, 2020
@white-gecko white-gecko deleted the fix_sparqlstore_post branch December 28, 2020 13:57
@white-gecko white-gecko added this to the rdflib 6.0.0 milestone Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants