mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 11:54:10 +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'
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      const globalId = model.globalId;
 | 
			
		||||
      const _schema = _.cloneDeep(_.get(strapi.plugins, `graphql.config._schema.graphql`, {}));
 | 
			
		||||
 | 
			
		||||
      if (!acc.resolver[globalId]) {
 | 
			
		||||
        acc.resolver[globalId] = {};
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // Add timestamps attributes.
 | 
			
		||||
      if (_.get(model, 'options.timestamps') === true) {
 | 
			
		||||
        Object.assign(initialState, {
 | 
			
		||||
          created_at: 'String',
 | 
			
		||||
          updated_at: 'String'
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      const globalId = model.globalId;
 | 
			
		||||
      const _schema = _.cloneDeep(_.get(strapi.plugins, `graphql.config._schema.graphql`, {}));
 | 
			
		||||
        Object.assign(acc.resolver[globalId], {
 | 
			
		||||
          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.
 | 
			
		||||
      const { type = {}, resolver = {} } = _schema;
 | 
			
		||||
@ -471,10 +484,6 @@ module.exports = {
 | 
			
		||||
 | 
			
		||||
      // Build associations queries.
 | 
			
		||||
      (model.associations || []).forEach(association => {
 | 
			
		||||
        if (!acc.resolver[globalId]) {
 | 
			
		||||
          acc.resolver[globalId] = {};
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        switch (association.nature) {
 | 
			
		||||
          case 'manyMorphToOne':
 | 
			
		||||
          case 'manyMorphToMany':
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user