Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app-headless-cms-common): push id in the list if no other field exists #4370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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