Avoid fetching from database when only accessing primary key
This commit is contained in:
parent
7e619deb22
commit
35b0c5b09e
|
@ -156,10 +156,15 @@ module.exports = {
|
||||||
types: {
|
types: {
|
||||||
[typeName]: async function({ id }) {
|
[typeName]: async function({ id }) {
|
||||||
let normalFields = fieldNames.map((name) => {
|
let normalFields = fieldNames.map((name) => {
|
||||||
|
if (name === primaryKey) {
|
||||||
|
// No point making a trip to the database if all we need is an ID we already have
|
||||||
|
return [ name, id ];
|
||||||
|
} else {
|
||||||
return [ name, async (_, { dlayerKnexTable }) => {
|
return [ name, async (_, { dlayerKnexTable }) => {
|
||||||
let record = await dlayerKnexTable.load(id);
|
let record = await dlayerKnexTable.load(id);
|
||||||
return record[name];
|
return record[name];
|
||||||
}];
|
}];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let relationFields = [];
|
let relationFields = [];
|
||||||
|
|
Loading…
Reference in a new issue