@@ -6,11 +6,26 @@ import sleep = require('sleep-promise')
66
77const defaultRegion : Record < string , string > = { dev : 'us-test-1' , stg : 'us-east-1' , prod : 'us-west-2' }
88
9+ const CREATE_DEPLOYMENT = `
10+ mutation CreateDeployment($dep: NewDeployment!) {
11+ createDeployment(input: $dep) {
12+ uid
13+ name
14+ url
15+ owner
16+ jwtToken
17+ deploymentMode
18+ lambdaScript
19+ }
20+ }
21+ ` ;
22+
923export default class DeployBackend extends BaseCommand {
1024 static description = 'Launch a new Backend'
1125
1226 static examples = [
1327 '$ slash-graphql deploy-backend "My New Backend"' ,
28+ '$ slash-graphql deploy-backend "My New Backend"' ,
1429 ]
1530
1631 static aliases = [ 'create-backend' , 'launch-backend' ]
@@ -21,47 +36,63 @@ export default class DeployBackend extends BaseCommand {
2136 organizationId : flags . string ( { char : 'o' , description : 'Organization ID' , default : '' } ) ,
2237 subdomain : flags . string ( { char : 's' , description : 'Subdomain' } ) ,
2338 mode : flags . string ( { char : 'm' , description : 'Backend Mode' , default : 'graphql' , options : [ 'readonly' , 'graphql' , 'flexible' ] } ) ,
39+ type : flags . string ( { char : 'T' , description : 'Backend Type' , default : 'slash-graphql' , options : [ 'slash-graphql' , 'dedicated' ] } ) ,
40+ jaeger : flags . string ( { description : 'Enable Jaeger (Only works for dedicated backends)' , default : 'false' , options : [ 'true' , 'false' ] } ) ,
41+ acl : flags . string ( { description : 'Enable ACL (Only works for dedicated backends)' , default : 'false' , options : [ 'true' , 'false' ] } ) ,
42+ dgraphHA : flags . string ( { description : 'Enable High Availability (Only works for dedicated backends)' , default : 'false' , options : [ 'true' , 'false' ] } ) ,
43+ size : flags . string ( { description : 'Backend Size (Only Works for dedicated backends)' , default : 'small' , options : [ 'small' , 'medium' , 'large' , 'xlarge' ] } ) ,
44+ storage : flags . integer ( { description : 'Alpha Storage in GBs - Accepts Only Integers (Only Works for dedicated backends)' , default : 10 } ) ,
45+ dataFile : flags . string ( { description : 'Data File Path for Bulk Loader (Only works for dedicated backends)' , default : '' } ) ,
46+ schemaFile : flags . string ( { description : 'Dgraph Schema File Path for Bulk Loader (Only works for dedicated backends)' , default : '' } ) ,
47+ gqlSchemaFile : flags . string ( { description : 'GQL Schema File Path for Bulk Loader (Only works for dedicated backends)' , default : '' } ) ,
2448 }
2549
2650 static args = [ { name : 'name' , description : 'Backend Name' , required : true } ]
2751
2852 async run ( ) {
2953 const opts = this . parse ( DeployBackend )
30- const { apiServer, authFile} = getEnvironment ( opts . flags . environment )
54+ const { apiServer, authFile, deploymentProtocol } = getEnvironment ( opts . flags . environment )
3155
3256 const token = await this . getAccessToken ( apiServer , authFile )
3357
3458 if ( ! token ) {
3559 this . error ( 'Please login with `slash-graphql login` before creating a backend' )
3660 }
3761
38- const response = await fetch ( `${ apiServer } /deployments/create` , {
39- method : 'POST' ,
40- headers : {
41- 'Content-Type' : 'application/json' ,
42- Authorization : `Bearer ${ token } ` ,
43- } ,
44- body : JSON . stringify ( {
62+ const { errors, data} = await this . sendGraphQLRequest ( apiServer , token , CREATE_DEPLOYMENT , {
63+ dep : {
4564 name : opts . args . name ,
4665 zone : opts . flags . region || defaultRegion [ opts . flags . environment ] ,
4766 subdomain : opts . flags . subdomain ,
4867 deploymentMode : opts . flags . mode ,
49- organizationId : opts . flags . organizationId ,
50- } ) ,
68+ organizationUID : opts . flags . organizationId === "" ? null : opts . flags . organizationId ,
69+ enterprise : opts . flags . type === "dedicated" ? "true" : "false" ,
70+ size : opts . flags . size ,
71+ storage : opts . flags . storage ,
72+ aclEnabled : opts . flags . acl ,
73+ jaegerEnabled : opts . flags . jaeger ,
74+ dgraphHA : opts . flags . dgraphHA ,
75+ bulkLoadSchemaFilePath : opts . flags . schemaFile ,
76+ bulkLoadGQLSchemaFilePath : opts . flags . gqlSchemaFile ,
77+ bulkLoadDataFilePath : opts . flags . dataFile ,
78+ } ,
5179 } )
52- if ( response . status !== 200 ) {
53- this . error ( `Unable to create backend. ${ response . status } ${ await response . text ( ) } ` )
80+ if ( errors ) {
81+ for ( const { message} of errors ) {
82+ this . error ( "Unable to create backend. " + message )
83+ }
84+ return
5485 }
55- const deployment = await response . json ( ) as APIBackend
56- const endpoint = `https://${ deployment . url } /graphql`
86+
87+ const deployment = data . createDeployment as APIBackend
88+ const endpoint = `${ deploymentProtocol } ://${ deployment . url } /graphql`
5789
5890 if ( ! opts . flags . quiet ) {
5991 this . log ( `Waiting for backend to come up at ${ endpoint } ` )
6092 }
6193
6294 await this . pollForEndpoint ( endpoint )
63-
64- this . log ( endpoint )
95+ this . log ( `Deployment Launched at: ${ endpoint } ` )
6596 }
6697
6798 async pollForEndpoint ( endpoint : string , endTime = new Date ( new Date ( ) . getTime ( ) + ( 120 * 1000 ) ) ) {
@@ -79,6 +110,6 @@ export default class DeployBackend extends BaseCommand {
79110
80111 sleep ( 5000 )
81112 }
82- this . error ( 'Gave up waiting for backend after 2 minutes' )
113+ this . error ( "Looks like your backend is taking longer than usual to come up. If you are bulk loading, then it might take a little more time based on your data size." )
83114 }
84115}
0 commit comments