-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
46 lines (38 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const path = require('path');
const { GraphQLSchema, GraphQLObjectType } = require('graphql'); // eslint-disable-line import/no-extraneous-dependencies
const graphqlHTTP = require('express-graphql');
const express = require('express');
const SemanticGraph = require('../..');
const data = require('./data');
const resolvers = require('./resolvers');
// You should check the basic example first
const _ = new SemanticGraph(resolvers, { relay: true });
console.log(`graph created: ${_}`);
_.parseFile(path.join(__dirname, './ontology.ttl'));
// Register connections
// This will add the proper mechanics around the field (ie the connectionArgs and the connectionResolver)
_['http://foo.com#hasComments'].isRelayConnection = true;
// Any part of the field can still be overriden with
// _['http://foo.com#hasComments'].graphqlFieldConfigExtension = { type: ..., resolve: ..., ...}
// Or the field can be overriden entirely using
// _['http://foo.com#hasComments'].graphqlFieldConfig = { type: ..., resolve: ..., ...}
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
article: {
type: _.getObjectType('http://foo.com#Article'),
descriptions: 'A cool article with paginated comments',
resolve: () => data[0],
},
node: _.nodeField,
},
}),
});
express()
.use('/graphql', graphqlHTTP({
schema,
pretty: true,
graphiql: true,
}))
.listen(3000, err => console.log(err || 'GraphQL endpoint listening on port 3000\n'));