@@ -10,12 +10,12 @@ express or implied. See the License for the specific language governing
10
10
permissions and limitations under the License.
11
11
*/
12
12
13
- import { astFromValue , buildASTSchema , typeFromAST , GraphQLID } from 'graphql' ;
13
+ import { astFromValue , buildASTSchema , typeFromAST , GraphQLID , GraphQLInputObjectType } from 'graphql' ;
14
14
import { gql } from 'graphql-tag' ; // GraphQL library to parse the GraphQL query
15
15
16
16
const useCallSubquery = false ;
17
17
18
- // 2025-02-19T23:41:22.685Z
18
+ // 2025-02-21T06:31:13.132Z
19
19
20
20
const schemaDataModelJSON = `{
21
21
"kind": "Document",
@@ -2469,6 +2469,98 @@ const schemaDataModelJSON = `{
2469
2469
}
2470
2470
},
2471
2471
"directives": []
2472
+ },
2473
+ {
2474
+ "kind": "FieldDefinition",
2475
+ "name": {
2476
+ "kind": "Name",
2477
+ "value": "getAirportWithGremlin"
2478
+ },
2479
+ "arguments": [
2480
+ {
2481
+ "kind": "InputValueDefinition",
2482
+ "name": {
2483
+ "kind": "Name",
2484
+ "value": "code"
2485
+ },
2486
+ "type": {
2487
+ "kind": "NamedType",
2488
+ "name": {
2489
+ "kind": "Name",
2490
+ "value": "String"
2491
+ }
2492
+ },
2493
+ "directives": []
2494
+ }
2495
+ ],
2496
+ "type": {
2497
+ "kind": "NamedType",
2498
+ "name": {
2499
+ "kind": "Name",
2500
+ "value": "Airport"
2501
+ }
2502
+ },
2503
+ "directives": [
2504
+ {
2505
+ "kind": "Directive",
2506
+ "name": {
2507
+ "kind": "Name",
2508
+ "value": "graphQuery"
2509
+ },
2510
+ "arguments": [
2511
+ {
2512
+ "kind": "Argument",
2513
+ "name": {
2514
+ "kind": "Name",
2515
+ "value": "statement"
2516
+ },
2517
+ "value": {
2518
+ "kind": "StringValue",
2519
+ "value": "g.V().has('airport', 'code', '$code').elementMap()",
2520
+ "block": false
2521
+ }
2522
+ }
2523
+ ]
2524
+ }
2525
+ ]
2526
+ },
2527
+ {
2528
+ "kind": "FieldDefinition",
2529
+ "name": {
2530
+ "kind": "Name",
2531
+ "value": "getCountriesCount"
2532
+ },
2533
+ "arguments": [],
2534
+ "type": {
2535
+ "kind": "NamedType",
2536
+ "name": {
2537
+ "kind": "Name",
2538
+ "value": "Int"
2539
+ }
2540
+ },
2541
+ "directives": [
2542
+ {
2543
+ "kind": "Directive",
2544
+ "name": {
2545
+ "kind": "Name",
2546
+ "value": "graphQuery"
2547
+ },
2548
+ "arguments": [
2549
+ {
2550
+ "kind": "Argument",
2551
+ "name": {
2552
+ "kind": "Name",
2553
+ "value": "statement"
2554
+ },
2555
+ "value": {
2556
+ "kind": "StringValue",
2557
+ "value": "g.V().hasLabel('country').count()",
2558
+ "block": false
2559
+ }
2560
+ }
2561
+ ]
2562
+ }
2563
+ ]
2472
2564
}
2473
2565
]
2474
2566
},
@@ -3466,7 +3558,7 @@ const schemaDataModelJSON = `{
3466
3558
],
3467
3559
"loc": {
3468
3560
"start": 0,
3469
- "end": 4698
3561
+ "end": 4902
3470
3562
}
3471
3563
}` ;
3472
3564
@@ -3487,7 +3579,7 @@ export function resolveGraphDBQueryFromAppSyncEvent(event) {
3487
3579
return resolveGraphDBQueryFromEvent ( {
3488
3580
field : event . field ,
3489
3581
arguments : event . arguments ,
3490
- selectionSet : gql `${ event . selectionSetGraphQL } ` . definitions [ 0 ] . selectionSet
3582
+ selectionSet : event . selectionSetGraphQL ? gql `${ event . selectionSetGraphQL } ` . definitions [ 0 ] . selectionSet : { }
3491
3583
} ) ;
3492
3584
}
3493
3585
@@ -3509,15 +3601,17 @@ export function resolveGraphDBQueryFromEvent(event) {
3509
3601
if ( value ) {
3510
3602
const inputType = typeFromAST ( schema , inputDef . type ) ;
3511
3603
const astValue = astFromValue ( value , inputType ) ;
3512
- // retrieve an ID field which may not necessarily be named 'id'
3513
- const idField = Object . values ( inputType . getFields ( ) ) . find ( field => field . type . name === GraphQLID . name ) ;
3514
- if ( idField ) {
3515
- // check if id was an input arg
3516
- const idValue = astValue . fields . find ( f => f . name . value === idField . name ) ;
3517
- if ( idValue ?. value ?. kind === 'IntValue' ) {
3518
- // graphql astFromValue function can convert ID integer strings into integer type
3519
- // if input args contain an id and the graphql library has interpreted the value as an int, change it to treat the value as a string
3520
- idValue . value . kind = 'StringValue' ;
3604
+ if ( inputType instanceof GraphQLInputObjectType ) {
3605
+ // retrieve an ID field which may not necessarily be named 'id'
3606
+ const idField = Object . values ( inputType . getFields ( ) ) . find ( field => field . type . name === GraphQLID . name ) ;
3607
+ if ( idField ) {
3608
+ // check if id was an input arg
3609
+ const idValue = astValue . fields . find ( f => f . name . value === idField . name ) ;
3610
+ if ( idValue ?. value ?. kind === 'IntValue' ) {
3611
+ // graphql astFromValue function can convert ID integer strings into integer type
3612
+ // if input args contain an id and the graphql library has interpreted the value as an int, change it to treat the value as a string
3613
+ idValue . value . kind = 'StringValue' ;
3614
+ }
3521
3615
}
3522
3616
}
3523
3617
args . push ( {
0 commit comments