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

Cannot extend Resolver Returned model class #201

Closed
chengjia0807 opened this issue Nov 20, 2018 · 1 comment
Closed

Cannot extend Resolver Returned model class #201

chengjia0807 opened this issue Nov 20, 2018 · 1 comment
Labels
Duplicate 🔑 This issue or pull request already exists

Comments

@chengjia0807
Copy link

Hi,

Type-graphql is a amazing library for sure

I currently got an issue with extending Return model class in Resolver

For example:

Model:

@ObjectType({ description: "User Type" })
export class SubUser {
  @Field()
  firstName: string;
}

@ObjectType({ description: "User Type" })
export class User extends SubUser {
  @Field()
  id: string;
  @Field()
  lastName: string;
}

Query:

query getUser{
  getUser{
    firstName,
    lastName
  }
}

Resolver:

  @Authorized()
  @Query(returns => User, { nullable: true })
  async getUser() {
    return await getUser();
  }

Error:

"stacktrace": [
            "Expected value of type \"User\" but got: { email: \"aaa@aaa.com\", id: \"UFZngG0M0lWbE5VtO2unWs9rUne2\", role: \"Student\", signInMethod: \"UserNameAndPassword\", lastName: \"asdasdasda\", phone: \"0451111111\", firstName: \"asdasdas\" }.",
            "",
            "GraphQL request (2:3)",
            "1: query getUser {",
            "2:   getUser {",
            "     ^",
            "3:     firstName",
            "",
            "    at invalidReturnTypeError (C:\\Projects\\eTutors-Backend\\node_modules\\graphql\\execution\\execute.js:711:10)",
            "    at completeObjectValue (C:\\Projects\\eTutors-Backend\\node_modules\\graphql\\execution\\execute.js:703:13)",
            "    at completeValue (C:\\Projects\\eTutors-Backend\\node_modules\\graphql\\execution\\execute.js:598:12)",
            "    at C:\\Projects\\eTutors-Backend\\node_modules\\graphql\\execution\\execute.js:500:16",
            "    at process._tickCallback (internal/process/next_tick.js:68:7)"
          ]

Is it a bug or I was doing wrong thing?

Thanks
CJ

@MichalLytek
Copy link
Owner

#160

@MichalLytek MichalLytek added the Duplicate 🔑 This issue or pull request already exists label Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🔑 This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants