| 
									
										
										
										
											2021-07-05 10:43:36 +02:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const { objectType } = require('nexus'); | 
					
						
							| 
									
										
										
										
											2021-07-30 11:44:26 +02:00
										 |  |  | const { prop } = require('lodash/fp'); | 
					
						
							| 
									
										
										
										
											2021-07-05 10:43:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 17:56:44 +02:00
										 |  |  | module.exports = ({ strapi }) => { | 
					
						
							|  |  |  |   const { naming } = strapi.plugin('graphql').service('utils'); | 
					
						
							| 
									
										
										
										
											2021-07-05 10:43:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 17:56:44 +02:00
										 |  |  |   return { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Build a type definition for a content API response for a given content type | 
					
						
							|  |  |  |      * @param {object} contentType The content type which will be used to build its content API response definition | 
					
						
							|  |  |  |      * @return {NexusObjectTypeDef} | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-23 14:26:31 +02:00
										 |  |  |     buildResponseDefinition(contentType) { | 
					
						
							| 
									
										
										
										
											2021-08-24 17:56:44 +02:00
										 |  |  |       const name = naming.getEntityResponseName(contentType); | 
					
						
							|  |  |  |       const entityName = naming.getEntityName(contentType); | 
					
						
							| 
									
										
										
										
											2021-07-05 10:43:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 17:56:44 +02:00
										 |  |  |       return objectType({ | 
					
						
							|  |  |  |         name, | 
					
						
							| 
									
										
										
										
											2021-07-05 10:43:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 17:56:44 +02:00
										 |  |  |         definition(t) { | 
					
						
							|  |  |  |           t.field('data', { | 
					
						
							|  |  |  |             type: entityName, | 
					
						
							| 
									
										
										
										
											2021-07-05 10:43:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 17:56:44 +02:00
										 |  |  |             resolve: prop('value'), | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; |