GraphQL for JSON-LD issues

I have loaded the folloing JSON-LD from "Libary" tab of https://json-ld.org/playground/ into Stardog:

{
  "@context": {
    "dc11": "http://purl.org/dc/elements/1.1/",
    "ex": "http://example.org/vocab#",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "ex:contains": {
      "@type": "@id"
    }
  },
  "@graph": [
    {
      "@id": "http://example.org/library",
      "@type": "ex:Library",
      "ex:contains": "http://example.org/library/the-republic"
    },
    {
      "@id": "http://example.org/library/the-republic",
      "@type": "ex:Book",
      "dc11:creator": "Plato",
      "dc11:title": "The Republic",
      "ex:contains": "http://example.org/library/the-republic#introduction"
    },
    {
      "@id": "http://example.org/library/the-republic#introduction",
      "@type": "ex:Chapter",
      "dc11:description": "An introductory chapter on The Republic.",
      "dc11:title": "The Introduction"
    }
  ]
}
  • But how do I GraphQL query it?

The following errors out:

query withPrefixes @prefix(ex: "http://example.org/vocab#") {
    ex_Book {        
        dc11_title
    }
}

I've also added ex namespace prefix to Stardog database and tried with no @prefix directive but getting this error:

QE0PE2: Encountered " <FUNCTION_NAME> "query "" at line 1, column 1.
Was expecting one of:
    <EOF> 
    ";" ...
    <HINT> ...

Never mind - it works now - I just had to save the file - as library.graphql - then it ran just fine

Now that it brings back the title:

{
  "data": [
    {
      "dc11_title": "The Republic"
    }
  ]
}
  • How can I get the "@id" in the results?

Thanks,
Radu

Radu,

@id is a JSON-LD specific keyword. In GraphQL you can query for the iri property to get this value.

Stephen,

Thank you for sharing this tip on "iri" - works but the results are coming back as:

  • iri": "cc_resource/attack/T1156",

cc is my namespace defined in Stardog