Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion src/validation/__tests__/ValuesOfCorrectType-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@

import { describe, it } from 'mocha';

import { GraphQLSchema } from '../../type/schema';
import { GraphQLString } from '../../type/scalars';
import { GraphQLScalarType, GraphQLObjectType } from '../../type/definition';

import { ValuesOfCorrectType } from '../rules/ValuesOfCorrectType';

import { expectValidationErrors } from './harness';
import {
expectValidationErrors,
expectValidationErrorsWithSchema,
} from './harness';

function expectErrors(queryStr) {
return expectValidationErrors(ValuesOfCorrectType, queryStr);
}

function expectErrorsWithSchema(schema, queryStr) {
return expectValidationErrorsWithSchema(
schema,
ValuesOfCorrectType,
queryStr,
);
}

function expectValid(queryStr) {
expectErrors(queryStr).to.deep.equal([]);
}
Expand Down Expand Up @@ -942,6 +957,45 @@ describe('Validate: Values of correct type', () => {
);
});

it('reports error for custom scalar that returns undefined', () => {
const customScalar = new GraphQLScalarType({
name: 'CustomScalar',
parseValue() {
return undefined;
},
});

const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
invalidArg: {
type: GraphQLString,
args: {
arg: { type: customScalar },
},
},
},
}),
});

const expectedErrors = expectErrorsWithSchema(
schema,
`
{
invalidArg(arg: 123)
}
`,
);

expectedErrors.to.deep.equal([
{
message: 'Expected value of type "CustomScalar", found 123.',
locations: [{ line: 3, column: 27 }],
},
]);
});

it('allows custom scalar to accept complex literals', () => {
expectValid(`
{
Expand Down