Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Feb 22, 2023
2 parents f4d4a6a + 3bfb416 commit 718b33d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CmsGraphQLSchemaSorterPlugin } from "~/plugins";
import { buildSchemaPlugins } from "~/graphql/buildSchemaPlugins";
import { createExecutableSchema } from "~/graphql/createExecutableSchema";
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
import { generateAlphaNumericId } from "@webiny/utils";

const defaultTitleFieldId = "id";

Expand Down Expand Up @@ -277,18 +278,29 @@ interface CreateGraphQLSchemaParams {
const createGraphQLSchema = async (params: CreateGraphQLSchemaParams): Promise<any> => {
const { context, model } = params;

context.security.disableAuthorization();
const models = await context.cms.listModels();
context.security.enableAuthorization();

const modelPlugins = await buildSchemaPlugins({
context,
models: [model]
models: models.concat([model])
});

const plugins = context.plugins.byType<GraphQLSchemaPlugin<CmsContext>>(
GraphQLSchemaPlugin.type
);
plugins.push(...modelPlugins);
const plugins = context.plugins
.byType<GraphQLSchemaPlugin<CmsContext>>(GraphQLSchemaPlugin.type)
.reduce<Record<string, GraphQLSchemaPlugin<CmsContext>>>((collection, plugin) => {
const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;
collection[name] = plugin;
return collection;
}, {});
for (const plugin of modelPlugins) {
const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;
plugins[name] = plugin;
}

return createExecutableSchema({
plugins
plugins: Object.values(plugins)
});
};

Expand Down Expand Up @@ -392,14 +404,6 @@ export const validateModelFields = async (params: ValidateModelFieldsParams): Pr
*/
if (!existingField) {
continue;
// throw new WebinyError(
// `Cannot remove the field "${lockedField.fieldId}" because it's already in use in created content.`,
// "ENTRY_FIELD_USED",
// {
// lockedField,
// fields
// }
// );
}

if (lockedField.multipleValues !== existingField.multipleValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const createBaseContentSchema = ({ context }: Params): GraphQLSchemaPlugi
.byType<GraphQLScalarPlugin>("graphql-scalar")
.map(item => item.scalar);

return new GraphQLSchemaPlugin({
const plugin = new GraphQLSchemaPlugin({
typeDefs: /* GraphQL */ `
${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
scalar JSON
Expand Down Expand Up @@ -77,4 +77,7 @@ export const createBaseContentSchema = ({ context }: Params): GraphQLSchemaPlugi
}
}
});
plugin.name = `headless-cms.graphql.schema.base`;

return plugin;
};
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const createContentEntriesSchema = ({
});
}

return new GraphQLSchemaPlugin<CmsContext>({
const plugin = new GraphQLSchemaPlugin<CmsContext>({
typeDefs: /* GraphQL */ `
type CmsModelMeta {
modelId: String
Expand Down Expand Up @@ -385,4 +385,7 @@ export const createContentEntriesSchema = ({
}
}
});
plugin.name = `headless-cms.graphql.schema.${context.cms.type}.contentEntries`;

return plugin;
};
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const createGroupsSchema = ({ context }: Params): GraphQLSchemaPlugin<Cms
};
}

return new GraphQLSchemaPlugin<CmsContext>({
const plugin = new GraphQLSchemaPlugin<CmsContext>({
typeDefs: /* GraphQL */ `
type CmsContentModelGroup {
id: ID!
Expand All @@ -155,4 +155,7 @@ export const createGroupsSchema = ({ context }: Params): GraphQLSchemaPlugin<Cms
`,
resolvers
});
plugin.name = `headless-cms.graphql.schema.${context.cms.type}.groups`;

return plugin;
};
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const createModelsSchema = ({ context }: Params): GraphQLSchemaPlugin<Cms
`;
}

return new GraphQLSchemaPlugin<CmsContext>({
const plugin = new GraphQLSchemaPlugin<CmsContext>({
typeDefs: /* GraphQL */ `
type CmsFieldValidation {
name: String!
Expand Down Expand Up @@ -292,4 +292,7 @@ export const createModelsSchema = ({ context }: Params): GraphQLSchemaPlugin<Cms
`,
resolvers
});

plugin.name = `headless-cms.graphql.schema.${context.cms.type}.models`;
return plugin;
};

0 comments on commit 718b33d

Please sign in to comment.