Avoid fetching from database when only accessing primary key
This commit is contained in:
parent
7e619deb22
commit
35b0c5b09e
13
src/index.js
13
src/index.js
|
@ -156,10 +156,15 @@ module.exports = {
|
|||
types: {
|
||||
[typeName]: async function({ id }) {
|
||||
let normalFields = fieldNames.map((name) => {
|
||||
return [ name, async (_, { dlayerKnexTable }) => {
|
||||
let record = await dlayerKnexTable.load(id);
|
||||
return record[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 }) => {
|
||||
let record = await dlayerKnexTable.load(id);
|
||||
return record[name];
|
||||
}];
|
||||
}
|
||||
});
|
||||
|
||||
let relationFields = [];
|
||||
|
|
Loading…
Reference in a new issue