This commit is contained in:
ryanwong
2022-02-06 22:15:10 -05:00
parent 46625dd6cd
commit a07577bffa
145 changed files with 12008 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* note Resolve All
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError } = require('apollo-server-express');
const Sequelize = require('sequelize');
const { last } = require('lodash');
const graphqlFields = require('graphql-fields');
module.exports = async (_, { first, after }, { db, credential }, info) => {
//Check Auth if user allowed
try {
const attributes = db.note.intersection(graphqlFields(info).edges.node);
const options = {
where: {},
limit: first,
attributes,
};
if (after) {
options.where = {
id: {
[Sequelize.Op.gt]: after,
},
};
}
const { count, rows } = await db.note.findAndCountAll(options);
const edges = rows.map((note) => ({
cursor: note.id,
node: note,
}));
const pageInfo = {
endCursor: last(edges)?.cursor,
hasNextPage: 0 < count - first,
};
return {
edges,
pageInfo,
};
} catch (error) {
console.log('note -> error', error);
return new ApolloError('InternalServerError');
}
}