chore: Refactor v2 folder and class structure + Adding Company App (dummy)

This commit is contained in:
Josepablo C
2024-08-07 00:59:50 -06:00
parent f8d41db04d
commit 288fdc10a7
24 changed files with 614 additions and 190 deletions

View File

@@ -0,0 +1,60 @@
'use strict';
const { createHandler } = require("graphql-http/lib/use/express");
/// Include graphql schema and resolvers
const schemaDescription = require('./graphql/schema.js');
const schemaResolvers = require('./graphql/resolvers.js');
const { initEvents } = require('../Domain');
async function test(req, res, next){
console.log( req.requestContext );
res.status(200).send({
msg : "It is alive!"
});
}
module.exports = {
AppInit : initEvents, /// Dummy App Init
hooks : {
before: {
/**Array of middleware functions*/
all : [],
del : [],
get : [ test ],
patch : [],
post : [],
put : []
},
after: {
/**Array of middleware functions*/
all : [],
del : [],
get : [],
patch : [],
post : [],
put : []
},
custom: {
/**Array of objects like { endpoint, middleware }*/
all : [],
del : [],
get : [],
patch : [],
post : [
{ '/graphql' :
createHandler({
schema: schemaDescription,
rootValue : schemaResolvers,
context: async (req, params) => { return { requestContext : req.raw.requestContext }; },
graphiql: true
})
}
],
put : []
}
}
};

View File

@@ -1,26 +1,13 @@
'use strict';
const router = require('express').Router();
const { createHandler } = require("graphql-http/lib/use/express");
const { hooks, AppInit } = require( './hooks' );
const GenericController = require('../../Lib');
/// Include graphql schema and resolvers
const schemaDescription = require('./graphql/schema.js');
const schemaResolvers = require('./graphql/resolvers.js');
class PrivateResources extends GenericController {
init(){
super.init();
AppInit();
}
}
router.get('/test', async (req, res) => {
console.log( req.requestContext );
res.status(200).send({
msg : "It is alive!"
});
} );
router.post( '/graphql',
createHandler({
schema: schemaDescription,
rootValue : schemaResolvers,
context: async (req, params) => { return { requestContext : req.raw.requestContext }; },
graphiql: true
})
);
module.exports = router;
module.exports = new PrivateResources( hooks );