Skip to content

Commit

Permalink
docs(examples): fix using private name error
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLytek committed Feb 18, 2019
1 parent 418a353 commit 0f496d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
6 changes: 2 additions & 4 deletions examples/resolvers-inheritance/person/person.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Resolver, Arg, Int, Mutation } from "../../../src";

import { createResourceResolver } from "../resource/resource.resolver";
import { ResourceResolver } from "../resource/resource.resolver";
import { Person } from "./person.type";
import { PersonRole } from "./person.role";

Expand All @@ -19,10 +19,8 @@ const persons: Person[] = [
},
];

export const ResourceResolver = createResourceResolver(Person, persons);

@Resolver()
export class PersonResolver extends ResourceResolver<Person> {
export class PersonResolver extends ResourceResolver(Person, persons) {
// here you can add resource-specific operations

@Mutation()
Expand Down
6 changes: 2 additions & 4 deletions examples/resolvers-inheritance/recipe/recipe.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Resolver, FieldResolver, Root } from "../../../src";

import { createResourceResolver } from "../resource/resource.resolver";
import { ResourceResolver } from "../resource/resource.resolver";
import { Recipe } from "./recipe.type";

const recipes: Recipe[] = [
Expand All @@ -11,10 +11,8 @@ const recipes: Recipe[] = [
},
];

export const ResourceResolver = createResourceResolver(Recipe, recipes);

@Resolver(of => Recipe)
export class RecipeResolver extends ResourceResolver<Recipe> {
export class RecipeResolver extends ResourceResolver(Recipe, recipes) {
// here you can add resource-specific operations

@FieldResolver()
Expand Down
23 changes: 4 additions & 19 deletions examples/resolvers-inheritance/resource/resource.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ import {
import { Resource } from "./resource";
import { ResourceService, ResourceServiceFactory } from "./resource.service";

// workaround for `return type of exported function has or is using private name`
export abstract class BaseResourceResolver<TResource extends Resource> {
protected resourceService: ResourceService<TResource>;

protected async getOne(id: number): Promise<TResource | undefined> {
throw new Error("Method not implemented.");
}

protected async getAll(args: GetAllArgs): Promise<TResource[]> {
throw new Error("Method not implemented.");
}
}

@ArgsType()
export class GetAllArgs {
@Field(type => Int)
Expand All @@ -37,20 +24,19 @@ export class GetAllArgs {
take: number = 10;
}

export function createResourceResolver<TResource extends Resource>(
export function ResourceResolver<TResource extends Resource>(
ResourceCls: ClassType,
resources: TResource[],
): typeof BaseResourceResolver {
) {
const resourceName = ResourceCls.name.toLocaleLowerCase();

// `isAbstract` decorator option is mandatory to prevent multiple registering in schema
@Resolver(of => ResourceCls, { isAbstract: true })
@Service()
abstract class ResourceResolver extends BaseResourceResolver<TResource> {
abstract class ResourceResolverClass {
protected resourceService: ResourceService<TResource>;

constructor(factory: ResourceServiceFactory) {
super();
this.resourceService = factory.create(resources);
}

Expand All @@ -72,6 +58,5 @@ export function createResourceResolver<TResource extends Resource>(
}
}

// workaround for generics conflict
return ResourceResolver as any;
return ResourceResolverClass;
}
6 changes: 6 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declaration": false
}
}

0 comments on commit 0f496d0

Please sign in to comment.