diff --git a/src/__test__/Server.test.ts b/src/__test__/Server.test.ts index 2c6922eb..45a923c1 100644 --- a/src/__test__/Server.test.ts +++ b/src/__test__/Server.test.ts @@ -63,7 +63,7 @@ describe('Server', () => { afterEach(() => { httpServer.close() }) - it('is returns data for all valid queries', async () => { + it('returns data for all valid queries', async () => { const validQueryResult = await client.query({ query: gql`query validButNotWhitelisted { cardano { diff --git a/src/config.ts b/src/config.ts index 8296cebd..0ca8ff6f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,7 +2,7 @@ import { IntrospectionNotPermitted, MissingConfig, TracingRequired } from './lib import { CorsOptions } from 'apollo-server-express' export type Config = { - allowIntrospection: boolean + allowIntrospection?: boolean allowedOrigins: CorsOptions['origin'] apiPort: number cacheEnabled: boolean @@ -35,9 +35,8 @@ export function getConfig (): Config { if (whitelistPath && allowIntrospection) { throw new IntrospectionNotPermitted('whitelist') } - return { - allowIntrospection: allowIntrospection || false, + allowIntrospection, allowedOrigins: allowedOrigins || true, apiPort: apiPort || 3100, cacheEnabled: cacheEnabled || false, @@ -62,14 +61,14 @@ function filterAndTypecastEnvs (env: any) { WHITELIST_PATH } = env return { - allowIntrospection: ALLOW_INTROSPECTION === 'true', + allowIntrospection: ALLOW_INTROSPECTION === 'true' ? true : undefined, allowedOrigins: ALLOWED_ORIGINS, apiPort: Number(API_PORT), - cacheEnabled: CACHE_ENABLED === 'true', + cacheEnabled: CACHE_ENABLED === 'true' ? true : undefined, hasuraUri: HASURA_URI, - prometheusMetrics: PROMETHEUS_METRICS === 'true', + prometheusMetrics: PROMETHEUS_METRICS === 'true' ? true : undefined, queryDepthLimit: Number(QUERY_DEPTH_LIMIT), - tracing: TRACING === 'true', + tracing: TRACING === 'true' ? true : undefined, whitelistPath: WHITELIST_PATH } } diff --git a/src/index.ts b/src/index.ts index c3b236e2..26d2eeff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,6 +30,7 @@ buildContext(config.hasuraUri) cacheControl: config.cacheEnabled ? { defaultMaxAge: 20 } : undefined, context, introspection: config.allowIntrospection, + playground: config.allowIntrospection, plugins, resolvers, validationRules, @@ -42,6 +43,9 @@ buildContext(config.hasuraUri) app.listen({ port: config.apiPort }, () => { const serverUri = `http://localhost:${config.apiPort}` console.log(`GraphQL HTTP server at ${serverUri}${server.graphqlPath}`) + if (process.env.NODE_ENV !== 'production' && config.whitelistPath) { + console.warn('As a whitelist is in effect, the GraphQL Playground is available, but will not allow schema exploration') + } if (config.prometheusMetrics) { console.log(`Prometheus metrics at ${serverUri}/metrics`) }