Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-codegen-modules-gen

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-codegen-modules-gen - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

2

package.json
{
"name": "graphql-codegen-modules-gen",
"version": "1.1.3",
"version": "1.2.0",
"description": "",

@@ -5,0 +5,0 @@ "scripts": {

@@ -13,2 +13,3 @@ import {

const typedefsFolder = "typedefs";
const providersFolder = "providers";
const genFolder = "_gen";

@@ -48,2 +49,21 @@

}
/**
* toPascalCase
* @param {String} input
* @returns A string that has been converted into Pascal Case for keeping with the React Naming convention required for naming Components.
* @see https://stackoverflow.com/a/53952925/13301381
* @author kalicki2K
*/
function toPascalCase(input) {
return `${input}`
.replace(new RegExp(/[-_]+/, "g"), " ")
.replace(new RegExp(/[^\w\s]/, "g"), "")
.replace(
new RegExp(/\s+(.)(\w+)/, "g"),
($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`
)
.replace(new RegExp(/\s/, "g"), "")
.replace(new RegExp(/\w/), (s) => s.toUpperCase());
}
/* End - Functions Helpers*/

@@ -54,5 +74,8 @@

if (isFolderExist) {
let ctxModules = [];
const moduleNames = getDirectories(modulePath);
moduleNames.forEach((moduleName) => {
/* resolvers.ts */
/***************** */
/* 1/ resolvers.ts */
/***************** */
// import { resolvers as _Mutation } from '../resolvers/_Mutation';

@@ -93,3 +116,5 @@ // import { resolvers as _Query } from '../resolvers/_Query';

/* typedefs.ts */
/***************** */
/* 2/ typedefs.ts */
/***************** */
// import { gql } from 'graphql-modules';

@@ -140,3 +165,3 @@

console.log(
` ${getGreen("✔")} Merge -`,
` ${getGreen("✔")} Merge -`,
`${getGreen(pad(typedefsFiles.length, 2))} Typedefs`,

@@ -148,8 +173,64 @@ `|`,

);
/******************* */
/* 3.1/ ctxModules */
/******************* */
// Are there files starting by _ctx? file to add in the global ctxModules.ts file?
const providersFiles = getFiles(
join(modulePath, moduleName, providersFolder)
);
providersFiles.forEach((providerFile) => {
if (providerFile.startsWith("_ctx")) {
const ctxName = providerFile.replace("_ctx", "").replace(".ts", "");
ctxModules.push({ moduleName, ctxName });
}
});
});
console.log(
` ${getGreen("✔")} Merge done`,
` ${getGreen("✔")} Merge done`,
`[${getGreen(moduleNames.length)} modules]`
);
/******************* */
/* 3.2/ ctxModules */
/******************* */
let dataCtxModules = [];
ctxModules.forEach((ctx) => {
dataCtxModules.push(
`import { getCtx${toPascalCase(ctx.ctxName)} } from '../../modules/${
ctx.moduleName
}/providers/_ctx${toPascalCase(ctx.ctxName)}';`
);
});
dataCtxModules.push(``);
dataCtxModules.push(
`// Do not type contextSoFar as it will to a circular reference`
);
dataCtxModules.push(`export function getCtxModules(contextSoFar: any) {`);
dataCtxModules.push(` return {`);
ctxModules.forEach((ctx) => {
dataCtxModules.push(
` ...getCtx${toPascalCase(ctx.ctxName)}(contextSoFar.prisma),`
);
});
dataCtxModules.push(` };`);
dataCtxModules.push(`}`);
writeFileSync(
join(modulePath, "../graphql", genFolder, "ctxModules.ts"),
dataCtxModules.join("\r\n"),
(err) => {
console.error(err);
}
);
console.log(
` ${getGreen("✔")} Merge contexts for`,
`[${ctxModules
.map((c) => getGreen(c.moduleName + "#" + c.ctxName))
.join(",")}]`
);
} else {

@@ -156,0 +237,0 @@ console.error(`❌ '${modulePath}' is not a valid folder path`);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc