Skip to content

Commit

Permalink
fix: generate preview schema using the read schema plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed May 20, 2020
1 parent 37d4186 commit b6c1115
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/api-headless-cms/src/handler/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default (
context.cms.PREVIEW = options.type === "preview";
context.cms.MANAGE = options.type === "manage";

if (context.cms.READ) {
if (!context.cms.MANAGE) {
context.resolvedValues = new TypeValueEmitter();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ interface RenderTypesFromFieldPlugins {
(params: { fieldTypePlugins: CmsFieldTypePlugins; type: string }): GraphQLSchemaModule[];
}

const TYPE_MAP = {
preview: "read",
read: "read",
manage: "manage"
};

export const getSchemaFromFieldPlugins: RenderTypesFromFieldPlugins = ({
fieldTypePlugins,
type
}) => {
return Object.values(fieldTypePlugins)
.map(pl => {
// Render gql types generated by field type plugins
if (typeof pl[type].createSchema === "function") {
return pl[type].createSchema();
if (typeof pl[TYPE_MAP[type]].createSchema === "function") {
return pl[TYPE_MAP[type]].createSchema();
}
return null;
})
Expand Down

0 comments on commit b6c1115

Please sign in to comment.