GraphQL Directive: @prefix
The @prefix directive is designed to manage and define namespace prefixes in a GraphQL query or schema. This directive can be used to either specify a single prefix with an IRI or map multiple prefixes to their corresponding IRIs.
Usage
The @prefix directive accepts two possible configurations:
- Single Prefix Definition: Use the
nameandiriarguments to define a single prefix. - Multiple Prefix Mapping: Use the
mapargument to define multiple prefixes in a key-value format.
Arguments
name(String): The prefix name to be used.iri(String): The IRI (Internationalized Resource Identifier) associated with the prefix.map(Map<String, String>): A map of prefix names to their corresponding IRIs.
Examples
-
Single Prefix Definition
Define a single prefix using the
nameandiriarguments:{ field @prefix(name: "rdf", iri: "http://www.w3.org/1999/02/22-rdf-syntax-ns#") @prefix(name: "owl", iri: "http://www.w3.org/2002/07/owl#") } -
Multiple Prefix Mapping
Define multiple prefixes using the
mapargument. As GraphQL does not allow the empty string""as a key, thename/iriform can be used in conjunction with map:query MyQuery @prefix(map: { rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", rdfs: "http://www.w3.org/2000/01/rdf-schema#" }, name: "", iri: "http://my.domain/ontology/) { # ... }
Notes
- When using the
mapargument, you can define multiple prefix-to-IRI mappings in a single directive instance.