graphql-paper
Version:
A flexible in-memory store based on a GraphQL Schema
36 lines (35 loc) • 1.16 kB
JavaScript
import { isObjectType } from 'graphql';
import { typeExists } from '../graphql/type-exists.mjs';
import { TypeDoesNotExist } from './errors/type-does-not-exist.mjs';
import { TypeIsNotDocumentCompatible } from './errors/type-is-not-document-compatible.mjs';
import { validateField } from './validate-field.mjs';
import { isNullDocument } from '../document/null-document.mjs';
function validate(graphqlSchema, document, store, validators) {
if (isNullDocument(document)) {
return;
}
var typeName = document.__typename;
var type = graphqlSchema.getType(typeName);
if (!type) {
throw new Error("Type ".concat(typeName, " does not exist in the graphql schema."));
}
if (!isObjectType(type)) {
throw new TypeIsNotDocumentCompatible({
type
});
}
if (!typeExists(graphqlSchema, typeName)) {
throw new TypeDoesNotExist({
typename: typeName
});
}
var combinedValidators = [...validators.document, validateField(validators.field)];
combinedValidators.forEach(validator => validator.validate({
store,
graphqlSchema,
document,
type
}));
}
export { validate };
//# sourceMappingURL=validate.mjs.map