graphql-mocks
Version:
Tools for setting up graphql test resolvers
28 lines (27 loc) • 1.38 kB
JavaScript
import { isScalarType } from 'graphql';
import { isScalarDefinition } from '../type-utils/is-scalar-definition.mjs';
function attachScalarsToSchema(schema, scalarMap) {
for (var scalarTypeName in scalarMap) {
var scalarType = schema.getType(scalarTypeName);
if (!scalarType) {
throw new Error("Could not find any type named \"".concat(scalarTypeName, "\". Double-check the scalar map where \"").concat(scalarTypeName, "\" is referenced against scalars defined in the graphql schema."));
}
if (!isScalarType(scalarType)) {
throw new Error("Could not find a scalar type of \"".concat(scalarTypeName, "\". Double-check the scalar map where \"").concat(scalarTypeName, "\" is referenced against scalars defined in the graphql schema."));
}
var scalarDefinition = scalarMap[scalarTypeName];
if (!isScalarDefinition(scalarDefinition)) {
throw new Error("Passed a scalar map with ".concat(scalarTypeName, " but it is not a proper scalar definition"));
}
// copy over keys from scalar defintion on to scalary instance
for (var key in scalarDefinition) {
if (key === 'name') {
continue;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
scalarType[key] = scalarDefinition[key];
}
}
}
export { attachScalarsToSchema };
//# sourceMappingURL=attach-scalars-to-schema.mjs.map