Skip to content

Commit 4f16d3b

Browse files
author
Salah Eddine Lalami
authored
new schema js/ts generated (#3)
1 parent 07b123f commit 4f16d3b

3 files changed

Lines changed: 45 additions & 18 deletions

File tree

index.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,27 @@ var mergeSchemas = function (_a) {
4646
};
4747
exports.mergeSchemas = mergeSchemas;
4848
var generateSchema = function (_a) {
49-
var inputPath = _a.inputPath, outPath = _a.outPath;
49+
var inputPath = _a.inputPath, _b = _a.schemaPath, schemaPath = _b === void 0 ? "" : _b, _c = _a.typeDefsPath, typeDefsPath = _c === void 0 ? "" : _c;
5050
var mergedSchemas = (0, exports.mergeSchemas)({ pathfiles: inputPath });
5151
var schema = mergedSchemas.join(" ");
52-
fs.writeFile(outPath, schema, function (err) {
53-
if (err) {
54-
console.error(err);
55-
return;
56-
}
57-
});
58-
console.log(" ✔ Schema Generated : ", outPath);
52+
if (schemaPath !== "") {
53+
fs.writeFile(schemaPath, schema, function (err) {
54+
if (err) {
55+
console.error(err);
56+
return;
57+
}
58+
});
59+
console.log(" ✔ Schema Generated : ", schemaPath);
60+
}
61+
if (typeDefsPath !== "") {
62+
var typeDefs = "export default `" + schema + "`;";
63+
fs.writeFile(typeDefsPath, typeDefs, function (err) {
64+
if (err) {
65+
console.error(err);
66+
return;
67+
}
68+
});
69+
console.log(" ✔ typeDefs Generated : ", typeDefsPath);
70+
}
5971
};
6072
exports.generateSchema = generateSchema;

index.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,36 @@ export const mergeSchemas = ({
5050

5151
export const generateSchema = ({
5252
inputPath,
53-
outPath,
53+
schemaPath = "",
54+
typeDefsPath = "",
5455
}: {
5556
inputPath: string
56-
outPath: string
57+
schemaPath?: string
58+
typeDefsPath?: string
5759
}): void => {
5860
const mergedSchemas = mergeSchemas({ pathfiles: inputPath })
5961

6062
const schema = mergedSchemas.join(" ")
6163

62-
fs.writeFile(outPath, schema, (err: any) => {
63-
if (err) {
64-
console.error(err)
65-
return
66-
}
67-
})
64+
if (schemaPath !== "") {
65+
fs.writeFile(schemaPath, schema, (err: any) => {
66+
if (err) {
67+
console.error(err)
68+
return
69+
}
70+
})
71+
console.log(" ✔ Schema Generated : ", schemaPath)
72+
}
73+
74+
if (typeDefsPath !== "") {
75+
const typeDefs = "export default `" + schema + "`;"
6876

69-
console.log(" ✔ Schema Generated : ", outPath)
77+
fs.writeFile(typeDefsPath, typeDefs, (err) => {
78+
if (err) {
79+
console.error(err)
80+
return
81+
}
82+
})
83+
console.log(" ✔ typeDefs Generated : ", typeDefsPath)
84+
}
7085
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fast-graphql",
3-
"version": "1.1.2",
3+
"version": "2.0.0",
44
"description": "Graphql Tools to Strucutre , Combine Resolvers and Merge Schema Definitions",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)