@apollo/federation
Version:
Apollo Federation Utilities
36 lines • 2.24 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.externalTypeMismatch = void 0;
const graphql_1 = require("graphql");
const utils_1 = require("../../utils");
const externalTypeMismatch = ({ schema }) => {
const errors = [];
const types = schema.getTypeMap();
for (const [typeName, namedType] of Object.entries(types)) {
if (!(0, graphql_1.isObjectType)(namedType))
continue;
const typeFederationMetadata = (0, utils_1.getFederationMetadata)(namedType);
if (typeFederationMetadata === null || typeFederationMetadata === void 0 ? void 0 : typeFederationMetadata.externals) {
for (const [serviceName, externalFieldsForService] of Object.entries(typeFederationMetadata.externals)) {
for (const { field: externalField } of externalFieldsForService) {
const externalFieldName = externalField.name.value;
const allFields = namedType.getFields();
const matchingBaseField = allFields[externalFieldName];
const externalFieldType = (0, graphql_1.typeFromAST)(schema, externalField.type);
if (!externalFieldType) {
errors.push((0, utils_1.errorWithCode)('EXTERNAL_TYPE_MISMATCH', (0, utils_1.logServiceAndType)(serviceName, typeName, externalFieldName) +
`the type of the @external field does not exist in the resulting composed schema`, externalField.type));
}
else if (matchingBaseField &&
!(0, graphql_1.isEqualType)(matchingBaseField.type, externalFieldType)) {
errors.push((0, utils_1.errorWithCode)('EXTERNAL_TYPE_MISMATCH', (0, utils_1.logServiceAndType)(serviceName, typeName, externalFieldName) +
`Type \`${externalFieldType}\` does not match the type of the original field in ${typeFederationMetadata.serviceName} (\`${matchingBaseField.type}\`)`, externalField.type));
}
}
}
}
}
return errors;
};
exports.externalTypeMismatch = externalTypeMismatch;
//# sourceMappingURL=externalTypeMismatch.js.map
;