MichalLytek / MichalLytek/type-graphql
name property in @Field does not work when used with @ArgsType
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
I am trying to combine the arguments to one of my resolver's functions by using a class that I annotate with `@ArgsType()`. Since the name I want to expose is different in one case from the name I want to use internally, For this I am using the `name` property for one of my fields, which has worked fine so far in my entities (annotated `@ObjectType`). However, whereas `name` does change the name that is exposed to the outside, it also changes the name of the property to which the incoming value is assigned.
**To Reproduce**
Using the following code:
```import { Field, ArgsType, Resolver, Mutation, Args } from 'type-graphql';
import Organization from '../../entities/Organization';
@ArgsType()
export class DeleteOrganizationArgs {
@Field({
name: 'id'
})
slug!: string;
}
@Resolver(Organization)
export default class OrganizationResolver {
@Mutation(returns => Organization)
async deleteOrganization(@Args() args: DeleteOrganizationArgs) {
console.log(args);
// Actually delete organization
}
}
```
Calling my resolver shows the log `{"id": "my-id"}`. This looks like a bug to me, because the type `DeleteOrganizationArgs` does not have a property id.
**Expected behavior**
I expect `args` to be equal to `{"slug": "my-id"}`
**Enviorment (please complete the following information):**
- OS: Ubuntu 18.04.2 LTS
- Node 10.15.1
- Package version 0.16.0
- TypeScript version 3.2.4
Contributor guide
Research direction
Start with the reproduction using @ArgsType, @Field({ name: 'id' }), and the deleteOrganization resolver, then inspect how these decorators map incoming GraphQL arguments onto the DeleteOrganizationArgs instance. Done means the schema still exposes id while the resolver receives {"slug":"my-id"}; verify this behavior against the reported environment or an equivalent test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100