Skip to content
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

@Arg parameter decorators in inherited Resolver do not produce any arguments in GraphQl schema. #408

Closed
altitudems opened this issue Aug 29, 2019 · 4 comments
Labels
Community 👨‍👧 Something initiated by a community Question ❔ Not future request, proposal or bug issue Wontfix ❌ This will not be worked on

Comments

@altitudems
Copy link

Describe the bug
@Arg parameter decorators in inherited Resolver do not produce any arguments in GraphQl schema.

To Reproduce
Create a simple resolver that inherits from a base resolver, following closely the documentation here: https://typegraphql.ml/docs/0.16.0/interfaces-and-inheritance.html.

Example:

import { Resolver, ClassType, Query, Arg, Int, ObjectType, Field } from 'type-graphql'

export function createBaseResolver<T extends ClassType>(classType: ClassType) {
  const suffix = classType.name

  @Resolver({ isAbstract: true })
  abstract class BaseResolver {
    protected items: T[] = []

    @Query(type => classType, { name: `multiply${suffix}` })
    public async multiply(@Arg('a', type => Int) a: number, @Arg('b', type => Int) b: number) {
      let instance = new classType()
      instance.value = a * b
      return instance
    }
  }

  return BaseResolver
}

@ObjectType()
class MyResource {
  @Field()
  public value: number
}

const MyResourceBaseResolver = createBaseResolver(MyResource)

@Resolver(of => MyResource)
export class StoryResolver extends MyResourceBaseResolver {}

Resulting schema:

type Query {
  multiplymyresource: MyResource!
  # Notice the missing arguments a and b
}

Expected behavior
Query or Mutation arguments represented by an @Arg decorator to appear in generated schema.

Logs
N/A

Environment (please complete the following information):

  • OS: OSX
  • Node 10.16.0
  • Package version 0.17.5
  • TypeScript version 3.5.1

Additional context
N/A

@MichalLytek
Copy link
Owner

Cannot reproduce:

async function main() {
  const schema = await buildSchema({
    resolvers: [StoryResolver],
  });
  console.log(printSchema(schema));
}

main();
type MyResource {
  value: Float!
}

type Query {
  multiplyMyResource(b: Int!, a: Int!): MyResource!     
}

I bet you (or your environment like lambda) are using babel which has legacy decorators plugin that doesn't support method parameters decorators, so they are stripped of and args are not registered. See #55 for more info.

@MichalLytek MichalLytek added Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community Need More Info 🤷‍♂️ Further information is requested labels Aug 30, 2019
@altitudems
Copy link
Author

Thanks for the feedback. I'll look for that and report back.

@MichalLytek
Copy link
Owner

Closing for a housekeeping purposes 🔒

@MichalLytek MichalLytek added Question ❔ Not future request, proposal or bug issue Wontfix ❌ This will not be worked on and removed Bug 🐛 Something isn't working Need More Info 🤷‍♂️ Further information is requested labels Sep 17, 2019
@ryanmargono
Copy link

@altitudems did you end up solving this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Question ❔ Not future request, proposal or bug issue Wontfix ❌ This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants