1- import { Kind , type GraphQLArgument , type GraphQLInputField , type ValueNode } from 'graphql' ;
1+ import {
2+ valueFromASTUntyped ,
3+ type GraphQLArgument ,
4+ type GraphQLInputField ,
5+ type ValueNode ,
6+ } from 'graphql' ;
27import { astFromValue } from './astFromValue.js' ;
38import { astFromValueUntyped } from './astFromValueUntyped.js' ;
49
@@ -23,7 +28,7 @@ export const defaultValueAstFromType = (
2328 return ( astFromValueUntyped ( ( arg . default as any ) . value ) as any ) ?? undefined ;
2429 }
2530
26- const value = convertConstValueNode ( ( arg . default as any ) . literal ) ;
31+ const value = valueFromASTUntyped ( ( arg . default as any ) . literal ) ;
2732 return ( astFromValue ( value , arg . type ) as any ) ?? undefined ;
2833 }
2934
@@ -32,26 +37,3 @@ export const defaultValueAstFromType = (
3237 ? ( ( astFromValue ( ( arg as any ) . defaultValue , ( arg as any ) . type ) as any ) ?? undefined )
3338 : undefined ;
3439} ;
35-
36- /**
37- * `convertConstValueNode` exhaustively traverses an literal node (a node with constant value)
38- * and constructs a JavaScript representation of the node values
39- *
40- * Note: `node` is supposed to be `ConstValueNode` for graphql@17 but
41- * it is not available in graphql@15 so we cannot import it from `graphql`
42- */
43- const convertConstValueNode = ( node : any ) => {
44- if ( node . kind === Kind . NULL ) {
45- return null ;
46- } else if ( node . kind === Kind . LIST ) {
47- return node . values . map ( convertConstValueNode ) ;
48- } else if ( node . kind === Kind . OBJECT ) {
49- const result = { } ;
50- for ( const field of node . fields ) {
51- result [ field . name . value ] = convertConstValueNode ( field . value ) ;
52- }
53- return result ;
54- }
55-
56- return node . value ;
57- } ;
0 commit comments