mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 23:29:33 +00:00
Display createdAt and updatedAt date with GraphQL
This commit is contained in:
parent
f7b41dbc01
commit
f01b7befd1
@ -387,16 +387,29 @@ module.exports = {
|
|||||||
[model.primaryKey]: 'String'
|
[model.primaryKey]: 'String'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const globalId = model.globalId;
|
||||||
|
const _schema = _.cloneDeep(_.get(strapi.plugins, `graphql.config._schema.graphql`, {}));
|
||||||
|
|
||||||
|
if (!acc.resolver[globalId]) {
|
||||||
|
acc.resolver[globalId] = {};
|
||||||
|
}
|
||||||
|
|
||||||
// Add timestamps attributes.
|
// Add timestamps attributes.
|
||||||
if (_.get(model, 'options.timestamps') === true) {
|
if (_.get(model, 'options.timestamps') === true) {
|
||||||
Object.assign(initialState, {
|
Object.assign(initialState, {
|
||||||
created_at: 'String',
|
created_at: 'String',
|
||||||
updated_at: 'String'
|
updated_at: 'String'
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
const globalId = model.globalId;
|
Object.assign(acc.resolver[globalId], {
|
||||||
const _schema = _.cloneDeep(_.get(strapi.plugins, `graphql.config._schema.graphql`, {}));
|
created_at: (obj, options, context) => {
|
||||||
|
return obj.createdAt || obj.created_at;
|
||||||
|
},
|
||||||
|
updated_at: (obj, options, context) => {
|
||||||
|
return obj.updatedAt || obj.updated_at;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve user customisation.
|
// Retrieve user customisation.
|
||||||
const { type = {}, resolver = {} } = _schema;
|
const { type = {}, resolver = {} } = _schema;
|
||||||
@ -471,10 +484,6 @@ module.exports = {
|
|||||||
|
|
||||||
// Build associations queries.
|
// Build associations queries.
|
||||||
(model.associations || []).forEach(association => {
|
(model.associations || []).forEach(association => {
|
||||||
if (!acc.resolver[globalId]) {
|
|
||||||
acc.resolver[globalId] = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (association.nature) {
|
switch (association.nature) {
|
||||||
case 'manyMorphToOne':
|
case 'manyMorphToOne':
|
||||||
case 'manyMorphToMany':
|
case 'manyMorphToMany':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user