Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Field Middlewares do not work on interfaces of interfaces #2666

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Type } from '@nestjs/common';
import { isUndefined } from '@nestjs/common/utils/shared.utils';
import {
GraphQLFieldConfigMap,
Expand Down Expand Up @@ -94,6 +94,23 @@ export class ObjectTypeDefinitionFactory {
};
}

private getRecursiveInterfaces(
metadatas: ObjectTypeMetadata[],
): ObjectTypeMetadata[] {
if (!metadatas || !metadatas.length) return [];

const interfaces = metadatas.reduce<ObjectTypeMetadata[]>((prev, curr) => {
return [
...prev,
...getInterfacesArray(curr.interfaces).map((it) =>
TypeMetadataStorage.getInterfaceMetadataByTarget(it as Type<unknown>),
),
];
}, []);

return [...interfaces, ...this.getRecursiveInterfaces(interfaces)];
}

private generateFields(
metadata: ObjectTypeMetadata,
options: BuildSchemaOptions,
Expand All @@ -109,12 +126,9 @@ export class ObjectTypeDefinitionFactory {

let properties = [];
if (metadata.interfaces) {
const implementedInterfaces =
TypeMetadataStorage.getInterfacesMetadata()
.filter((it) =>
getInterfacesArray(metadata.interfaces).includes(it.target),
)
.map((it) => it.properties);
const implementedInterfaces = this.getRecursiveInterfaces([
metadata,
]).map((it) => it.properties);

implementedInterfaces.forEach((fields) =>
properties.push(...(fields || [])),
Expand Down