UNPKG

graphql-mocks

Version:

Tools for setting up graphql test resolvers

30 lines (28 loc) 1.38 kB
'use strict'; var graphql = require('graphql'); var isScalarDefinition = require('../type-utils/is-scalar-definition.js'); function attachScalarsToSchema(schema, scalarMap) { for (const scalarTypeName in scalarMap) { const scalarType = schema.getType(scalarTypeName); if (!scalarType) { throw new Error(`Could not find any type named "${scalarTypeName}". Double-check the scalar map where "${scalarTypeName}" is referenced against scalars defined in the graphql schema.`); } if (!graphql.isScalarType(scalarType)) { throw new Error(`Could not find a scalar type of "${scalarTypeName}". Double-check the scalar map where "${scalarTypeName}" is referenced against scalars defined in the graphql schema.`); } const scalarDefinition = scalarMap[scalarTypeName]; if (!isScalarDefinition.isScalarDefinition(scalarDefinition)) { throw new Error(`Passed a scalar map with ${scalarTypeName} but it is not a proper scalar definition`); } // copy over keys from scalar defintion on to scalary instance for (const key in scalarDefinition) { if (key === 'name') { continue; } // eslint-disable-next-line @typescript-eslint/no-explicit-any scalarType[key] = scalarDefinition[key]; } } } exports.attachScalarsToSchema = attachScalarsToSchema; //# sourceMappingURL=attach-scalars-to-schema.js.map