Skip to content

Commit

Permalink
Merge pull request #5055 from brunoLehnen/refactor-5025-add-env-for-p…
Browse files Browse the repository at this point in the history
…layground-and-introspection

Refactor #5025: Add env. vars. for graphql playground and introspection
  • Loading branch information
aldeed authored Mar 20, 2019
2 parents 4e3dfcd + 2ce46ac commit 437f2e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GRAPHQL_INTROSPECTION_ENABLED=true
GRAPHQL_PLAYGROUND_ENABLED=true
HYDRA_ADMIN_URL=http://hydra:4445
HYDRA_OAUTH2_INTROSPECT_URL=http://hydra:4445/oauth2/introspect
HYDRA_TOKEN_URL=http://hydra:4444/oauth2/token
Expand Down
13 changes: 13 additions & 0 deletions imports/node-app/core/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import envalid, { bool, str } from "envalid";

export default envalid.cleanEnv(process.env, {
GRAPHQL_INTROSPECTION_ENABLED: bool({ default: false }),
GRAPHQL_PLAYGROUND_ENABLED: bool({ default: false }),
// This is necessary to override the envalid default
// validation for NODE_ENV, which uses
// str({ choices: ['development', 'test', 'production'] })
//
// We currently need to set NODE_ENV to "jesttest" when
// integration tests run.
NODE_ENV: str()
});
5 changes: 4 additions & 1 deletion imports/node-app/core/createApolloServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import cors from "cors";
import express from "express";
import { makeExecutableSchema, mergeSchemas } from "apollo-server";
import { ApolloServer } from "apollo-server-express";
import config from "./config";
import buildContext from "./util/buildContext";
import getErrorFormatter from "./util/getErrorFormatter";
import tokenMiddleware from "./util/tokenMiddleware";
Expand Down Expand Up @@ -59,7 +60,9 @@ export default function createApolloServer(options = {}) {
schema,
subscriptions: {
path
}
},
introspection: config.GRAPHQL_INTROSPECTION_ENABLED,
playground: config.GRAPHQL_PLAYGROUND_ENABLED
});

// GraphQL endpoint, enhanced with JSON body parser
Expand Down

0 comments on commit 437f2e0

Please sign in to comment.