@@ -66,14 +66,15 @@ class GraphQLEndpoint implements ProtocolEndpoint {
6666 private async executeCreate ( operation : ProtocolOperation ) : Promise < ProtocolResponse > {
6767 const entityName = this . capitalize ( operation . entity ) ;
6868 const mutation = `
69- mutation Create${ entityName } ($data: JSON !) {
70- create${ entityName } (data : $data )
69+ mutation Create${ entityName } ($input: ${ entityName } Input !) {
70+ create${ entityName } (input : $input )
7171 }
7272 ` ;
7373
74- const result = await this . graphqlRequest ( mutation , { data : operation . data } ) ;
74+ const result = await this . graphqlRequest ( mutation , { input : operation . data } ) ;
7575
7676 if ( result . errors ) {
77+ console . log ( 'GraphQL create error:' , JSON . stringify ( result . errors , null , 2 ) ) ;
7778 return {
7879 success : false ,
7980 error : {
@@ -91,9 +92,10 @@ class GraphQLEndpoint implements ProtocolEndpoint {
9192
9293 private async executeRead ( operation : ProtocolOperation ) : Promise < ProtocolResponse > {
9394 const entityName = this . capitalize ( operation . entity ) ;
95+ const camelName = this . toCamelCase ( operation . entity ) ;
9496 const query = `
95- query Get${ entityName } ($id: String !) {
96- ${ operation . entity } (id: $id)
97+ query Get${ entityName } ($id: ID !) {
98+ ${ camelName } (id: $id)
9799 }
98100 ` ;
99101
@@ -111,21 +113,21 @@ class GraphQLEndpoint implements ProtocolEndpoint {
111113
112114 return {
113115 success : true ,
114- data : result . data [ operation . entity ]
116+ data : result . data [ camelName ]
115117 } ;
116118 }
117119
118120 private async executeUpdate ( operation : ProtocolOperation ) : Promise < ProtocolResponse > {
119121 const entityName = this . capitalize ( operation . entity ) ;
120122 const mutation = `
121- mutation Update${ entityName } ($id: String !, $data: JSON !) {
122- update${ entityName } (id: $id, data : $data )
123+ mutation Update${ entityName } ($id: ID !, $input: ${ entityName } UpdateInput !) {
124+ update${ entityName } (id: $id, input : $input )
123125 }
124126 ` ;
125127
126128 const result = await this . graphqlRequest ( mutation , {
127129 id : operation . id ,
128- data : operation . data
130+ input : operation . data
129131 } ) ;
130132
131133 if ( result . errors ) {
@@ -147,7 +149,7 @@ class GraphQLEndpoint implements ProtocolEndpoint {
147149 private async executeDelete ( operation : ProtocolOperation ) : Promise < ProtocolResponse > {
148150 const entityName = this . capitalize ( operation . entity ) ;
149151 const mutation = `
150- mutation Delete${ entityName } ($id: String !) {
152+ mutation Delete${ entityName } ($id: ID !) {
151153 delete${ entityName } (id: $id)
152154 }
153155 ` ;
@@ -172,13 +174,14 @@ class GraphQLEndpoint implements ProtocolEndpoint {
172174
173175 private async executeQuery ( operation : ProtocolOperation ) : Promise < ProtocolResponse > {
174176 const entityName = this . capitalize ( operation . entity ) ;
177+ const camelName = this . toCamelCase ( operation . entity ) ;
175178
176179 let queryArgs = '' ;
177180 const variables : any = { } ;
178181
179182 if ( operation . filter ) {
180- queryArgs += '$filter: JSON' ;
181- variables . filter = operation . filter ;
183+ queryArgs += `$where: ${ entityName } Filter` ;
184+ variables . where = operation . filter ;
182185 }
183186
184187 if ( operation . options ?. limit ) {
@@ -195,7 +198,7 @@ class GraphQLEndpoint implements ProtocolEndpoint {
195198
196199 const query = `
197200 query List${ entityName } ${ queryArgs ? `(${ queryArgs } )` : '' } {
198- ${ operation . entity } List${ this . buildQueryArgs ( variables ) }
201+ ${ camelName } List${ this . buildQueryArgs ( variables ) }
199202 }
200203 ` ;
201204
@@ -213,7 +216,7 @@ class GraphQLEndpoint implements ProtocolEndpoint {
213216
214217 return {
215218 success : true ,
216- data : result . data [ `${ operation . entity } List` ] || [ ]
219+ data : result . data [ `${ camelName } List` ] || [ ]
217220 } ;
218221 }
219222
@@ -232,16 +235,16 @@ class GraphQLEndpoint implements ProtocolEndpoint {
232235 }
233236
234237 const mutations = operation . data . map ( ( item , index ) => `
235- item${ index } : create${ entityName } (data : $data ${ index } )
238+ item${ index } : create${ entityName } (input : $input ${ index } )
236239 ` ) . join ( '\n' ) ;
237240
238241 const variables : any = { } ;
239242 const variableDefinitions = operation . data . map ( ( _ , index ) =>
240- `$data ${ index } : JSON !`
243+ `$input ${ index } : ${ entityName } Input !`
241244 ) . join ( ', ' ) ;
242245
243246 operation . data . forEach ( ( item , index ) => {
244- variables [ `data ${ index } ` ] = item ;
247+ variables [ `input ${ index } ` ] = item ;
245248 } ) ;
246249
247250 const mutation = `
@@ -317,7 +320,16 @@ class GraphQLEndpoint implements ProtocolEndpoint {
317320 }
318321
319322 private capitalize ( str : string ) : string {
320- return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
323+ // Convert to PascalCase (handle underscores and hyphens)
324+ return str
325+ . split ( / [ _ - ] / )
326+ . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( ) )
327+ . join ( '' ) ;
328+ }
329+
330+ private toCamelCase ( str : string ) : string {
331+ const pascal = this . capitalize ( str ) ;
332+ return pascal . charAt ( 0 ) . toLowerCase ( ) + pascal . slice ( 1 ) ;
321333 }
322334
323335 private buildQueryArgs ( variables : any ) : string {
0 commit comments