dherault / semantic-graphql

Create GraphQL schemas from RDF ontologies
MIT License
93 stars 13 forks source link

More examples and documentation #2

Open xmnlab opened 5 years ago

xmnlab commented 5 years ago

hey everyone,

I am trying to adapt https://github.com/dherault/aquest to use schema.org ttl files but I am not sure how to make that work. also printSchema just return:

"""An object with an ID"""
interface Node {
  """The id of the object."""
  id: ID!
}

type Query {
  """Fetches an object given its ID"""
  node(
    """The ID of an object"""
    id: ID!
  ): Node
}

not sure if it is the correct output.

xmnlab commented 5 years ago

when I start the service, the output is:

graph created: [SemanticGraph: 6099 triples]
GraphQL endpoint listening on port 3001
dherault commented 5 years ago

You need an entrypoint in your schema. Can your paste your schema file ? It should be a bit like this:

const schema = new GraphQLSchema({
    node: nodeField,
    person: personField,
})

where person: personField is your entry point. personField should be of type Person, found in the graph.

xmnlab commented 5 years ago

currently my schema is just:

module.exports = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      // Relay's favorite
      node: _.nodeField,
      // Helpers for common app resources
      // Viewer's data entry point
      /*
      viewer: {
        resolve: (source, args, { viewer }) => viewer,
      },*/
    },
  }) /*,
  mutation: new GraphQLObjectType({
    name: 'Mutation',
    fields: mutationFields,
  }),*/
});

is there a way add this entrypoints automatically from rdf? schema.org has a lot of entities/types ....

dherault commented 5 years ago

Well you could modify your schema like this:

module.exports = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      // Relay's favorite
      node: _.nodeField,
      // Helpers for common app resources
      // Viewer's data entry point
      /*
      viewer: {
        type: _.getObjectType('http://schema.org/Person'),
        resolve: (source, args, { viewer }) => viewer,
      },*/
    },
  }) /*,
  mutation: new GraphQLObjectType({
    name: 'Mutation',
    fields: mutationFields,
  }),*/
});

The type http://schema.org/Person will insert in your schema all the triples relative to Person, including its super classes.

dherault commented 5 years ago

Have a look at the examples folder for more info.

xmnlab commented 5 years ago

yes I have look that. I could add manually types like Dataset and Person .. but not sure yet how to add all fields automatically.

xmnlab commented 5 years ago

I am playing with that here: https://github.com/Quansight/ivan-sandbox/blob/master/semantic-graphql-test/service/src/schema.js

dherault commented 5 years ago

To add all fields automatically, you'll have to iterate on all your classes and add a field for each class. Or you can add this entrypoint:

     resource: {
        // The rdfs:Resource interface allows you to query any data
        type: _.getInterfaceType('http://www.w3.org/2000/01/rdf-schema#Resource'),
        args: {
          id: { type: new GraphQLNonNull(GraphQLString) },
        },
        resolve: /* ... */,
      },
xmnlab commented 5 years ago

thanks @dherault I will try that!