SqlBatch junction column name conflict
When doing a junction sqlBatch, the column aliases assigned by JM can conflict, causing hydration to fail.
Eg.
const one = new GraphQLObjectType({
// ...
uniqueKey: 'id'
// ...
})
const two = new GraphQLObjectType({
// ...
fields: {
type: GraphQLList(one),
join: {
junction: {
uniqueKey: 'id',
sqlTable: 'junction_tbl',
sqlBatch: {
parentKey: 'parentKey',
thisKey: 'thisKey',
sqlJoin: () => '', // ...
},
},
},
},
// ...
})
doing a selection on this results in this sql:
SELECT
`two`.`id` AS `id`,
`two`.`id` AS `parentKey`
FROM two `two`;
-- batch --
SELECT
`junction_t`.`id` AS `id`,
`one`.`id` AS `id`,
`junction_t`.`thisKey` AS `thisKey`
FROM junction_tbl `junction_t`
LEFT JOIN one `one` ON // ...
WHERE `junction_t`.`thisKey` IN (66,70,71,72,79,80)
as you can see in the batched SQL statement, one.id is aliased as id, so does junction_t.id. So when the data is hydrated, it ignores the junction table id column because it gets overwritten by the join table id column.
Commenting for visibility - experienced this exact same bug today. I think this has something to do with the aliased field's template string having a new line in it. The code does set-ify the select statements to make them unique, but the extra newline technically makes the select statement different, so the set conversion doesn't eliminate it.
EDIT : I think I might have solved a similar but different issue.
a workaround we've found for this is to define the unique key as a composite of itself: uniqueKey: ['id', 'id'],
This will add the unique key to the query as
CONCAT(id, '#', id) AS `id#id`
Thus working around the conflict
The uniqueKey: ['id', 'id'] workaround fixed it for me too- thanks.
Can you provide a https://github.com/join-monster/join-monster-sscce?