Skip to content

Commit

Permalink
feat: introduce api-settings-manager package
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed May 28, 2020
1 parent 3c45e8e commit cbb2508
Show file tree
Hide file tree
Showing 32 changed files with 308 additions and 17 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"packages/*",
"sample-project/apps/*",
"sample-project/api/apolloGateway",
"sample-project/api/settingsManager",
"sample-project/api/databaseProxy",
"sample-project/api/files/*",
"sample-project/api/formBuilder",
"sample-project/api/cms/*",
"sample-project/api/i18n",
"sample-project/api/i18n/*",
"sample-project/api/pageBuilder",
"sample-project/api/security/*"
],
Expand Down
3 changes: 2 additions & 1 deletion packages/api-cookie-policy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-typescript": "^7.8.3",
"@svgr/webpack": "^4.3.2"
"@svgr/webpack": "^4.3.2",
"@webiny/api-settings-manager": "^4.0.0-beta.1"
},
"publishConfig": {
"access": "public",
Expand Down
15 changes: 13 additions & 2 deletions packages/api-cookie-policy/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import gql from "graphql-tag";
import { emptyResolver, resolveGetSettings, resolveUpdateSettings } from "@webiny/commodo-graphql";
import { emptyResolver, ErrorResponse, resolveUpdateSettings } from "@webiny/commodo-graphql";
import { hasScope } from "@webiny/api-security";
import cookiePolicySettings from "./cookiePolicySettings.model";
import { Context } from "@webiny/graphql/types";
import { Context as SettingsManagerContext } from "@webiny/api-settings-manager/types";

type SettingsContext = Context & SettingsManagerContext;

export default () => [
{
Expand Down Expand Up @@ -102,7 +106,14 @@ export default () => [
cookiePolicy: emptyResolver
},
CookiePolicyQuery: {
getSettings: resolveGetSettings(({ models }) => models.CookiePolicySettings)
getSettings: async (_, args, context: SettingsContext) => {
try {
const data = await context.settingsManager.getSettings("cookie-policy");
return { data };
} catch (err) {
return new ErrorResponse(err);
}
}
},
CookiePolicyMutation: {
updateSettings: hasScope("pb:settings")(
Expand Down
2 changes: 2 additions & 0 deletions packages/api-cookie-policy/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"exclude": [
"node_modules",
"../api-security",
"../api-settings-manager",
"../commodo",
"../commodo-graphql",
"../validation"
Expand All @@ -15,6 +16,7 @@
},
"references": [
{ "path": "../api-security/tsconfig.build.json" },
{ "path": "../api-settings-manager/tsconfig.build.json" },
{ "path": "../commodo-graphql/tsconfig.build.json" },
{ "path": "../validation/tsconfig.build.json" }
]
Expand Down
1 change: 1 addition & 0 deletions packages/api-cookie-policy/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig",
"references": [
{ "path": "../api-security" },
{ "path": "../api-settings-manager" },
{ "path": "../commodo" },
{ "path": "../commodo-graphql" },
{ "path": "../validation" }
Expand Down
1 change: 1 addition & 0 deletions packages/api-form-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@babel/preset-env": "^7.5.5",
"@babel/preset-typescript": "^7.8.3",
"@webiny/api-plugin-commodo-db-proxy": "^4.0.0-beta.1",
"@webiny/api-settings-manager": "^4.0.0-beta.1",
"flow-copy-source": "^2.0.2"
},
"publishConfig": {
Expand Down
15 changes: 13 additions & 2 deletions packages/api-form-builder/src/plugins/graphql/formsSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { resolveUpdateSettings, resolveGetSettings } from "@webiny/commodo-graphql";
import { resolveUpdateSettings, ErrorResponse } from "@webiny/commodo-graphql";
import { hasScope } from "@webiny/api-security";
import { Context } from "@webiny/graphql/types";
import { Context as SettingsManagerContext } from "@webiny/api-settings-manager/types";

type SettingsContext = Context & SettingsManagerContext;

const getFormSettings = ctx => ctx.models.FormSettings;

Expand Down Expand Up @@ -43,7 +47,14 @@ export default {
`,
resolvers: {
FormsQuery: {
getSettings: hasScope("forms:settings")(resolveGetSettings(getFormSettings))
getSettings: hasScope("forms:settings")(async (_, args, context: SettingsContext) => {
try {
const data = await context.settingsManager.getSettings("forms");
return { data };
} catch (err) {
return new ErrorResponse(err);
}
})
},
FormsMutation: {
updateSettings: hasScope("forms:settings")(resolveUpdateSettings(getFormSettings))
Expand Down
2 changes: 2 additions & 0 deletions packages/api-form-builder/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"../graphql",
"../api-i18n",
"../api-security",
"../api-settings-manager",
"../commodo",
"../commodo-graphql",
"../handler-ssr",
Expand All @@ -20,6 +21,7 @@
{ "path": "../graphql/tsconfig.build.json" },
{ "path": "../api-i18n/tsconfig.build.json" },
{ "path": "../api-security/tsconfig.build.json" },
{ "path": "../api-settings-manager/tsconfig.build.json" },
{ "path": "../commodo-graphql/tsconfig.build.json" },
{ "path": "../handler-ssr/tsconfig.build.json" },
{ "path": "../validation/tsconfig.build.json" }
Expand Down
1 change: 1 addition & 0 deletions packages/api-form-builder/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{ "path": "../graphql" },
{ "path": "../api-i18n" },
{ "path": "../api-security" },
{ "path": "../api-settings-manager" },
{ "path": "../commodo" },
{ "path": "../commodo-graphql" },
{ "path": "../handler-ssr" },
Expand Down
1 change: 1 addition & 0 deletions packages/api-google-tag-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-typescript": "^7.8.3",
"@webiny/api-settings-manager": "^4.0.0-beta.1",
"@svgr/webpack": "^4.3.2"
},
"publishConfig": {
Expand Down
15 changes: 13 additions & 2 deletions packages/api-google-tag-manager/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import gql from "graphql-tag";
import { emptyResolver, resolveUpdateSettings, resolveGetSettings } from "@webiny/commodo-graphql";
import { emptyResolver, resolveUpdateSettings, ErrorResponse } from "@webiny/commodo-graphql";
import { hasScope } from "@webiny/api-security";
import googleTagManagerSettings from "./googleTagManagerSettings.model";
import { Context } from "@webiny/graphql/types";
import { Context as SettingsManagerContext } from "@webiny/api-settings-manager/types";

type SettingsContext = Context & SettingsManagerContext;

export default () => [
{
Expand Down Expand Up @@ -63,7 +67,14 @@ export default () => [
googleTagManager: emptyResolver
},
GtmQuery: {
getSettings: resolveGetSettings(({ models }) => models.GoogleTagManagerSettings)
getSettings: async (_, args, context: SettingsContext) => {
try {
const data = await context.settingsManager.getSettings("google-tag-manager");
return { data };
} catch (err) {
return new ErrorResponse(err);
}
}
},
GtmMutation: {
updateSettings: hasScope("pb:settings")(
Expand Down
10 changes: 9 additions & 1 deletion packages/api-google-tag-manager/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
{
"extends": "../../tsconfig.build.json",
"include": ["./src"],
"exclude": ["node_modules", "./dist", "../api-security", "../commodo", "../commodo-graphql"],
"exclude": [
"node_modules",
"./dist",
"../api-security",
"../api-settings-manager",
"../commodo",
"../commodo-graphql"
],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"declarationDir": "./dist"
},
"references": [
{ "path": "../api-security/tsconfig.build.json" },
{ "path": "../api-settings-manager/tsconfig.build.json" },
{ "path": "../commodo-graphql/tsconfig.build.json" }
]
}
1 change: 1 addition & 0 deletions packages/api-google-tag-manager/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig",
"references": [
{ "path": "../api-security" },
{ "path": "../api-settings-manager" },
{ "path": "../commodo" },
{ "path": "../commodo-graphql" }
]
Expand Down
1 change: 1 addition & 0 deletions packages/api-mailchimp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.8.3",
"@svgr/webpack": "^4.3.2",
"@webiny/api-settings-manager": "^4.0.0-beta.1",
"apollo-server-lambda": "^2.9.6"
},
"publishConfig": {
Expand Down
20 changes: 15 additions & 5 deletions packages/api-mailchimp/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import gql from "graphql-tag";
import { emptyResolver, resolveGetSettings, resolveUpdateSettings } from "@webiny/commodo-graphql";
import { emptyResolver, resolveUpdateSettings } from "@webiny/commodo-graphql";
import { ListErrorResponse, ListResponse, ErrorResponse } from "@webiny/graphql";
import { hasScope } from "@webiny/api-security";
import mailchimpSettings from "./mailchimpSettings.model";
import MailchimpApi from "./MailchimpApi";
import { get } from "lodash";
import { Context } from "@webiny/graphql/types";
import { Context, ContextPlugin, GraphQLSchemaPlugin } from "@webiny/graphql/types";
import { Context as SettingsManagerContext } from "@webiny/api-settings-manager/types";

type SettingsContext = Context & SettingsManagerContext;

export default () => [
{
Expand All @@ -14,7 +17,7 @@ export default () => [
apply({ models }) {
models.MailchimpSettings = mailchimpSettings({ createBase: models.createBase });
}
},
} as ContextPlugin,
{
name: "graphql-schema-mailchimp",
type: "graphql-schema",
Expand Down Expand Up @@ -124,7 +127,14 @@ export default () => [
}
},
getSettings: hasScope("pb:settings")(
resolveGetSettings(({ models }) => models.MailchimpSettings)
async (_, args, context: SettingsContext) => {
try {
const data = await context.settingsManager.getSettings("mailchimp");
return { data };
} catch (err) {
return new ErrorResponse(err);
}
}
)
},
MailchimpMutation: {
Expand Down Expand Up @@ -180,5 +190,5 @@ export default () => [
}
}
}
}
} as GraphQLSchemaPlugin
];
11 changes: 10 additions & 1 deletion packages/api-mailchimp/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"extends": "../../tsconfig.build.json",
"include": ["./src"],
"exclude": ["node_modules", "./dist", "../graphql", "../api-security", "../commodo", "../commodo-graphql"],
"exclude": [
"node_modules",
"./dist",
"../graphql",
"../api-security",
"../api-settings-manager",
"../commodo",
"../commodo-graphql"
],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
Expand All @@ -10,6 +18,7 @@
"references": [
{ "path": "../graphql/tsconfig.build.json" },
{ "path": "../api-security/tsconfig.build.json" },
{ "path": "../api-settings-manager/tsconfig.build.json" },
{ "path": "../commodo-graphql/tsconfig.build.json" }
]
}
1 change: 1 addition & 0 deletions packages/api-mailchimp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"references": [
{ "path": "../graphql" },
{ "path": "../api-security" },
{ "path": "../api-settings-manager" },
{ "path": "../commodo" },
{ "path": "../commodo-graphql" }
]
Expand Down
1 change: 1 addition & 0 deletions packages/api-page-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@babel/plugin-proposal-export-default-from": "^7.5.2",
"@babel/preset-env": "^7.5.5",
"@babel/preset-typescript": "^7.8.3",
"@webiny/api-settings-manager": "^4.0.0-beta.1",
"flow-copy-source": "^2.0.2"
},
"publishConfig": {
Expand Down
15 changes: 13 additions & 2 deletions packages/api-page-builder/src/plugins/graphql/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { resolveUpdateSettings, resolveGetSettings } from "@webiny/commodo-graphql";
import { resolveUpdateSettings, ErrorResponse } from "@webiny/commodo-graphql";
import { Context } from "@webiny/graphql/types";
import { Context as SettingsManagerContext } from "@webiny/api-settings-manager/types";

type SettingsContext = Context & SettingsManagerContext;

export default {
name: "graphql-schema-settings-page-builder",
Expand Down Expand Up @@ -81,7 +85,14 @@ export default {
`,
resolvers: {
PbQuery: {
getSettings: resolveGetSettings(ctx => ctx.models.PbSettings)
getSettings: async (_, args, context: SettingsContext) => {
try {
const data = await context.settingsManager.getSettings("page-builder");
return { data };
} catch (err) {
return new ErrorResponse(err);
}
}
},
PbMutation: {
updateSettings: resolveUpdateSettings(ctx => ctx.models.PbSettings)
Expand Down
2 changes: 2 additions & 0 deletions packages/api-page-builder/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"node_modules",
"../graphql",
"../api-security",
"../api-settings-manager",
"../commodo",
"../commodo-graphql",
"../handler-ssr",
Expand All @@ -18,6 +19,7 @@
"references": [
{ "path": "../graphql/tsconfig.build.json" },
{ "path": "../api-security/tsconfig.build.json" },
{ "path": "../api-settings-manager/tsconfig.build.json" },
{ "path": "../commodo-graphql/tsconfig.build.json" },
{ "path": "../handler-ssr/tsconfig.build.json" },
{ "path": "../validation/tsconfig.build.json" }
Expand Down
1 change: 1 addition & 0 deletions packages/api-page-builder/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"references": [
{ "path": "../graphql" },
{ "path": "../api-security" },
{ "path": "../api-settings-manager" },
{ "path": "../commodo" },
{ "path": "../commodo-graphql" },
{ "path": "../handler-ssr" },
Expand Down
1 change: 1 addition & 0 deletions packages/api-settings-manager/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("../../.babel.node");
21 changes: 21 additions & 0 deletions packages/api-settings-manager/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Webiny

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions packages/api-settings-manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @webiny/api-settings-manager
Loading

0 comments on commit cbb2508

Please sign in to comment.