From bc3f0d5eaf7e4bd13021ef53b68f21d06959e703 Mon Sep 17 00:00:00 2001 From: anon Date: Mon, 29 Apr 2019 17:18:34 -0400 Subject: [PATCH] Disable default mutations is now in config file --- postgraphile/README.md | 4 ++-- postgraphile/spec/server/config.spec.ts | 3 ++- postgraphile/src/config/parse.ts | 7 ++++++- postgraphile/src/server/config.ts | 2 +- postgraphile/src/server/interface.ts | 1 + 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/postgraphile/README.md b/postgraphile/README.md index 6915d945..9c388ca3 100644 --- a/postgraphile/README.md +++ b/postgraphile/README.md @@ -23,8 +23,7 @@ Build the docker image in this directory. Start the `GraphiQL` frontend by: * GraphiQL frontend is available at `:3000/graphiql` GraphQL endpoint is available at `:3000/graphql` -By default, this build will expose only the "public" schema - to add other schemas, use either the env variables, -or a config file `config.toml` and set the env var `CONFIG_PATH` to point to its location. Example `toml`: +By default, this build will expose only the "public" schema and will disable mutations - to change mutation behaviour, you can use an optional config file `config.toml` and set the env var `CONFIG_PATH` to point to its location. Example `toml`: ``` [database] @@ -34,6 +33,7 @@ or a config file `config.toml` and set the env var `CONFIG_PATH` to point to its gq_schemas = ["public", "yourschema"] gq_user = "graphql" gq_password = "graphql" + disable_default_mutations = false ``` ## Building diff --git a/postgraphile/spec/server/config.spec.ts b/postgraphile/spec/server/config.spec.ts index e66ff999..347ad8c3 100644 --- a/postgraphile/spec/server/config.spec.ts +++ b/postgraphile/spec/server/config.spec.ts @@ -25,7 +25,8 @@ describe('buildServerConfig', () => { host: 'example.com', database: 'example_database', schemas: ['public'], - ownerConnectionString: 'postgres://admin:admin@host' + ownerConnectionString: 'postgres://admin:admin@host', + disableDefaultMutations: true }; postgraphileMiddleware = jasmine diff --git a/postgraphile/src/config/parse.ts b/postgraphile/src/config/parse.ts index a81cbab7..c51bff6b 100644 --- a/postgraphile/src/config/parse.ts +++ b/postgraphile/src/config/parse.ts @@ -24,6 +24,7 @@ export function parseConfig( let gqSchemas = ['public']; let gqUser = ''; let gqPassword = ''; + let disableDefaultMutations = true; if (configPath) { const tomlContents = readCallback(`${configPath}`).toString(); @@ -37,6 +38,9 @@ export function parseConfig( gqSchemas = parsedToml['database']['gq_schemas']; gqUser = parsedToml['database']['gq_user'] || gqUser; gqPassword = parsedToml['database']['gq_password'] || gqPassword; + disableDefaultMutations = parsedToml['database']['disable_default_mutations'] === undefined + ? true + : parsedToml['database']['disable_default_mutations']; } // Overwrite config values with env. vars if such are set @@ -69,6 +73,7 @@ export function parseConfig( : `postgres://${user}:${password}@${host}:${port}`, database, schemas: gqSchemas, - ownerConnectionString: `postgres://${user}:${password}@${host}:${port}/${database}` + ownerConnectionString: `postgres://${user}:${password}@${host}:${port}/${database}`, + disableDefaultMutations }; } diff --git a/postgraphile/src/server/config.ts b/postgraphile/src/server/config.ts index 03e07157..638036fe 100644 --- a/postgraphile/src/server/config.ts +++ b/postgraphile/src/server/config.ts @@ -27,7 +27,7 @@ export function buildServerConfig( const options: PostgraphileOptions = { appendPlugins: [PgSimplifyInflectorPlugin], - disableDefaultMutations: true, + disableDefaultMutations: databaseConfig.disableDefaultMutations, enableCors: true, exportGqlSchemaPath: 'schema.graphql', graphiql: true, diff --git a/postgraphile/src/server/interface.ts b/postgraphile/src/server/interface.ts index 9d6a066e..816ebcb1 100644 --- a/postgraphile/src/server/interface.ts +++ b/postgraphile/src/server/interface.ts @@ -18,6 +18,7 @@ export interface DatabaseConfig { database: string; schemas: string[]; ownerConnectionString: string; + disableDefaultMutations: boolean; } export interface ServerConfig {