Skip to content

Commit 4623c3d

Browse files
valueFromAST-test: improve coverage (#2349)
1 parent 53afba1 commit 4623c3d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/utilities/__tests__/valueFromAST-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import { expect } from 'chai';
44
import { describe, it } from 'mocha';
55

6+
import invariant from '../../jsutils/invariant';
7+
import identityFunc from '../../jsutils/identityFunc';
8+
69
import { parseValue } from '../../language/parser';
710
import {
811
GraphQLInt,
@@ -12,6 +15,7 @@ import {
1215
GraphQLID,
1316
} from '../../type/scalars';
1417
import {
18+
GraphQLScalarType,
1519
GraphQLEnumType,
1620
GraphQLInputObjectType,
1721
GraphQLList,
@@ -53,6 +57,39 @@ describe('valueFromAST', () => {
5357
expectValueFrom('123.456', GraphQLString).to.equal(undefined);
5458
});
5559

60+
it('convert using parseLiteral from a custom scalar type', () => {
61+
const passthroughScalar = new GraphQLScalarType({
62+
name: 'PassthroughScalar',
63+
parseLiteral(node) {
64+
invariant(node.kind === 'StringValue');
65+
return node.value;
66+
},
67+
parseValue: identityFunc,
68+
});
69+
70+
expectValueFrom('"value"', passthroughScalar).to.equal('value');
71+
72+
const throwScalar = new GraphQLScalarType({
73+
name: 'ThrowScalar',
74+
parseLiteral() {
75+
throw new Error('Test');
76+
},
77+
parseValue: identityFunc,
78+
});
79+
80+
expectValueFrom('value', throwScalar).to.equal(undefined);
81+
82+
const returnUndefinedScalar = new GraphQLScalarType({
83+
name: 'ReturnUndefinedScalar',
84+
parseLiteral() {
85+
return undefined;
86+
},
87+
parseValue: identityFunc,
88+
});
89+
90+
expectValueFrom('value', returnUndefinedScalar).to.equal(undefined);
91+
});
92+
5693
it('converts enum values according to input coercion rules', () => {
5794
const testEnum = new GraphQLEnumType({
5895
name: 'TestColor',

0 commit comments

Comments
 (0)