Skip to content

Commit

Permalink
fix(core): Improve message for custom field schema errors
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Apr 29, 2024
1 parent 8a1fffb commit 7ac4ac9
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions packages/core/src/api/config/graphql-custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
GraphQLInputObjectType,
GraphQLList,
GraphQLSchema,
isInterfaceType,
parse,
} from 'graphql';

import { CustomFieldConfig, CustomFields } from '../../config/custom-field/custom-field-types';
import { Logger } from '../../config/logger/vendure-logger';

import { getCustomFieldsConfigWithoutInterfaces } from './get-custom-fields-config-without-interfaces';

Expand Down Expand Up @@ -47,12 +47,23 @@ export function addGraphQLCustomFields(

for (const fieldDef of customEntityFields) {
if (fieldDef.type === 'relation') {
if (!schema.getType(fieldDef.graphQLType || fieldDef.entity.name)) {
throw new Error(
`The GraphQL type "${
fieldDef?.graphQLType ?? '(unknown)'
}" specified by the ${entityName}.${fieldDef.name} custom field does not exist`,
);
const graphQlTypeName = fieldDef.graphQLType || fieldDef.entity.name;
if (!schema.getType(graphQlTypeName)) {
const customFieldPath = `${entityName}.${fieldDef.name}`;
const errorMessage = `The GraphQL type "${
graphQlTypeName ?? '(unknown)'
}" specified by the ${customFieldPath} custom field does not exist in the ${publicOnly ? 'Shop API' : 'Admin API'} schema.`;
Logger.warn(errorMessage);
if (publicOnly) {
Logger.warn(
[
`This can be resolved by either:`,
` - setting \`public: false\` in the ${customFieldPath} custom field config`,
` - defining the "${graphQlTypeName}" type in the Shop API schema`,
].join('\n'),
);
}
throw new Error(errorMessage);
}
}
}
Expand Down Expand Up @@ -245,7 +256,7 @@ export function addServerConfigCustomFields(
'',
)}
}
type EntityCustomFields {
entityName: String!
customFields: [CustomFieldConfig!]!
Expand Down

0 comments on commit 7ac4ac9

Please sign in to comment.