Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Check modelDef.getType() is defined before use #353

Merged
merged 2 commits into from
Jan 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/graphqlgen/src/generators/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export function fieldsFromModelDefinition(
// If model is of type `type TypeName = { ... }`
if (
modelDef.kind === 'TypeAliasDefinition' &&
(modelDef as TypeAliasDefinition).getType().kind ===
'AnonymousInterfaceAnnotation'
modelDef.getType() &&
modelDef.getType().kind === 'AnonymousInterfaceAnnotation'
) {
const interfaceDef = (modelDef as TypeAliasDefinition).getType() as AnonymousInterfaceAnnotation
const interfaceDef = modelDef.getType() as AnonymousInterfaceAnnotation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup! I probably should have looked a little higher level than my as bike-sheds. I think this code should probably look something more like:

// we already know that modelDef.kind === 'TypeAliasDefinition' here
const interfaceDef = modelDef.getType()
if (interfaceDef && interfaceDef.kind === 'AnonymousInterfaceAnnotation') {
    return interfaceDef.fields
}
return []

Kinda irrelevant though because it seems these types aren't fully capturing everything being passed in at runtime. Don't think it's worth hanging up on code hygiene until that's sorted out.


return interfaceDef.fields
}
Expand Down