Skip to content

Commit

Permalink
Represent argument-less methods as properties (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
aldahick authored Oct 8, 2018
1 parent a20a1f8 commit 4630f1b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/decorators/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const field = (options?: FieldOptions) => <T, K extends keyof T & string>
name: parameter,
type: options!.arguments![parameter] || paramTypes[i]
}));
schema += `(${parameters.map(p => `${p.name}: ${p.type}`)})`;
if (parameters.length > 0) {
schema += `(${parameters.map(p => `${p.name}: ${p.type}`)})`;
}
Reflect.defineMetadata("barnacle:parameters", parameters, target, key);
}
if (type !== undefined) {
Expand Down
1 change: 1 addition & 0 deletions test/cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from "./fields-complex";
export * from "./fields-nullable";
export * from "./methods";
export * from "./methods-complex";
export * from "./methods-no-arguments";
export * from "./methods-no-return";
10 changes: 10 additions & 0 deletions test/cases/methods-no-arguments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as barnacle from "../../lib";

export class MethodsNoArguments {
static description = `create a "field" for methods without arguments`;
static schema = `type MethodsNoArguments {
noArguments: String!
}`;
@barnacle.field()
noArguments(): string { return ""; }
}

0 comments on commit 4630f1b

Please sign in to comment.