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 read property 'type' of undefined" with multiple inheritance levels #5061

Closed
TheReincarnator opened this issue Nov 9, 2020 · 3 comments

Comments

@TheReincarnator
Copy link

TheReincarnator commented Nov 9, 2020

When generating TypeScript types from the following schema , I get "Cannot read property 'type' of undefined":

  type ApplicationForm {
    items: [Item!]!
  }

  interface Item {
    id: ID!
  }
  interface Field {
    id: ID!
    label: String!
  }

  type RichTextItem implements Item {
    id: ID!
    content: String!
  }
  type TextField implements Item & Field {
    id: ID!
    label: String!
  }

I think the code generator is confused by using both types that implement "Item" and "Item & Field".

The problem seems to be in pre-resolve-types.ts, in both transformPrimitiveFields and transformAliasesPrimitiveFields. At that point, the schemaType contains fields that fields do not.

A work-around, maybe even the solution, is to filter all schemaType fields before mapping them:

fields.filter(field => schemaType.getFields()[field]).map(...)
@dotansimha
Copy link
Owner

@TheReincarnator can you please share a live reproduction of that issue?
Thank you!

@ardatan
Copy link
Collaborator

ardatan commented May 11, 2021

Closing this issue for now. Feel free to create a new issue with a minimal reproduction if it still persists.

@n1ru4l
Copy link
Collaborator

n1ru4l commented Nov 5, 2021

@TheReincarnator Hey, can you please share the operation that caused this issue? We have a potential PR that solves this issue, however, @mvestergaard is not able to produce a failing test (See #6874).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants