Skip to content

Commit

Permalink
Merge branch 'roypeled-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Feb 6, 2023
2 parents 42c39be + c2b3b9a commit d6ac4b0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 23 deletions.
12 changes: 4 additions & 8 deletions packages/graphql/lib/decorators/resolver.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ function getObjectOrInterfaceTypeNameIfExists(
nameOrType: Function,
): string | undefined {
const ctor = getClassOrUndefined(nameOrType);
const objectTypesMetadata = TypeMetadataStorage.getObjectTypesMetadata();
const objectMetadata = objectTypesMetadata.find(
(type) => type.target === ctor,
);
const objectMetadata =
TypeMetadataStorage.getObjectTypeMetadataByTarget(ctor);
if (!objectMetadata) {
const interfaceTypesMetadata = TypeMetadataStorage.getInterfacesMetadata();
const interfaceMetadata = interfaceTypesMetadata.find(
(type) => type.target === ctor,
);
const interfaceMetadata =
TypeMetadataStorage.getInterfaceMetadataByTarget(ctor);
if (!interfaceMetadata) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ObjectTypeMetadata } from '../metadata/object-type.metadata';

export interface MetadataCollectionModel {
argumentType: ClassMetadata[];
interface: ClassMetadata[];
interface: Map<Function, ClassMetadata>;
inputType: ClassMetadata[];
objectType: ObjectTypeMetadata[];
resolver: ResolverClassMetadata[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { MetadataCollectionModel } from './metada-collection-model.interface';
import { TargetMetadataCollection } from './target-metadata.collection';
import { ClassMetadata } from '../metadata';

export class MetadataByTargetCollection {
public readonly all: MetadataCollectionModel = {
argumentType: [],
interface: [],
interface: new Map<Function, ClassMetadata>(),
inputType: [],
objectType: [],
resolver: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class TargetMetadataCollection {

set interface(val: ClassMetadata) {
this._interface = val;
this.all.interface.push(val);
this.all.interface.set(val.target, val);
}

get interface() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class GraphQLSchemaFactory {
options = scalarsOrOptions;
}

TypeMetadataStorage.clear();
LazyMetadataStorage.load(resolvers);
TypeMetadataStorage.compile(options.orphanedTypes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ export class LazyMetadataStorageHost {
.filter((metadata) => metadata),
);

loadersToExecute = loadersToExecute.concat(
...(this.lazyMetadataByTarget.get(NO_TARGET_METADATA) || []),
);
loadersToExecute = [
loadersToExecute,
this.lazyMetadataByTarget.get(NO_TARGET_METADATA) || [],
].flat();

if (!options.skipFieldLazyMetadata) {
loadersToExecute = loadersToExecute.concat(
...(this.lazyMetadataByTarget.get(FIELD_LAZY_METADATA) || []),
);
loadersToExecute = [
loadersToExecute,
this.lazyMetadataByTarget.get(FIELD_LAZY_METADATA) || [],
].flat();
}
loadersToExecute.forEach((func) => func());
}
Expand Down Expand Up @@ -83,10 +85,16 @@ export class LazyMetadataStorageHost {

private updateStorage(key: symbol | Type<unknown>, func: Function) {
const existingArray = this.lazyMetadataByTarget.get(key);
let called = false;
const singleCallFunctionWrapper = () => {
if (called) return;
func();
called = true;
};
if (existingArray) {
existingArray.push(func);
existingArray.push(singleCallFunctionWrapper);
} else {
this.lazyMetadataByTarget.set(key, [func]);
this.lazyMetadataByTarget.set(key, [singleCallFunctionWrapper]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class TypeMetadataStorageHost {
}

getInterfacesMetadata(): InterfaceMetadata[] {
return this.metadataByTargetCollection.all.interface;
return [...this.metadataByTargetCollection.all.interface.values()];
}

getInterfaceMetadataByTarget(
Expand Down Expand Up @@ -195,7 +195,7 @@ export class TypeMetadataStorageHost {
...this.metadataByTargetCollection.all.objectType,
...this.metadataByTargetCollection.all.inputType,
...this.metadataByTargetCollection.all.argumentType,
...this.metadataByTargetCollection.all.interface,
...this.metadataByTargetCollection.all.interface.values(),
];
this.loadClassPluginMetadata(classMetadata);
this.compileClassMetadata(classMetadata);
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/lib/utils/transform-schema.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export function transformSchema(

return new GraphQLInterfaceType({
...config,
interfaces: () => config.interfaces.map(replaceNamedType),
fields: () => replaceFields(config.fields),
});
} else if (isUnionType(type)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/mercurius/tests/e2e/code-first-federation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type Query @extends {
"""Search result description"""
union FederationSearchResultUnion = Post | User
type User @extends @key(fields: "id") {
type User @key(fields: "id") @extends {
id: ID! @external
posts: [Post!]!
}
Expand Down

0 comments on commit d6ac4b0

Please sign in to comment.