Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #107 from cjoudrey/add-region-to-projects-command
Browse files Browse the repository at this point in the history
Add region to `projects` list command
  • Loading branch information
schickling authored Jun 23, 2017
2 parents d6e0f4a + 6e2a15d commit 32fdfb6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
12 changes: 10 additions & 2 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mutation addProject($schema: String!, $name: String!, $alias: String, $region: R
schema
alias
version
region
}
}
}
Expand All @@ -91,8 +92,9 @@ mutation addProject($schema: String!, $name: String!, $alias: String, $region: R
schema = json.data.addProject.project.schema
const returnedAlias = json.data.addProject.project.alias
name = json.data.addProject.project.name
const returnedRegion = json.data.addProject.project.region

const projectInfo = {projectId, version, alias: returnedAlias, schema, name}
const projectInfo = {projectId, version, alias: returnedAlias, schema, name, region: returnedRegion}

return projectInfo
}
Expand Down Expand Up @@ -215,7 +217,7 @@ export async function fetchProjects(resolver: Resolver): Promise<[ProjectInfo]>
const query = `\
{
viewer {
user {
user {
projects {
edges {
node {
Expand All @@ -224,6 +226,7 @@ export async function fetchProjects(resolver: Resolver): Promise<[ProjectInfo]>
schema
alias
version
region
}
}
}
Expand All @@ -240,6 +243,7 @@ export async function fetchProjects(resolver: Resolver): Promise<[ProjectInfo]>
alias: p.alias,
schema: p.schema,
version: p.version,
region: p.region,
}))

return projectInfos
Expand All @@ -256,6 +260,7 @@ query ($projectId: ID!){
alias
schema
version
region
}
}
}`
Expand All @@ -274,6 +279,7 @@ query ($projectId: ID!){
schema: json.data.viewer.project.schema,
alias: json.data.viewer.project.alias,
version: String(json.data.viewer.project.version),
region: json.data.viewer.project.region,
}
return projectInfo
}
Expand Down Expand Up @@ -352,6 +358,7 @@ mutation ($projectId: String!, $name: String!, $includeMutationCallbacks: Boolea
alias
schema
version
region
}
}
}`
Expand All @@ -369,6 +376,7 @@ mutation ($projectId: String!, $name: String!, $includeMutationCallbacks: Boolea
schema: json.data.cloneProject.project.schema,
alias: json.data.cloneProject.project.alias,
version: String(json.data.cloneProject.project.version),
region: json.data.cloneProject.project.region,
}

return projectInfo
Expand Down
5 changes: 3 additions & 2 deletions src/commands/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fetchProjects } from '../api/api'
import figures = require('figures')
import {couldNotFetchProjectsMessage, graphcoolProjectFileName} from '../utils/constants'
import { readProjectIdFromProjectFile } from '../utils/file'
import { regionEnumToOption } from '../utils/utils'

const {table, getBorderCharacters} = require('table')
const debug = require('debug')('graphcool')
Expand All @@ -24,14 +25,14 @@ export default async (props: Props, env: SystemEnvironment): Promise<void> => {

const data = projects.map(project => {
const isCurrentProject = currentProjectId !== null && (currentProjectId === project.projectId || currentProjectId === project.alias)
return [isCurrentProject ? '*' : ' ', `${project.alias || project.projectId} `, project.name]
return [isCurrentProject ? '*' : ' ', `${project.alias || project.projectId} `, project.name, regionEnumToOption(project.region)]
})

const output = table(data, {
border: getBorderCharacters('void'),
columnDefault: {
paddingLeft: '0',
paddingRight: '1',
paddingRight: '2',
},
drawHorizontalLine: () => false,
}).trimRight()
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ProjectInfo {
schema: string
version: string
alias: string
region: string
}

export interface MigrationMessage {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export function makePartsEnclodesByCharacterBold(str: string, character: string)
}
}
return components.join(chalk.bold(`\``))
}
}

export function regionEnumToOption(regionEnum: string): string {
return regionEnum.toLowerCase().replace(/_/g, '-')
}
21 changes: 14 additions & 7 deletions tests/fixtures/mock_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ export const mockedPullProjectResponse1 = `\
"alias": null,
"version": 1,
"id": "cj26898xqm9tz0126n34d64ey",
"schema": "${mockedPullResponseSchema}"
"schema": "${mockedPullResponseSchema}",
"region": "EU_WEST_1"
}
}
}
Expand All @@ -253,7 +254,8 @@ export const mockedPullProjectResponseWithAlias1 = `\
"alias": "example",
"version": 1,
"id": "cj26898xqm9tz0126n34d64ey",
"schema": "${mockedPullResponseSchema}"
"schema": "${mockedPullResponseSchema}",
"region": "EU_WEST_1"
}
}
}
Expand All @@ -268,7 +270,8 @@ export const mockedPullProjectResponse2 = `\
"alias": null,
"version": 2,
"id": "cj26898xqm9tz0126n34d64ey",
"schema": "${mockedPullResponseSchema}"
"schema": "${mockedPullResponseSchema}",
"region": "EU_WEST_1"
}
}
}
Expand All @@ -283,7 +286,8 @@ export const mockedPullProjectResponseWithAlias2 = `\
"alias": "example",
"version": 2,
"id": "cj26898xqm9tz0126n34d64ey",
"schema": "${mockedPullResponseSchema}"
"schema": "${mockedPullResponseSchema}",
"region": "EU_WEST_1"
}
}
}
Expand Down Expand Up @@ -325,7 +329,8 @@ export const mockedCreateProjectResponse = `\
"schema": "type Tweet {\\n id: ID!\\n createdAt: DateTime!\\n updatedAt: DateTime!\\n text: String!\\n}\\n",
"version": 1,
"alias": null,
"name": "Example"
"name": "Example",
"region": "EU_WEST_1"
}
}
}
Expand All @@ -340,7 +345,8 @@ export const mockedClonedProjectResponse = `\
"schema": "type Tweet {\\n id: ID!\\n createdAt: DateTime!\\n updatedAt: DateTime!\\n text: String!\\n}\\n",
"version": 1,
"alias": null,
"name": "Clone of Example"
"name": "Clone of Example",
"region": "EU_WEST_1"
}
}
}
Expand All @@ -355,7 +361,8 @@ export const mockedCreateProjectResponseWithAlias = `\
"schema": "type Tweet {\\n id: ID!\\n createdAt: DateTime!\\n updatedAt: DateTime!\\n text: String!\\n}\\n",
"alias": "example",
"version": 1,
"name": "Example"
"name": "Example",
"region": "EU_WEST_1"
}
}
}
Expand Down

0 comments on commit 32fdfb6

Please sign in to comment.