Skip to content
Open
Show file tree
Hide file tree
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
Expand Up @@ -6,7 +6,8 @@ export type GqlTypeReference<T = any> =
| GraphQLScalarType
| Function
| object
| symbol;
| symbol
| string;
export type ReturnTypeFuncValue = GqlTypeReference | [GqlTypeReference];
export type ReturnTypeFunc<T extends ReturnTypeFuncValue = any> = (
returns?: void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { UnionDefinition } from '../factories/union-definition.factory';
export type GqlInputTypeKey = Function | object;
export type GqlInputType = InputTypeDefinition | EnumDefinition;

export type GqlOutputTypeKey = Function | object | symbol;
export type GqlOutputTypeKey = Function | object | symbol | string;
export type GqlOutputType =
| InterfaceTypeDefinition
| ObjectTypeDefinition
Expand All @@ -38,13 +38,15 @@ export class TypeDefinitionsStorage {
Function,
InputTypeDefinition
>();
private readonly outputTypesByName = new Map<string, GqlOutputType>();
private inputTypeDefinitionsLinks?: Map<GqlInputTypeKey, GqlInputType>;
private outputTypeDefinitionsLinks?: Map<GqlOutputTypeKey, GqlOutputType>;

addEnums(enumDefs: EnumDefinition[]) {
enumDefs.forEach((item) =>
this.enumTypeDefinitions.set(item.enumRef, item),
);
enumDefs.forEach((item) => {
this.enumTypeDefinitions.set(item.enumRef, item);
this.outputTypesByName.set(item.type.name, item);
});
}

getEnumByObject(obj: object): EnumDefinition {
Expand All @@ -56,7 +58,10 @@ export class TypeDefinitionsStorage {
}

addUnions(unionDefs: UnionDefinition[]) {
unionDefs.forEach((item) => this.unionTypeDefinitions.set(item.id, item));
unionDefs.forEach((item) => {
this.unionTypeDefinitions.set(item.id, item);
this.outputTypesByName.set(item.type.name, item);
});
}

getUnionBySymbol(key: symbol): UnionDefinition {
Expand All @@ -68,9 +73,10 @@ export class TypeDefinitionsStorage {
}

addInterfaces(interfaceDefs: InterfaceTypeDefinition[]) {
interfaceDefs.forEach((item) =>
this.interfaceTypeDefinitions.set(item.target, item),
);
interfaceDefs.forEach((item) => {
this.interfaceTypeDefinitions.set(item.target, item);
this.outputTypesByName.set(item.type.name, item);
});
}

getInterfaceByTarget(type: Function): InterfaceTypeDefinition {
Expand All @@ -96,9 +102,10 @@ export class TypeDefinitionsStorage {
}

addObjectTypes(objectDefs: ObjectTypeDefinition[]) {
objectDefs.forEach((item) =>
this.objectTypeDefinitions.set(item.target, item),
);
objectDefs.forEach((item) => {
this.objectTypeDefinitions.set(item.target, item);
this.outputTypesByName.set(item.type.name, item);
});
}

getObjectTypeByTarget(type: Function): ObjectTypeDefinition {
Expand Down Expand Up @@ -142,6 +149,7 @@ export class TypeDefinitionsStorage {
...this.interfaceTypeDefinitions.entries(),
...this.enumTypeDefinitions.entries(),
...this.unionTypeDefinitions.entries(),
...this.outputTypesByName.entries(),
]);
}
const definition = this.outputTypeDefinitionsLinks.get(key);
Expand Down