Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.

Commit cab6045

Browse files
fix(graphql): error on invalid model (#12)
1 parent b6e8e3e commit cab6045

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

server/graphql/types.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const _ = require('lodash');
22
const { getPluginService } = require('../utils/getPluginService');
3+
const { ValidationError } = require('@strapi/utils').errors;
34

45
const getCustomTypes = (strapi, nexus) => {
56
const { naming } = getPluginService(strapi, 'utils', 'graphql');
@@ -45,15 +46,17 @@ const getCustomTypes = (strapi, nexus) => {
4546
modelName: nexus.stringArg('The model name of the content type'),
4647
slug: nexus.stringArg('The slug to query for'),
4748
},
48-
resolve: async (_, args) => {
49+
resolve: async (_parent, args) => {
4950
const { models } = getPluginService(strapi, 'settingsService').get();
5051
const { modelName, slug } = args;
5152

5253
const model = models[modelName];
5354

5455
// ensure valid model is passed
5556
if (!model) {
56-
return toEntityResponse(null, { resourceUID: uid });
57+
throw new ValidationError(
58+
`${modelName} model name not found, all models must be defined in the settings and are case sensitive.`
59+
);
5760
}
5861

5962
const { uid, field, contentType } = model;

0 commit comments

Comments
 (0)