Manually registered GraphQL schemas

Hi Miel,

First, looks like a I made a mistake in my first message when I described the schema annotations. These annotations should be defined on fields (e.g. under QueryType) and not on the type definition. Second, the localname attribute can only be used with prefix but not namespace. That is why in the SPARQL query you are getting skos:label and not skos:prefLabel. So you need to change that definition to be either:

@iri(prefix : "skos", localname: "prefLabel") 

to use the already registered skos prefix or use the full IRI of the property int he directive:

@iri(value : "http://www.w3.org/2004/02/skos/core#prefLabel") 

So the final schema should look like this:

schema {
    query: QueryType
}

type QueryType {
    Organization(id: ID, orderBy: ID): Organization @iri(namespace : "http://www.w3.org/ns/org#")
}

interface IOrganization {
  label: String!                                  
  altLabel: String                                                                 
}

type Organization implements IOrganization {
  label: String!                                  @iri(value : "http://www.w3.org/2004/02/skos/core#prefLabel")
  altLabel: String                                @iri(namespace : "http://www.w3.org/2004/02/skos/core#")                                
}

Once you registered a default schema manually the value of graphql.auto.schema does not matter. But if you are querying without the schema (i.e. without the --schema option in the CLI) then the registered schema will not have an effect either.

To answer your other questions:

  • There is no inheritance of namespaces in the schema. They need to be specified for each field separately.
  • We use the built-in GraphQL type ID to represent IRIs. There is no id field by default. That property exists in the starwars example but it is just a regular property.
  • You can use iris filter to get a single resource but since the type of iri is an ID you cannot pass a string as in your example. You can do Human(iri: Alice) where the IRI will be resolved to the default namespace in the database or Human(iri: ex_Alice) to resolve it for the namespace ex.
  • Named graphs cannot be specified in the GraphQL schema, only in the queries. This would be a useful extension.
  • There can be one or more GraphQL schemas for each database. Each schema can expose a different subset of the underlying graph resulting in different APIs.

Best,
Evren

1 Like