UNPKG

graphql-paper

Version:

A flexible in-memory store based on a GraphQL Schema

28 lines (27 loc) 1.04 kB
import { isNonNullType } from 'graphql'; import { key } from '../../document/null-document.mjs'; import { FieldReturnTypeMismatch } from '../errors/field-return-type-mismatch.mjs'; var nonNullFieldValidator = { skipConnectionValue: false, skipNullValue: false, validate(_ref) { var { field, fieldValue, fieldConnections: connections } = _ref; if (isNonNullType(field.type)) { var hasConnectedNullDocument = (connections === null || connections === void 0 ? void 0 : connections.length) === 1 && (connections === null || connections === void 0 ? void 0 : connections.includes(key)); var actual = hasConnectedNullDocument ? 'null document' : fieldValue === undefined ? 'undefined' : 'null'; if (fieldValue == null && (hasConnectedNullDocument || !connections)) { throw new FieldReturnTypeMismatch({ field: field, expected: 'non-null', actual }); } } } }; export { nonNullFieldValidator }; //# sourceMappingURL=non-null-field.mjs.map