Add files via upload

Add resolvers, globals and server script
This commit is contained in:
Jaime Idolpx 2022-06-14 11:38:53 -05:00 committed by GitHub
parent 1a41e9d5ea
commit 22a6904638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 583 additions and 1 deletions

7
server/globals.js Normal file
View File

@ -0,0 +1,7 @@
const globals = {
data_path: '/var/www/csdbng/data'
}
module.exports = { globals }

16
server/package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "csdb-ng",
"version": "1.0.0",
"description": "CSDb-ng GraphQL Server",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"mon": "nodemon ./server.js localhost 3000"
},
"author": "Jaime Idolpx",
"license": "MIT",
"dependencies": {
"apollo-server": "^3.7.0",
"graphql": "^16.5.0"
}
}

View File

@ -0,0 +1,62 @@
let globals = require('../globals.js').globals;
const resolvers = {
Query: {
getBBS: (parent, { id }, context, info) => getBBS(id),
},
Mutation: {
createBBS: (parent, { data }, context, info) => createBBS(data),
updateBBS: (parent, { id }, context, info) => updateBBS(id),
deleteBBS: (parent, { id }, context, info) => deleteBBS(id),
},
//////////
BBS: {
GroupIDs: ({ GroupIDs }, args, context, info) => addGroups(GroupIDs, context),
UserHandleIDs: ({ UserHandleIDs }, args, context, info) => addHandles(UserHandleIDs, context),
Groups: (parent, args, context, info) => context.Groups,
Handles: (parent, args, context, info) => context.Handles,
},
BBSSysop: {
HandleID: ({ HandleID }, args, context, info) => addHandle(HandleID, context),
},
}
getBBSFile = id => `${globals.data_path}/bbs/${id}/bbs.${id}.json`;
// Object loader
getBBS = id => {
return loadJSON(getBBSFile(id));
}
// Load object by ID or ID array
addBBS = (id, context) => {
addBBSs([id], context);
return id;
}
addBBSs = (idArray, context) => {
try {
idArray.forEach( id => {
// Add object if it isn't already added
if (!objectExists(context, 'BBSs', id)) {
data = getBBS(id);
addElementToObjectArray( context, 'BBSs', data );
}
})
}
catch(err) {
// console.log(err);
}
return idArray;
}
module.exports = { resolvers } // , getBBSFile, getBBS, addBBS, addBBSs }

View File

@ -0,0 +1,70 @@
let globals = require('../globals.js').globals;
const resolvers = {
Query: {
getEvent: (parent, { id }, context, info) => getEvent(id),
},
Mutation: {
createEvent: (parent, { data }, context, info) => createEvent(data),
updateEvent: (parent, { id }, context, info) => updateEvent(id),
deleteEvent: (parent, { id }, context, info) => deleteEvent(id),
},
//////////
Event: {
Releases: (parent, args, context, info) => context.Releases,
Groups: (parent, args, context, info) => context.Groups,
Handles: (parent, args, context, info) => context.Handles,
},
EventCompo: {
ReleaseIDs: ({ ReleaseIDs }, args, context, info) => addReleases(ReleaseIDs, context),
},
EventReport: {
HandleID: ({ HandleID }, args, context, info) => addHandle(HandleID, context),
},
EventComment: {
HandleID: ({ HandleID }, args, context, info) => addHandle(HandleID, context),
},
EventOrganizers: {
GroupIDs: ({ GroupIDs }, args, context, info) => addGroups(GroupIDs, context),
HandleIDs: ({ HandleIDs }, args, context, info) => addHandles(HandleIDs, context),
},
}
getEventFile = id => `${globals.data_path}/event/${id}/event.${id}.json`;
// Object loader
getEvent = id => {
return loadJSON(getEventFile(id));
}
// Load object by ID or ID array
addEvent = (id, context) => {
addEvents([id], context);
return id;
}
addEvents = (idArray, context) => {
try {
idArray.forEach( id => {
// Add object if it isn't already added
if (!objectExists(context, 'Events', id)) {
data = getEvent(id);
addElementToObjectArray( context, 'Events', data );
}
})
}
catch(err) {
// console.log(err);
}
return idArray;
}
module.exports = { resolvers } // , getEventFile, getEvent, addEvent, addEvents }

View File

@ -0,0 +1,70 @@
let globals = require('../globals.js').globals;
const resolvers = {
Query: {
getGroup: (parent, { id }, context, info) => getGroup(id),
},
Mutation: {
createGroup: (parent, { data }, context, info) => createGroup(data),
updateGroup: (parent, { id }, context, info) => updateGroup(id),
deleteGroup: (parent, { id }, context, info) => deleteGroup(id),
},
//////////
Group: {
ReleaseIDs: ({ ReleaseIDs }, args, context, info) => addReleases(ReleaseIDs, context),
FounderHandleIDs: ({ FounderHandleIDs }, args, context, info) => addHandles(FounderHandleIDs, context),
OrganizedEventIDs: ({ OrganizedEventIDs }, args, context, info) => addEvents(OrganizedEventIDs, context),
BBSIDs: ({ BBSIDs }, args, context, info) => addBBSs(BBSIDs, context),
Releases: (parent, args, context, info) => context.Releases,
Sceners: (parent, args, context, info) => context.Sceners,
Handles: (parent, args, context, info) => context.Handles,
Events: (parent, args, context, info) => context.Events,
BBSs: (parent, args, context, info) => context.BBSs,
},
GroupCommentData: {
ScenerID: ({ ScenerID }, args, context, info) => addScener(ScenerID, context),
},
GroupMember: {
HandleID: ({ HandleID }, args, context, info) => addHandle(HandleID, context),
},
}
getGroupFile = id => `${globals.data_path}/group/${id}/group.${id}.json`;
// Object loader
getGroup = id => {
return loadJSON(getGroupFile(id));
}
// Load object by ID or ID array
addGroup = (id, context) => {
addGroups([id], context);
return id;
}
addGroups = (idArray, context) => {
try {
idArray.forEach( id => {
// Add object if it isn't already added
if (!objectExists(context, 'Groups', id)) {
data = getGroup(id);
addElementToObjectArray( context, 'Groups', data );
}
})
}
catch(err) {
// console.log(err);
}
return idArray;
}
module.exports = { resolvers } // , getGroupFile, getGroup, addGroup, addGroups }

View File

@ -0,0 +1,69 @@
let globals = require('../globals.js').globals;
const resolvers = {
Query: {
getHandle: (parent, { id }, context, info) => getHandle(id),
},
Mutation: {
createHandle: (parent, { data }, context, info) => createHandle(data),
updateHandle: (parent, { id }, context, info) => updateHandle(id),
deleteHandle: (parent, { id }, context, info) => deleteHandle(id),
},
//////////
Handle: {
FoundedGroupIDs: ({ FoundedGroupIDs }, args, context, info) => addGroups(FoundedGroupIDs, context),
OrganizedEventIDs: ({ OrganizedEventIDs }, args, context, info) => addEvents(OrganizedEventIDs, context),
AttendedEventIDs: ({ AttendedEventIDs }, args, context, info) => addEvents(AttendedEventIDs, context),
ScenerIDs: ({ ScenerIDs }, args, context, info) => addSceners(ScenerIDs, context),
Releases: (parent, args, context, info) => context.Releases,
Groups: (parent, args, context, info) => context.Groups,
Sceners: (parent, args, context, info) => context.Sceners,
Events: (parent, args, context, info) => context.Events,
},
HandleGroup: {
GroupID: ({ GroupID }, args, context, info) => addGroup(GroupID, context),
},
HandleCredit: {
ReleaseID: ({ ReleaseID }, args, context, info) => addRelease(ReleaseID, context),
},
}
getHandleFile = id => `${globals.data_path}/handle/${id}/handle.${id}.json`;
// Object loader
getHandle = id => {
return loadJSON(getHandleFile(id));
}
// Load object by ID or ID array
addHandle = (id, context) => {
addHandles([id], context);
return id;
}
addHandles = (idArray, context) => {
try {
idArray.forEach( id => {
// Add object if it isn't already added
if (!objectExists(context, 'Handles', id)) {
data = getHandle(id);
addElementToObjectArray( context, 'Handles', data );
}
})
}
catch(err) {
// console.log(err);
}
return idArray;
}
module.exports = { resolvers } // , getHandleFile, getHandle, addHandle, addHandles }

View File

@ -0,0 +1,89 @@
const fs = require('fs');
const release = require('./resolvers.release.js');
const group = require('./resolvers.group.js');
const scener = require('./resolvers.scener.js');
const handle = require('./resolvers.handle.js');
const event = require('./resolvers.event.js');
const bbs = require('./resolvers.bbs.js');
const sid = require('./resolvers.sid.js');
let resolvers = {
...release.resolvers,
...group.resolvers,
...scener.resolvers,
...handle.resolvers,
...event.resolvers,
...bbs.resolvers,
...sid.resolvers,
Query: {
...release.resolvers.Query,
...group.resolvers.Query,
...scener.resolvers.Query,
...handle.resolvers.Query,
...event.resolvers.Query,
...bbs.resolvers.Query,
...sid.resolvers.Query,
},
Mutation: {
...release.resolvers.Mutation,
...group.resolvers.Mutation,
...scener.resolvers.Mutation,
...handle.resolvers.Mutation,
...event.resolvers.Mutation,
...bbs.resolvers.Mutation,
...sid.resolvers.Mutation,
}
}
// console.log(resolvers);
// Util Functions
loadJSON = filename => {
console.log(filename);
if ( !fs.existsSync(filename) )
return null;
const data = fs.readFileSync(filename, {encoding:'utf8', flag:'r'});
if ( !data )
console.log(`Empty or missing file [${filename}]`);
return JSON.parse(data);
}
// Add element to object array
addElementToObjectArray = (object, array, element) => {
if ( element != null ) {
// Does the array exist?
if (typeof object[array] != "undefined") {
// No - Add it
object[array].push(element);
} else {
// No - Create the array
object[array] = [element];
}
}
}
// Check to see if ID exists in array
objectExists = (object, array, id) => {
let found = false;
try {
if (object[array] !== undefined) {
if (object[array].find(element => element.ID === id)) {
found = true;
// console.log(`found: ${found}, id: ${id}`);
}
}
}
catch(err) {
//
}
return found;
}
module.exports = { resolvers }

View File

@ -0,0 +1,72 @@
let globals = require('../globals.js').globals;
const resolvers = {
Query: {
getRelease: (parent, { id }, context, info) => getRelease(id),
},
Mutation: {
createRelease: (parent, { data }, context, info) => createRelease(data),
updateRelease: (parent, { id }, context, info) => updateRelease(id),
deleteRelease: (parent, { id }, context, info) => deleteRelease(id),
},
//////////
Release: {
ReleasedAt: ({ ReleasedAt }, args, context, info) => addEvent(ReleasedAt, context),
SIDIDs: ({ SIDIDs }, args, context, info) => addSIDs(SIDIDs, context),
Groups: (parent, args, context, info) => context.Groups,
Sceners: (parent, args, context, info) => context.Sceners,
Handles: (parent, args, context, info) => context.Handles,
Events: (parent, args, context, info) => context.Events,
SIDs: (parent, args, context, info) => context.SIDs,
},
ReleaseGroupsHandles: {
GroupIDs: ({ GroupIDs }, args, context, info) => addGroups(GroupIDs, context),
HandleIDs: ({ HandleIDs }, args, context, info) => addHandles(HandleIDs, context),
},
ReleaseCredit: {
HandleID: ({ HandleID }, args, context, info) => addHandle(HandleID, context),
},
ReleaseCommentData: {
ScenerID: ({ ScenerID }, args, context, info) => addScener(ScenerID, context),
},
}
getReleaseFile = id => `${globals.data_path}/release/${id}/release.${id}.json`;
// Object loader
getRelease = id => {
return loadJSON(getReleaseFile(id));
}
// Load object by ID or ID array
addRelease = (id, context) => {
addReleases([id], context);
return id;
}
addReleases = (idArray, context) => {
try {
idArray.forEach( id => {
// Add object if it isn't already added
if (!objectExists(context, 'Releases', id)) {
data = getRelease(id);
addElementToObjectArray( context, 'Releases', data );
}
})
}
catch(err) {
// console.log(err);
}
return idArray;
}
module.exports = { resolvers } // , getReleaseFile, getRelease, addRelease, addReleases }

View File

@ -0,0 +1,56 @@
let globals = require('../globals.js').globals;
const resolvers = {
Query: {
getScener: (parent, { id }, context, info) => getScener(id),
},
Mutation: {
createScener: (parent, { data }, context, info) => createScener(data),
updateScener: (parent, { id }, context, info) => updateScener(id),
deleteScener: (parent, { id }, context, info) => deleteScener(id),
},
//////////
Scener: {
HandleIDs: ({ HandleIDs }, args, context, info) => addHandles(HandleIDs, context),
Handles: (parent, args, context, info) => context.Handles,
},
}
getScenerFile = id => `${globals.data_path}/scener/${id}/scener.${id}.json`;
// Object loader
getScener = id => {
return loadJSON(getScenerFile(id));
}
// Load object by ID or ID array
addScener = (id, context) => {
addSceners([id], context);
return id;
}
addSceners = (idArray, context) => {
try {
idArray.forEach( id => {
// Add object if it isn't already added
if (!objectExists(context, 'Sceners', id)) {
data = getScener(id);
addElementToObjectArray( context, 'Sceners', data );
}
})
}
catch(err) {
//console.log(err);
}
return idArray;
}
module.exports = { resolvers } // , getScenerFile, getScener, addScener, addSceners }

View File

@ -0,0 +1,57 @@
let globals = require('../globals.js').globals;
const resolvers = {
Query: {
getSID: (parent, { id }, context, info) => getSID(id),
},
Mutation: {
createSID: (parent, { data }, context, info) => createSID(data),
updateSID: (parent, { id }, context, info) => updateSID(id),
deleteSID: (parent, { id }, context, info) => deleteSID(id),
},
//////////
SID: {
ReleaseIDs: ({ ReleaseIDs }, args, context, info) => addReleases(ReleaseIDs, context),
Releases: (parent, args, context, info) => context.Releases,
}
}
getSIDFile = id => `${globals.data_path}/sid/${id}/sid.${id}.json`;
// Object loader
getSID = id => {
return loadJSON(getSIDFile(id));
}
// Load object by ID or ID array
addSID = (id, context) => {
addSIDs([id], context);
return id;
}
addSIDs = (idArray, context) => {
try {
idArray.forEach( id => {
// Add object if it isn't already added
if (!objectExists(context, 'SIDs', id)) {
data = getSID(id);
addElementToObjectArray( context, 'SIDs', data );
}
})
}
catch(err) {
// console.log(err);
}
return idArray;
}
module.exports = { resolvers } // , getSIDFile, getSID, addSID, addSIDs }

View File

@ -127,6 +127,7 @@ type Group {
Rating: Float Rating: Float
Trivia: String Trivia: String
BaseCountry: String BaseCountry: String
IsCoOp: Boolean
FoundDate: [FuzzyDate] FoundDate: [FuzzyDate]
DissolveDate: [FuzzyDate] DissolveDate: [FuzzyDate]

13
server/server.js Normal file
View File

@ -0,0 +1,13 @@
const { ApolloServer } = require('apollo-server');
const fs = require('fs');
const typeDefs = fs.readFileSync('./schema.graphql', { encoding:'utf-8' })
const resolvers = require('./resolvers/resolvers.js').resolvers
const server = new ApolloServer({ typeDefs, resolvers });
server
.listen({ port: 3000 })
.then(({ url }) => console.log(`Server running at ${url}`));