Browse Source

fix(core): Correctly return custom field relation scalar fields

Michael Bromley 1 year ago
parent
commit
1280cf3b74

+ 44 - 2
packages/core/e2e/custom-fields.e2e-spec.ts

@@ -215,6 +215,9 @@ describe('Custom fields', () => {
                                     type
                                     list
                                 }
+                                ... on RelationCustomFieldConfig {
+                                    scalarFields
+                                }
                             }
                         }
                     }
@@ -241,7 +244,25 @@ describe('Custom fields', () => {
                 { name: 'validateFn2', type: 'string', list: false },
                 { name: 'validateFn3', type: 'string', list: false },
                 { name: 'validateFn4', type: 'string', list: false },
-                { name: 'validateRelation', type: 'relation', list: false },
+                {
+                    name: 'validateRelation',
+                    type: 'relation',
+                    list: false,
+                    scalarFields: [
+                        'id',
+                        'createdAt',
+                        'updatedAt',
+                        'name',
+                        'type',
+                        'fileSize',
+                        'mimeType',
+                        'width',
+                        'height',
+                        'source',
+                        'preview',
+                        'customFields',
+                    ],
+                },
                 { name: 'stringWithOptions', type: 'string', list: false },
                 { name: 'nullableStringWithOptions', type: 'string', list: false },
                 { name: 'nonPublic', type: 'string', list: false },
@@ -273,6 +294,9 @@ describe('Custom fields', () => {
                                     type
                                     list
                                 }
+                                ... on RelationCustomFieldConfig {
+                                    scalarFields
+                                }
                             }
                         }
                     }
@@ -303,7 +327,25 @@ describe('Custom fields', () => {
                 { name: 'validateFn2', type: 'string', list: false },
                 { name: 'validateFn3', type: 'string', list: false },
                 { name: 'validateFn4', type: 'string', list: false },
-                { name: 'validateRelation', type: 'relation', list: false },
+                {
+                    name: 'validateRelation',
+                    type: 'relation',
+                    list: false,
+                    scalarFields: [
+                        'id',
+                        'createdAt',
+                        'updatedAt',
+                        'name',
+                        'type',
+                        'fileSize',
+                        'mimeType',
+                        'width',
+                        'height',
+                        'source',
+                        'preview',
+                        'customFields',
+                    ],
+                },
                 { name: 'stringWithOptions', type: 'string', list: false },
                 { name: 'nullableStringWithOptions', type: 'string', list: false },
                 { name: 'nonPublic', type: 'string', list: false },

+ 1 - 1
packages/core/src/api/resolvers/admin/global-settings.resolver.ts

@@ -141,7 +141,7 @@ export class GlobalSettingsResolver {
                     .map(c => {
                         // In the VendureConfig, the relation entity is specified
                         // as the class, but the GraphQL API exposes it as a string.
-                        const customFieldConfig: GraphQLCustomFieldConfig = c as any;
+                        const customFieldConfig: GraphQLCustomFieldConfig = { ...c } as any;
                         if (this.isRelationGraphQLType(customFieldConfig) && this.isRelationConfigType(c)) {
                             customFieldConfig.entity = c.entity.name;
                             customFieldConfig.scalarFields = this.getScalarFieldsOfType(