Skip to content

Commit

Permalink
Remove split between GQL schema & class types in `ResourcesHost.getIn…
Browse files Browse the repository at this point in the history
…terfaces`

The GQL schema is always available now that my PR got merged.
The class types (aka `EnhancedResource.interfaces`) now works for IntersectTypes

Still, having the split between our class type inheritance and GQL schema gives me pause for thought.
They should be in sync, so maybe one should just be picked always over the other?
I guess class types could still be private, not exposed to GQL schema.
And GQL schema needs the app to be booted & use service, instead of just accessing on EnhancedResource...
  • Loading branch information
CarsonF committed Sep 19, 2024
1 parent 444ac63 commit 99cdb39
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions src/core/resources/resources.host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,34 +131,8 @@ export class ResourcesHost {
: EnhancedResource.of(ref);
}

getInterfaces(
resource: EnhancedResource<any>,
): ReadonlyArray<EnhancedResource<any>> {
// Use interfaces from GQL schema if it's available.
// Otherwise, fallback to the interfaces from DTO class hierarchy.
// The former doesn't work with CLI.
// The latter doesn't work for IntersectionTypes.
// Hoping to resolve with https://github.com/nestjs/graphql/pull/2435
try {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.gqlSchema.schema;
} catch (e) {
return this.getInterfacesFromClassType(resource);
}
return this.getInterfacesFromGQLSchema(resource);
}

@CachedByArg()
private getInterfacesFromClassType(
resource: EnhancedResource<any>,
): ReadonlyArray<EnhancedResource<any>> {
const map = this.getEnhancedMap();
const resSet = new Set<EnhancedResource<any>>(Object.values(map));
return [...resource.interfaces].filter((i) => resSet.has(i));
}

@CachedByArg()
private getInterfacesFromGQLSchema(
getInterfaces(
resource: EnhancedResource<any>,
): ReadonlyArray<EnhancedResource<any>> {
const { schema } = this.gqlSchema;
Expand Down

0 comments on commit 99cdb39

Please sign in to comment.