-
Notifications
You must be signed in to change notification settings - Fork 19
Implement defaultValue for @Arg #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,25 +91,60 @@ describe('Arguments with @Arg', () => { | |
| }); | ||
|
|
||
| it('Will allow registering argument at runtime', () => { | ||
| @ObjectType() | ||
| class Foo { | ||
| @Field() | ||
| bar(baz: string, bazRequired: string): string { | ||
| return baz; | ||
| } | ||
| } | ||
|
|
||
| Arg({ type: String, isNullable: true })(Foo.prototype, 'bar', 0); | ||
| Arg({ type: String, isNullable: false })(Foo.prototype, 'bar', 1); | ||
|
|
||
| const [bazArg, bazRequiredArg] = compileObjectType( | ||
| Foo, | ||
| ).getFields().bar.args; | ||
|
|
||
| expect(bazArg.type).toBe(GraphQLString); | ||
| expect(bazRequiredArg.type).toEqual(new GraphQLNonNull(GraphQLString)); | ||
| }); | ||
|
|
||
| it('Respects unset defaultValue @Arg option', () => { | ||
| @ObjectType() | ||
| class Foo { | ||
| @Field() | ||
| bar( | ||
| @Arg({ isNullable: true }) | ||
| baz: string, | ||
| @Arg({ isNullable: false }) | ||
| bazRequired: string, | ||
| ): string { | ||
| return baz; | ||
| } | ||
| } | ||
|
|
||
| Arg({type: String, isNullable: true})(Foo.prototype, 'bar', 0); | ||
| Arg({type: String, isNullable: false})(Foo.prototype, 'bar', 1); | ||
|
|
||
| const [bazArg, bazRequiredArg] = compileObjectType( | ||
| Foo, | ||
| ).getFields().bar.args; | ||
|
|
||
| expect(bazArg.type).toBe(GraphQLString); | ||
| expect(bazArg.defaultValue).toBe(undefined); | ||
| expect(bazRequiredArg.type).toEqual(new GraphQLNonNull(GraphQLString)); | ||
| }); | ||
|
|
||
| it('Respects defaultValue @Arg option', () => { | ||
| @ObjectType() | ||
| class Foo { | ||
| @Field() | ||
| bar( | ||
| @Arg({ isNullable: true, defaultValue: 'default' }) | ||
| baz: string, | ||
| ): string { | ||
| return baz; | ||
| } | ||
| } | ||
| const compiledObject = compileObjectType(Foo); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to test it basing on resolving some field that is based on knowing default value.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I couldn't think of a way to do this, maybe defining a schema in the test, compiling it and executing against it?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added such a condition, I hope async/await is OK, seemed the easiest way to do it. |
||
| const [bazArg] = compiledObject.getFields().bar.args; | ||
| expect(bazArg.type).toBe(GraphQLString); | ||
| expect(bazArg.defaultValue).toBe('default'); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should keep focusing only on registering args at runtime. Having default values tested here pollutes this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I agree, I haven't actually changed this test at all, I have no idea why github has decided to render the diff like this, my own tools don't. Though it does look like something autoformatted the parameter block (line 97), maybe that's it.