Skip to content

Commit 332e91a

Browse files
taeyzzzThanetpon Kultontikorn
andauthored
fix the way for gql-gen (#9)
* fix the way for gql-gen * update version --------- Co-authored-by: Thanetpon Kultontikorn <[email protected]>
1 parent 277ee78 commit 332e91a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agoda-graphql-csharp-generator",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"main": "index.js",
55
"files": [
66
"dist"

src/generate.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ import { promises as fs } from 'fs';
44
import * as path from 'path';
55
import { exec } from 'child_process';
66

7+
// Helper to find the gql-gen binary
8+
const getGqlGenCommand = (): string => {
9+
try {
10+
// Find the graphql-code-generator package that provides gql-gen
11+
const gqlGenPath = require.resolve('graphql-code-generator/dist/cli.js');
12+
console.log("gqlGenPath:", gqlGenPath);
13+
14+
return `node "${gqlGenPath}"`;
15+
} catch (error) {
16+
// Fallback to npx with correct package name
17+
console.warn('Could not resolve gql-gen binary, falling back to npx');
18+
return 'npx graphql-code-generator';
19+
}
20+
};
21+
722
// Helper to get argument value from CLI
823
const getArgValue = (argName: string): string | undefined => {
924
const args = process.argv.slice(2);
@@ -44,10 +59,11 @@ async function removeInputTypesRegion(filePath: string): Promise<void> {
4459
// Generate GraphQL code and post-process
4560
const generateGraphql = async (schemaUrl: string, filePath: string): Promise<void> => {
4661
const folder = path.dirname(filePath);
62+
const gqlGenCommand = getGqlGenCommand();
4763

4864
await new Promise<void>((resolve, reject) => {
4965
exec(
50-
`gql-gen --schema '${schemaUrl}' --template agoda-graphql-codegen-csharp --out ${folder} ${filePath}`,
66+
`${gqlGenCommand} --schema '${schemaUrl}' --template agoda-graphql-codegen-csharp --out ${folder} ${filePath}`,
5167
(error, stdout, stderr) => {
5268
if (error) {
5369
console.error(`Error: ${error.message}`);

0 commit comments

Comments
 (0)