@@ -4,6 +4,21 @@ import { promises as fs } from 'fs';
4
4
import * as path from 'path' ;
5
5
import { exec } from 'child_process' ;
6
6
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
+
7
22
// Helper to get argument value from CLI
8
23
const getArgValue = ( argName : string ) : string | undefined = > {
9
24
const args = process . argv . slice ( 2 ) ;
@@ -44,10 +59,11 @@ async function removeInputTypesRegion(filePath: string): Promise<void> {
44
59
// Generate GraphQL code and post-process
45
60
const generateGraphql = async ( schemaUrl : string , filePath : string ) : Promise < void > => {
46
61
const folder = path . dirname ( filePath ) ;
62
+ const gqlGenCommand = getGqlGenCommand ( ) ;
47
63
48
64
await new Promise < void > ( ( resolve , reject ) => {
49
65
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 } ` ,
51
67
( error , stdout , stderr ) => {
52
68
if ( error ) {
53
69
console . error ( `Error: ${ error . message } ` ) ;
0 commit comments