Skip to content

Commit

Permalink
fix(app-headless-cms-common): push id in the list if no other field e…
Browse files Browse the repository at this point in the history
…xists (#4370)
  • Loading branch information
brunozoric authored Nov 11, 2024
1 parent 9bd4fa2 commit 6ba635c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
17 changes: 7 additions & 10 deletions packages/app-headless-cms-common/src/createFieldsList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CmsModelField, CmsModelFieldTypePlugin, CmsModel } from "~/types";
import { CmsModel, CmsModelField, CmsModelFieldTypePlugin } from "~/types";
import { plugins } from "@webiny/plugins";

interface CreateFieldsListParams {
Expand All @@ -9,7 +9,7 @@ interface CreateFieldsListParams {

export function createFieldsList({
model,
fields,
fields: inputFields,
graphQLTypePrefix
}: CreateFieldsListParams): string {
const fieldPlugins: Record<string, CmsModelFieldTypePlugin["field"]> = plugins
Expand All @@ -18,7 +18,7 @@ export function createFieldsList({

const typePrefix = graphQLTypePrefix ?? model.singularApiName;

const allFields = fields
const fields = inputFields
.map(field => {
if (!fieldPlugins[field.type]) {
console.log(`Unknown field plugin for field type "${field.type}".`);
Expand Down Expand Up @@ -46,14 +46,11 @@ export function createFieldsList({
return field.fieldId;
})
.filter(Boolean);

/**
* If there are no fields for a given type, we add a dummy `_empty` field, which will also be present in the schema
* on the API side, to protect the schema from invalid types.
* If there are no fields, let's always load the `id` field.
*/
if (!allFields.length) {
allFields.push("_empty");
if (fields.length === 0) {
fields.push("id");
}

return allFields.join("\n");
return fields.join("\n");
}
30 changes: 0 additions & 30 deletions packages/app-headless-cms-common/src/entries.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,6 @@ const createEntrySystemFields = (model: CmsModel) => {
type
displayName
}
revisionCreatedOn
revisionSavedOn
revisionModifiedOn
revisionFirstPublishedOn
revisionLastPublishedOn
revisionCreatedBy {
id
type
displayName
}
revisionSavedBy {
id
type
displayName
}
revisionModifiedBy {
id
type
displayName
}
revisionFirstPublishedBy {
id
type
displayName
}
revisionLastPublishedBy {
id
type
displayName
}
${optionalFields}
`;
};
Expand Down

0 comments on commit 6ba635c

Please sign in to comment.