Commit f468d58e authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Init

parents
import * as express from 'express';
import {Duniter} from 'duniter';
import {UpnpProvider} from "duniter/app/modules/upnp-provider";
import graphqlHTTP = require("express-graphql");
import {makeExecutableSchema} from "graphql-tools";
Duniter.run([{
name: 'gva',
required: {
duniter: {
cli: [{
name: 'gva',
desc: 'Starts the UI',
onDatabaseExecute: async (server, conf, program, params, start, stop) => {
// Never ending
await new Promise(async (res, rej) => {
try {
await start();
} catch (e) {
rej(e)
}
})
}
}],
service: {
neutral: (server, conf, logger) => {
let api = new UpnpProvider(
15000,
16000,
':gva:' + conf.pair.pub.substr(0, 6))
let app = express()
return {
startService: async () => {
const schema = makeExecutableSchema({
typeDefs: `
type Certification {
from: String!
to: String!
}
type Identity {
uid: String!
pub: String!
certs: [Certification!]!
}
type Query {
hello: String
identity(uid: String!): Identity
}
`,
resolvers: {
Query: {
hello: () => 'Hello world!',
identity: async (_, { uid }: { uid: string }) => {
return server.dal.iindexDAL.getFullFromUID(uid)
},
},
Identity: {
certs: async (identity: { pub:string }) => {
return (await server.dal.cindexDAL.getValidLinksTo(identity.pub)).map(c => ({
from: c.issuer,
to: c.receiver,
}))
}
}
}
})
// app.use('/graphql', graphqlHTTP({
// schema,
// graphiql: true,
// }))
// app.listen(15000, () => console.log(`Now browse to ${'192.168.1.24'}:${15000}/graphql`))
const { available, host, port } = { available: true, host: 'localhost', port: 15000 }
// const { available, host, port } = await api.startRegular()
if (available) {
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true,
}))
app.listen(port, () => console.log(`Now browse to ${host}:${port}/graphql`))
}
},
stopService: async () => {
return undefined;
}
} as any
}
}
}
}
}])
{
"name": "gva-api",
"version": "0.0.1",
"main": "index.js",
"license": "MIT",
"dependencies": {
"express": "^4.16.4",
"express-graphql": "^0.7.1",
"graphql": "^14.0.2",
"graphql-tools": "^4.0.3"
},
"devDependencies": {
"@types/express": "^4.16.0",
"@types/express-graphql": "^0.6.2",
"@types/graphql": "^14.0.3",
"duniter": "file:///home/cgeek/dev/duniter",
"typescript": "^3.1.6"
}
}
{
"compilerOptions": {
"sourceMap": true,
"target": "es2017",
"declaration": true,
"moduleResolution": "node",
"module": "commonjs",
"strictNullChecks": true,
"noImplicitThis": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"experimentalDecorators": true,
"lib": ["es6", "dom", "esnext"]
},
"include": [
"*.ts"
],
"compileOnSave": true
}
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment