UNPKG

graphql-paper

Version:

A flexible in-memory store based on a GraphQL Schema

22 lines (20 loc) 763 B
'use strict'; var fieldDoesNotExistOnType = require('../errors/field-does-not-exist-on-type.js'); const documentPropertyExistsAsFieldOnTypeValidator = { validate({ document, type }) { const documentFieldNames = Object.keys(document); const typeFieldNames = Object.keys(type.getFields()); const nonExistingFieldName = documentFieldNames.find(fieldName => !typeFieldNames.includes(fieldName)); if (nonExistingFieldName) { throw new fieldDoesNotExistOnType.FieldDoesNotExistOnType({ type, fieldName: nonExistingFieldName }); } } }; exports.documentPropertyExistsAsFieldOnTypeValidator = documentPropertyExistsAsFieldOnTypeValidator; //# sourceMappingURL=document-property-exists-as-field-on-type.js.map