Skip to content

Using GraphQL

OWLGraph automatically generates a GraphQL schema from your OWL ontology. Classes become types, properties become fields, and class hierarchies become interface implementations.

When you load an ontology, OWLGraph’s GraphQL generator:

  1. Maps each OWL class to a GraphQL type
  2. Maps rdfs:subClassOf to GraphQL implements (parent becomes an interface)
  3. Maps object properties to relationship fields
  4. Maps data properties to scalar fields
  5. Maps owl:inverseOf to @hasInverse directives

Given this ontology:

:Animal a owl:Class .
:Dog a owl:Class ; rdfs:subClassOf :Animal .
:name a owl:DatatypeProperty ; rdfs:range xsd:string .
:hasOwner a owl:ObjectProperty ;
rdfs:domain :Animal ; rdfs:range :Person .
:isOwnerOf a owl:ObjectProperty ;
owl:inverseOf :hasOwner .

OWLGraph generates:

interface Animal {
name: String
hasOwner: Person @hasInverse(field: "isOwnerOf")
}
type Dog implements Animal {
name: String
hasOwner: Person @hasInverse(field: "isOwnerOf")
}
type Person {
name: String
isOwnerOf: [Animal] @hasInverse(field: "hasOwner")
}

Once the GraphQL schema is generated, you can query using standard GraphQL:

# Get all dogs with their owners
query {
queryDog {
name
hasOwner {
name
}
}
}
# Get all animals (subsumption — returns Dogs, Cats, etc.)
query {
queryAnimal {
name
__typename
}
}
# Add a dog
mutation {
addDog(input: [{
name: "Rex"
hasOwner: { name: "Alice" }
}]) {
dog {
name
hasOwner { name }
}
}
}

The write-time materializer still runs — Rex gets Animal type automatically, and Alice gets an isOwnerOf edge back to Rex.

The GraphQL endpoint is available at:

POST https://YOUR-INSTANCE/graphql

You can also explore the schema using any GraphQL IDE (GraphiQL, Apollo Studio, etc.) pointed at your instance.

  • The GraphQL generator produces a schema that mirrors the ontology structure
  • Complex class expressions (intersections, unions) are simplified to their named class components
  • Property chain axioms are not directly representable in GraphQL but are still enforced by the materializer