Replies: 1 comment
-
Apparently nest-query does not implement the option for this functionality, or I simply did not find it or know how to use it, however I managed to make a patch in reference.resolver.js which until a new problem appears, met the need: "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReferenceResolver = exports.Referenceable = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@nestjs/common");
const graphql_1 = require("@nestjs/graphql");
const common_2 = require("../common");
const resolver_interface_1 = require("./resolver.interface");
/**
* @internal
* Mixin to expose `resolveReference` for a DTO on the resolver.
*/
const Referenceable = (DTOClass, opts) => (BaseClass) => {
if (!("key" in opts) || opts.key === undefined) {
return BaseClass;
}
const { key } = opts;
// Divide a string única em múltiplas chaves
const keys = key.split(" ").map((k) => k.trim());
let ResolveReferenceResolverBase = class ResolveReferenceResolverBase extends BaseClass {
async resolveReference(representation) {
// Verifica se todas as chaves estão presentes
const missingKeys = keys.filter((k) => representation[k] === undefined);
if (missingKeys.length > 0) {
throw new common_1.BadRequestException(
`Unable to resolve reference, missing required keys: ${missingKeys.join(", ")} for ${(0, common_2.getDTONames)(DTOClass).baseName}`
);
}
// Cria o filtro para múltiplas chaves
const filter = keys.reduce((acc, k) => {
acc[k] = { eq: representation[k] };
return acc;
}, {});
return this.service.query({ filter }).then((results) => results[0] || null);
}
};
tslib_1.__decorate(
[
(0, graphql_1.ResolveReference)(),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object]),
tslib_1.__metadata("design:returntype", Promise)
],
ResolveReferenceResolverBase.prototype,
"resolveReference",
null
);
ResolveReferenceResolverBase = tslib_1.__decorate(
[(0, graphql_1.Resolver)(() => DTOClass, { isAbstract: true })],
ResolveReferenceResolverBase
);
return ResolveReferenceResolverBase;
};
exports.Referenceable = Referenceable;
const ReferenceResolver = (DTOClass, opts = {}) => (0, exports.Referenceable)(DTOClass, opts)(resolver_interface_1.BaseServiceResolver);
exports.ReferenceResolver = ReferenceResolver;
//# sourceMappingURL=reference.resolver.js.map |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have doubts and problems in the use and consumption of federated data when the external resource has a composite key, even defining the decorator @directive('@key(fields: "x1 x2")'), I am receiving an error in the gateway, follow my code for visualization:
I already have other data configured with a key formed by a single field and there is no problem.
nest-query 7.1.0
apollo/gateway 2.9.3
apollo/server 4.11.0
WS 1:
WS 2
Query/Error:
Beta Was this translation helpful? Give feedback.
All reactions