Using GraphQL
OWLGraph automatically generates a GraphQL schema from your OWL ontology. Classes become types, properties become fields, and class hierarchies become interface implementations.
How It Works
Section titled “How It Works”When you load an ontology, OWLGraph’s GraphQL generator:
- Maps each OWL class to a GraphQL type
- Maps
rdfs:subClassOfto GraphQLimplements(parent becomes an interface) - Maps object properties to relationship fields
- Maps data properties to scalar fields
- Maps
owl:inverseOfto@hasInversedirectives
Example: From Ontology to GraphQL
Section titled “Example: From Ontology to GraphQL”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")}Querying
Section titled “Querying”Once the GraphQL schema is generated, you can query using standard GraphQL:
# Get all dogs with their ownersquery { queryDog { name hasOwner { name } }}
# Get all animals (subsumption — returns Dogs, Cats, etc.)query { queryAnimal { name __typename }}Mutations
Section titled “Mutations”# Add a dogmutation { 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.
Accessing the GraphQL API
Section titled “Accessing the GraphQL API”The GraphQL endpoint is available at:
POST https://YOUR-INSTANCE/graphqlYou can also explore the schema using any GraphQL IDE (GraphiQL, Apollo Studio, etc.) pointed at your instance.
Limitations
Section titled “Limitations”- 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