Skip to content

Commit

Permalink
perf(graphql): Fix GraphQL version
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This commit changes GraphQL version from 0.13.x to 14.x.x.

- Added Prettier and husky to prevent any styling changes accross commits.

- Added missing inquirer type definitions.
  • Loading branch information
maticzav committed Nov 16, 2018
1 parent 8ef59ab commit baa691a
Show file tree
Hide file tree
Showing 12 changed files with 1,672 additions and 625 deletions.
5 changes: 5 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
72 changes: 38 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,56 +51,60 @@
]
},
"devDependencies": {
"@types/express": "4.11.1",
"@types/graphql": "0.13.1",
"@types/inquirer": "0.0.36",
"@types/lodash": "4.14.104",
"@types/node": "9.4.6",
"@types/node-fetch": "1.6.9",
"@types/ora": "1.3.1",
"@types/request": "2.47.0",
"@types/express": "4.16.0",
"@types/graphql": "14.0.3",
"@types/inquirer": "0.0.43",
"@types/lodash": "4.14.118",
"@types/node": "10.12.9",
"@types/node-fetch": "2.1.3",
"@types/ora": "1.3.4",
"@types/request": "2.48.1",
"@types/rimraf": "2.0.2",
"@types/yargs": "11.0.0",
"@types/yargs": "12.0.1",
"ava": "0.25.0",
"pkg": "4.3.0",
"ts-node": "5.0.0",
"tslint": "5.9.1",
"tslint-config-standard": "7.0.0",
"typescript": "2.7.2"
"husky": "^1.1.4",
"pkg": "4.3.4",
"prettier": "^1.15.2",
"pretty-quick": "^1.8.0",
"ts-node": "7.0.1",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.16.0",
"tslint-config-standard": "^8.0.1",
"typescript": "3.1.6"
},
"dependencies": {
"adm-zip": "0.4.7",
"apollo-codegen": "^0.19.1",
"chalk": "^2.3.1",
"command-exists": "^1.2.2",
"adm-zip": "0.4.13",
"apollo-codegen": "^0.20.2",
"chalk": "^2.4.1",
"command-exists": "^1.2.8",
"cross-spawn": "^6.0.5",
"disparity": "^2.0.0",
"dotenv": "^5.0.0",
"express": "^4.16.2",
"express-request-proxy": "^2.0.0",
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0",
"dotenv": "^6.1.0",
"express": "^4.16.4",
"express-request-proxy": "^2.2.2",
"graphql": "^14.0.2",
"graphql-cli-prepare": "1.4.19",
"graphql-config": "2.2.1",
"graphql-config-extension-graphcool": "1.0.11",
"graphql-config-extension-prisma": "0.2.5",
"graphql-playground-middleware-express": "1.7.6",
"graphql-schema-linter": "0.1.1",
"inquirer": "5.1.0",
"graphql-playground-middleware-express": "1.7.7",
"graphql-schema-linter": "0.1.6",
"inquirer": "6.2.0",
"is-url-superb": "2.0.0",
"js-yaml": "^3.10.0",
"lodash": "^4.17.5",
"js-yaml": "^3.12.0",
"lodash": "^4.17.11",
"mkdirp": "^0.5.1",
"node-fetch": "^2.0.0",
"node-fetch": "^2.3.0",
"npm-paths": "^1.0.0",
"npm-run": "4.1.2",
"opn": "^5.2.0",
"ora": "^1.4.0",
"opn": "^5.4.0",
"ora": "^3.0.0",
"parse-github-url": "^1.0.2",
"request": "^2.83.0",
"request": "^2.88.0",
"rimraf": "2.6.2",
"source-map-support": "^0.5.3",
"source-map-support": "^0.5.9",
"tmp-graphql-config-extension-openapi": "^1.0.7",
"update-notifier": "^2.3.0",
"yargs": "11.0.0"
"update-notifier": "^2.5.0",
"yargs": "12.0.2"
}
}
5 changes: 5 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
semi: false,
singleQuote: true,
trailingComma: 'all',
}
2 changes: 1 addition & 1 deletion src/cmds/add-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function handler(context: Context) {
chalk.blue(newEndpoints.join(', ')),
)

const { save } = await prompt({
const { save } = await prompt<{ save: boolean }>({
type: 'confirm',
name: 'save',
message: `Is this ok?`,
Expand Down
42 changes: 26 additions & 16 deletions src/cmds/add-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ export async function handler(context: Context) {
const config = await getConfig()
if (config.config.schemaPath && !config.config.projects) {
console.log(chalk.yellow('Your existing config does not use projects.'))
const { existingProjectName }: {[key: string]: string} = await prompt({
type: 'input',
name: 'existingProjectName',
message: 'Enter project name for existing configuration:'
})
const { existingProjectName }: { [key: string]: string } = await prompt<{}>(
{
type: 'input',
name: 'existingProjectName',
message: 'Enter project name for existing configuration:',
},
)

newConfig = { projects: {
[existingProjectName]: config.config }
newConfig = {
projects: {
[existingProjectName]: config.config,
},
}
} else {
newConfig = config.config
}

const { projectName }: {[key: string]: string} = await prompt({
const { projectName }: { [key: string]: string } = await prompt<{}>({
type: 'input',
name: 'projectName',
message: 'Enter project name for new project:',
Expand All @@ -42,17 +46,17 @@ export async function handler(context: Context) {
return true
}
return false
}
},
})

merge(newConfig, { projects: { [projectName]: {} } })

let projectConfig: GraphQLResolvedConfigData = await prompt({
let projectConfig: GraphQLResolvedConfigData = (await prompt({
type: 'input',
name: 'schemaPath',
message: `Local schema file path:`,
default: 'schema.graphql',
validate (schemaPath) {
validate(schemaPath) {
const parentDir = dirname(schemaPath)
if (!existsSync(parentDir)) {
return `Parent dir doesn't exists: ${parentDir}`
Expand All @@ -62,7 +66,7 @@ export async function handler(context: Context) {
}
return true
},
}) as GraphQLResolvedConfigData
})) as GraphQLResolvedConfigData

newConfig.projects[projectName] = projectConfig

Expand All @@ -78,18 +82,24 @@ export async function handler(context: Context) {
}

let configData: string
if (config.configPath.endsWith('.yaml') || config.configPath.endsWith('.yml')) {
if (
config.configPath.endsWith('.yaml') ||
config.configPath.endsWith('.yml')
) {
configData = yaml.safeDump(newConfig)
} else {
configData = JSON.stringify(newConfig, null, 2)
}

console.log(
`\nAbout to write new configuration to ${chalk.blue(config.configPath)}:\n\n` +
chalk.yellow(configData) + '\n',
`\nAbout to write new configuration to ${chalk.blue(
config.configPath,
)}:\n\n` +
chalk.yellow(configData) +
'\n',
)

const { save } = await prompt({
const { save } = await prompt<{ save: boolean }>({
type: 'confirm',
name: 'save',
message: `Is this ok?`,
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function handler(
}

if (!directory) {
const { newDir } = await context.prompt({
const { newDir } = await context.prompt<{ newDir: string }>({
type: 'input',
name: 'newDir',
default: '.',
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function handler(
const choices = defaultBoilerplates.map(
bp => `${padEnd(bp.name, maxNameLength + 2)} ${bp.description}`,
)
const { choice } = await context.prompt({
const { choice } = await context.prompt<{ choice: string }>({
type: 'list',
name: 'choice',
message: `Choose GraphQL boilerplate project:`,
Expand Down
55 changes: 32 additions & 23 deletions src/cmds/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ import {

import { Context } from '../'

export async function handler (context: Context) {
export async function handler(context: Context) {
const { prompt } = context

const { projectName }: {[key: string]: string} = await prompt({
const { projectName }: { [key: string]: string } = await prompt<{
[key: string]: string
}>({
type: 'input',
name: 'projectName',
message: 'Enter project name (Enter to skip):'
message: 'Enter project name (Enter to skip):',
})

let config: GraphQLResolvedConfigData = await prompt({
let config: GraphQLResolvedConfigData = (await prompt({
type: 'input',
name: 'schemaPath',
message: `Local schema file path:`,
default: 'schema.graphql',
validate (schemaPath) {
validate(schemaPath) {
const parentDir = dirname(schemaPath)
if (!existsSync(parentDir)) {
return `Parent dir doesn't exists: ${parentDir}`
Expand All @@ -38,7 +40,7 @@ export async function handler (context: Context) {
}
return true
},
}) as GraphQLResolvedConfigData
})) as GraphQLResolvedConfigData

let extensionEndpoints = {}
while (await addEndpoint(prompt, extensionEndpoints)) {
Expand All @@ -53,14 +55,16 @@ export async function handler (context: Context) {

let finalConfig: any = config
if (projectName) {
finalConfig = { projects: {
[projectName]: config
}}
finalConfig = {
projects: {
[projectName]: config,
},
}
}

// TODO: add validation of entire config

const { configFormat } = await prompt({
const { configFormat } = await prompt<{ configFormat: 'JSON' | 'YAML' }>({
type: 'list',
name: 'configFormat',
message: 'What format do you want to save your config in?',
Expand All @@ -71,16 +75,18 @@ export async function handler (context: Context) {
const configFilename = resolve(
configFormat === 'JSON' ? GRAPHQL_CONFIG_NAME : GRAPHQL_CONFIG_YAML_NAME,
)
const configData = configFormat === 'JSON' ?
JSON.stringify(finalConfig, null, 2) :
yaml.safeDump(finalConfig)
const configData =
configFormat === 'JSON'
? JSON.stringify(finalConfig, null, 2)
: yaml.safeDump(finalConfig)

console.log(
`\nAbout to write to ${chalk.blue(configFilename)}:\n\n` +
chalk.yellow(configData) + '\n',
chalk.yellow(configData) +
'\n',
)

const { confirmSave } = await prompt({
const { confirmSave } = await prompt<{ confirmSave: boolean }>({
type: 'confirm',
name: 'confirmSave',
message: `Is this ok?`,
Expand All @@ -94,12 +100,15 @@ export async function handler (context: Context) {
}
}

export async function addEndpoint (prompt: Context['prompt'], extensionEndpoints) {
const { url } = await prompt({
export async function addEndpoint(
prompt: Context['prompt'],
extensionEndpoints,
) {
const { url } = await prompt<{ url: string }>({
name: 'url',
type: 'input',
message: 'Endpoint URL (Enter to skip):',
validate (url) {
validate(url) {
if (url === '') {
return true
}
Expand All @@ -113,14 +122,14 @@ export async function addEndpoint (prompt: Context['prompt'], extensionEndpoints
return false
}

const { name } = await prompt({
const { name } = await prompt<{ name: string }>({
type: 'input',
name: 'name',
message: 'Name of this endpoint, for e.g. default, dev, prod:',
default () {
default() {
return extensionEndpoints['default'] ? undefined : 'default'
},
validate (name) {
validate(name) {
if (name === '') {
return `You can't use empty string as a name.`
}
Expand All @@ -133,7 +142,7 @@ export async function addEndpoint (prompt: Context['prompt'], extensionEndpoints

let endpoint: any = { url }

const { subscriptionUrl } = await prompt({
const { subscriptionUrl } = await prompt<{ subscriptionUrl: string }>({
type: 'input',
name: 'subscriptionUrl',
message: 'Subscription URL (Enter to skip):',
Expand All @@ -149,7 +158,7 @@ export async function addEndpoint (prompt: Context['prompt'], extensionEndpoints

extensionEndpoints[name] = endpoint

return (await prompt({
return (await prompt<{ continue: boolean }>({
type: 'confirm',
name: 'continue',
message: 'Do you want to add other endpoints?',
Expand Down
5 changes: 3 additions & 2 deletions src/cmds/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as requestProxy from 'express-request-proxy'
import * as fs from 'fs'
import expressPlayground from 'graphql-playground-middleware-express'
import * as opn from 'opn'
import { AddressInfo } from 'net'

import { Context, noEndpointError, getTmpPath } from '../'

Expand Down Expand Up @@ -33,7 +34,7 @@ export const builder = {
const startServer = async ({
context,
endpoint,
port = 3000,
port = '3000',
}: {
context: Context
endpoint: string
Expand Down Expand Up @@ -77,7 +78,7 @@ const startServer = async ({
}

const listener = app.listen(port, () => {
let host = listener.address().address
let host = (listener.address() as AddressInfo).address
if (host === '::') {
host = 'localhost'
}
Expand Down
Loading

0 comments on commit baa691a

Please sign in to comment.