Skip to content

Commit

Permalink
show example values
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Feb 9, 2018
1 parent e042013 commit 302682d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/gatsby/src/schema/type-conflict-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@ const getMeaningfulTypeName = value => {
}
}

const squeezeValue = value =>
_.isArray(value) ? _.uniqBy(value, typeOf) : value

class TypeConflictEntry {
constructor(selector) {
this.selector = selector
this.types = []
this.types = {}
}

addValue(value) {
const typeName = getMeaningfulTypeName(value)
if (!_.includes(this.types, typeName)) {
this.types.push(typeName)
}
this.types[typeName] = squeezeValue(value)
}

printEntry() {
report.log(`${this.selector}: ${this.types.sort().join(`, `)}`)
const sortedByTypeName = _.sortBy(
_.entries(this.types),
([typeName, value]) => typeName
)

report.log(
`${this.selector}:${sortedByTypeName
.map(
([typeName, value]) => `\n ${typeName} (${JSON.stringify(value)})`
)
.join(``)}`
)
}
}

Expand Down

0 comments on commit 302682d

Please sign in to comment.