@@ -60,6 +60,8 @@ describe('Type System: Scalars', () => {
60
60
serialize : someScalar . serialize ,
61
61
parseValue : someScalar . parseValue ,
62
62
parseLiteral : someScalar . parseLiteral ,
63
+ coerceOutputValue : someScalar . coerceOutputValue ,
64
+ coerceInputValue : someScalar . coerceInputValue ,
63
65
coerceInputLiteral : undefined ,
64
66
valueToLiteral : undefined ,
65
67
extensions : { } ,
@@ -76,6 +78,8 @@ describe('Type System: Scalars', () => {
76
78
serialize : passThroughFunc ,
77
79
parseValue : passThroughFunc ,
78
80
parseLiteral : passThroughFunc ,
81
+ coerceOutputValue : passThroughFunc ,
82
+ coerceInputValue : passThroughFunc ,
79
83
coerceInputLiteral : passThroughFunc ,
80
84
valueToLiteral : passThroughFunc ,
81
85
extensions : { someExtension : 'extension' } ,
@@ -91,6 +95,8 @@ describe('Type System: Scalars', () => {
91
95
92
96
expect ( scalar . serialize ) . to . equal ( identityFunc ) ;
93
97
expect ( scalar . parseValue ) . to . equal ( identityFunc ) ;
98
+ expect ( scalar . coerceOutputValue ) . to . equal ( identityFunc ) ;
99
+ expect ( scalar . coerceInputValue ) . to . equal ( identityFunc ) ;
94
100
expect ( scalar . parseLiteral ) . to . be . a ( 'function' ) ;
95
101
/* default will be provided in v18 when parseLiteral is removed */
96
102
// expect(scalar.coerceInputLiteral).to.be.a('function');
@@ -124,15 +130,15 @@ describe('Type System: Scalars', () => {
124
130
) ;
125
131
} ) ;
126
132
127
- it ( 'rejects a Scalar type defining coerceInputLiteral but not parseValue ' , ( ) => {
133
+ it ( 'rejects a Scalar type defining coerceInputLiteral but not coerceInputValue ' , ( ) => {
128
134
expect (
129
135
( ) =>
130
136
new GraphQLScalarType ( {
131
137
name : 'SomeScalar' ,
132
138
coerceInputLiteral : passThroughFunc ,
133
139
} ) ,
134
140
) . to . throw (
135
- 'SomeScalar must provide both "parseValue " and "coerceInputLiteral" functions.' ,
141
+ 'SomeScalar must provide both "coerceInputValue " and "coerceInputLiteral" functions.' ,
136
142
) ;
137
143
} ) ;
138
144
} ) ;
@@ -625,6 +631,30 @@ describe('Type System: Enums', () => {
625
631
expect ( someEnum . toConfig ( ) ) . to . deep . equal ( someEnumConfig ) ;
626
632
} ) ;
627
633
634
+ it ( 'can be coerced to an output value via serialize() method' , ( ) => {
635
+ const someEnum = new GraphQLEnumType ( {
636
+ name : 'SomeEnum' ,
637
+ values : {
638
+ FOO : {
639
+ value : 'foo' ,
640
+ } ,
641
+ } ,
642
+ } ) ;
643
+ expect ( someEnum . serialize ( 'foo' ) ) . to . equal ( 'FOO' ) ;
644
+ } ) ;
645
+
646
+ it ( 'can be coerced to an input value via parseValue() method' , ( ) => {
647
+ const someEnum = new GraphQLEnumType ( {
648
+ name : 'SomeEnum' ,
649
+ values : {
650
+ FOO : {
651
+ value : 'foo' ,
652
+ } ,
653
+ } ,
654
+ } ) ;
655
+ expect ( someEnum . parseValue ( 'FOO' ) ) . to . equal ( 'foo' ) ;
656
+ } ) ;
657
+
628
658
it ( 'defines an enum type with deprecated value' , ( ) => {
629
659
const EnumTypeWithDeprecatedValue = new GraphQLEnumType ( {
630
660
name : 'EnumWithDeprecatedValue' ,
0 commit comments