@@ -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' } ,
@@ -95,6 +99,8 @@ describe('Type System: Scalars', () => {
95
99
serialize : passThroughFunc ,
96
100
parseValue : passThroughFunc ,
97
101
parseLiteral : passThroughFunc ,
102
+ coerceOutputValue : passThroughFunc ,
103
+ coerceInputValue : passThroughFunc ,
98
104
coerceInputLiteral : passThroughFunc ,
99
105
valueToLiteral : passThroughFunc ,
100
106
extensions : { [ test ] : 'extension' } ,
@@ -110,6 +116,8 @@ describe('Type System: Scalars', () => {
110
116
111
117
expect ( scalar . serialize ) . to . equal ( identityFunc ) ;
112
118
expect ( scalar . parseValue ) . to . equal ( identityFunc ) ;
119
+ expect ( scalar . coerceOutputValue ) . to . equal ( identityFunc ) ;
120
+ expect ( scalar . coerceInputValue ) . to . equal ( identityFunc ) ;
113
121
expect ( scalar . parseLiteral ) . to . be . a ( 'function' ) ;
114
122
/* default will be provided in v18 when parseLiteral is removed */
115
123
// expect(scalar.coerceInputLiteral).to.be.a('function');
@@ -143,15 +151,15 @@ describe('Type System: Scalars', () => {
143
151
) ;
144
152
} ) ;
145
153
146
- it ( 'rejects a Scalar type defining coerceInputLiteral but not parseValue ' , ( ) => {
154
+ it ( 'rejects a Scalar type defining coerceInputLiteral but not coerceInputValue ' , ( ) => {
147
155
expect (
148
156
( ) =>
149
157
new GraphQLScalarType ( {
150
158
name : 'SomeScalar' ,
151
159
coerceInputLiteral : passThroughFunc ,
152
160
} ) ,
153
161
) . to . throw (
154
- 'SomeScalar must provide both "parseValue " and "coerceInputLiteral" functions.' ,
162
+ 'SomeScalar must provide both "coerceInputValue " and "coerceInputLiteral" functions.' ,
155
163
) ;
156
164
} ) ;
157
165
} ) ;
@@ -644,6 +652,30 @@ describe('Type System: Enums', () => {
644
652
expect ( someEnum . toConfig ( ) ) . to . deep . equal ( someEnumConfig ) ;
645
653
} ) ;
646
654
655
+ it ( 'can be coerced to an output value via serialize() method' , ( ) => {
656
+ const someEnum = new GraphQLEnumType ( {
657
+ name : 'SomeEnum' ,
658
+ values : {
659
+ FOO : {
660
+ value : 'foo' ,
661
+ } ,
662
+ } ,
663
+ } ) ;
664
+ expect ( someEnum . serialize ( 'foo' ) ) . to . equal ( 'FOO' ) ;
665
+ } ) ;
666
+
667
+ it ( 'can be coerced to an input value via parseValue() method' , ( ) => {
668
+ const someEnum = new GraphQLEnumType ( {
669
+ name : 'SomeEnum' ,
670
+ values : {
671
+ FOO : {
672
+ value : 'foo' ,
673
+ } ,
674
+ } ,
675
+ } ) ;
676
+ expect ( someEnum . parseValue ( 'FOO' ) ) . to . equal ( 'foo' ) ;
677
+ } ) ;
678
+
647
679
it ( 'defines an enum type with deprecated value' , ( ) => {
648
680
const EnumTypeWithDeprecatedValue = new GraphQLEnumType ( {
649
681
name : 'EnumWithDeprecatedValue' ,
0 commit comments