File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed
Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @graphql-tools/utils " : patch
3+ ---
4+
5+ Respect JS ` Date ` in ` astFromValueUntyped `
Original file line number Diff line number Diff line change @@ -41,8 +41,8 @@ export function astFromValueUntyped(value: any): ValueNode | null {
4141 }
4242
4343 if ( typeof value === 'object' ) {
44- if ( value instanceof Date ) {
45- return { kind : Kind . STRING , value : value . toISOString ( ) } ;
44+ if ( value ?. toJSON ) {
45+ return astFromValueUntyped ( value . toJSON ( ) ) ;
4646 }
4747 const fieldNodes : Array < ObjectFieldNode > = [ ] ;
4848 for ( const fieldName in value ) {
Original file line number Diff line number Diff line change 1+ import { Kind , valueFromASTUntyped } from 'graphql' ;
2+ import { astFromValueUntyped } from '../src/astFromValueUntyped.js' ;
3+
4+ describe ( 'astFromValueUntyped' , ( ) => {
5+ it ( 'supports Date' , ( ) => {
6+ const date = new Date ( ) ;
7+ const ast = astFromValueUntyped ( date ) ;
8+ expect ( ast ) . toEqual ( {
9+ kind : Kind . STRING ,
10+ value : date . toISOString ( ) ,
11+ } ) ;
12+ } ) ;
13+ it ( 'supports Buffer' , ( ) => {
14+ const buffer = Buffer . from ( 'test' ) ;
15+ const ast = astFromValueUntyped ( buffer ) ;
16+ const generatedValue = valueFromASTUntyped ( ast ! ) ;
17+ expect ( generatedValue ) . toMatchObject ( buffer . toJSON ( ) ) ;
18+ } ) ;
19+ } ) ;
You can’t perform that action at this time.
0 commit comments