1
- import {
2
- GraphQLConfig ,
3
- GraphQLConfigData ,
4
- GraphQLConfigEnpointsData ,
5
- GraphQLProjectConfig ,
6
- } from 'graphql-config'
1
+ import { GraphQLConfig , GraphQLConfigData , GraphQLConfigEnpointsData , GraphQLProjectConfig } from 'graphql-config'
7
2
import { PrismaDefinitionClass , Environment } from 'prisma-yml'
8
3
import { set , values } from 'lodash'
9
4
import * as os from 'os'
10
5
import * as path from 'path'
11
6
import * as fs from 'fs'
12
7
13
- export async function patchConfig <
14
- T extends GraphQLConfig | GraphQLProjectConfig
15
- > ( config : T , cwd ?: string , envVars ?: { [ key : string ] : any } ) : Promise < T > {
8
+ export async function patchConfig < T extends GraphQLConfig | GraphQLProjectConfig > (
9
+ config : T ,
10
+ cwd ?: string ,
11
+ envVars ?: { [ key : string ] : any } ,
12
+ ) : Promise < T > {
16
13
config = await patchEndpointsToConfig ( config , cwd , envVars )
17
14
config = patchDirectivesToConfig ( config , cwd , envVars )
18
15
return config
19
16
}
20
17
21
- function patchDirectivesToConfig <
22
- T extends GraphQLConfig | GraphQLProjectConfig
23
- > ( config : T , cwd ?: string , envVars ?: { [ key : string ] : any } ) : T {
18
+ function patchDirectivesToConfig < T extends GraphQLConfig | GraphQLProjectConfig > (
19
+ config : T ,
20
+ cwd ?: string ,
21
+ envVars ?: { [ key : string ] : any } ,
22
+ ) : T {
24
23
config . config = patchDirectivesToConfigData ( config . config , cwd , envVars )
25
24
return config
26
25
}
@@ -31,10 +30,7 @@ function patchDirectivesToConfigData(
31
30
envVars ?: { [ key : string ] : any } ,
32
31
) : GraphQLConfigData {
33
32
// return early if no prisma extension found
34
- const allExtensions = [
35
- config . extensions ,
36
- ...values ( config . projects ) . map ( p => p . extensions ) ,
37
- ]
33
+ const allExtensions = [ config . extensions , ...values ( config . projects ) . map ( p => p . extensions ) ]
38
34
if ( ! allExtensions . some ( e => e && e . prisma ) ) {
39
35
return config
40
36
}
@@ -49,11 +45,7 @@ function patchDirectivesToConfigData(
49
45
Object . keys ( newConfig . projects ) . map ( projectName => {
50
46
const project = newConfig . projects ! [ projectName ]
51
47
if ( project . extensions ) {
52
- set (
53
- newConfig ,
54
- [ 'projects' , projectName , 'extensions' , 'customDirectives' ] ,
55
- getCustomDirectives ( ) ,
56
- )
48
+ set ( newConfig , [ 'projects' , projectName , 'extensions' , 'customDirectives' ] , getCustomDirectives ( ) )
57
49
}
58
50
} )
59
51
}
@@ -78,20 +70,13 @@ export function getCustomDirectives(version?: string) {
78
70
// TODO: Deprecate and remove this public API in favor
79
71
// of patchConfig function in playground and other usages
80
72
// of this project.
81
- export async function patchEndpointsToConfig <
82
- T extends GraphQLConfig | GraphQLProjectConfig
83
- > (
73
+ export async function patchEndpointsToConfig < T extends GraphQLConfig | GraphQLProjectConfig > (
84
74
config : T ,
85
75
cwd ?: string ,
86
76
envVars ?: { [ key : string ] : any } ,
87
77
graceful ?: boolean ,
88
78
) : Promise < T > {
89
- config . config = await patchEndpointsToConfigData (
90
- config . config ,
91
- cwd ,
92
- envVars ,
93
- graceful ,
94
- )
79
+ config . config = await patchEndpointsToConfigData ( config . config , cwd , envVars , graceful )
95
80
return config
96
81
}
97
82
@@ -102,10 +87,7 @@ export async function patchEndpointsToConfigData(
102
87
graceful ?: boolean ,
103
88
) : Promise < GraphQLConfigData > {
104
89
// return early if no prisma extension found
105
- const allExtensions = [
106
- config . extensions ,
107
- ...values ( config . projects ) . map ( p => p . extensions ) ,
108
- ]
90
+ const allExtensions = [ config . extensions , ...values ( config . projects ) . map ( p => p . extensions ) ]
109
91
if ( ! allExtensions . some ( e => e && e . prisma ) ) {
110
92
return config
111
93
}
@@ -115,19 +97,13 @@ export async function patchEndpointsToConfigData(
115
97
const home = os . homedir ( )
116
98
117
99
const env = new Environment ( home )
118
- await env . load ( true )
100
+ await env . load ( )
119
101
120
102
if ( newConfig . extensions && newConfig . extensions . prisma ) {
121
103
set (
122
104
newConfig ,
123
105
[ 'extensions' , 'endpoints' ] ,
124
- await getEndpointsFromPath (
125
- env ,
126
- newConfig . extensions . prisma ,
127
- cwd ,
128
- envVars ,
129
- graceful ,
130
- ) ,
106
+ await getEndpointsFromPath ( env , newConfig . extensions . prisma , cwd , envVars , graceful ) ,
131
107
)
132
108
}
133
109
@@ -139,13 +115,7 @@ export async function patchEndpointsToConfigData(
139
115
set (
140
116
newConfig ,
141
117
[ 'projects' , projectName , 'extensions' , 'endpoints' ] ,
142
- await getEndpointsFromPath (
143
- env ,
144
- project . extensions . prisma ,
145
- cwd ,
146
- envVars ,
147
- graceful ,
148
- ) ,
118
+ await getEndpointsFromPath ( env , project . extensions . prisma , cwd , envVars , graceful ) ,
149
119
)
150
120
}
151
121
} ) ,
@@ -166,31 +136,25 @@ export async function makeConfigFromPath(
166
136
167
137
const home = os . homedir ( )
168
138
const env = new Environment ( home )
169
- await env . load ( true )
139
+ await env . load ( )
170
140
171
141
const definition = new PrismaDefinitionClass ( env , ymlPath , envVars )
172
142
await definition . load ( { } )
173
143
const serviceName = definition . service !
174
144
const stage = definition . stage !
175
145
const clusterName = definition . cluster
176
146
if ( ! clusterName ) {
177
- throw new Error (
178
- `No cluster set. Please set the "cluster" property in your prisma.yml` ,
179
- )
147
+ throw new Error ( `No cluster set. Please set the "cluster" property in your prisma.yml` )
180
148
}
181
- const cluster = definition . getCluster ( )
149
+ const cluster = await definition . getCluster ( )
182
150
if ( ! cluster ) {
183
151
throw new Error (
184
152
`Cluster ${ clusterName } provided in prisma.yml could not be found in global ~/.prisma/config.yml.
185
153
Please check in ~/.prisma/config.yml, if the cluster exists.
186
154
You can use \`docker-compose up -d\` to start a new cluster.` ,
187
155
)
188
156
}
189
- const url = cluster . getApiEndpoint (
190
- serviceName ,
191
- stage ,
192
- definition . getWorkspace ( ) || undefined ,
193
- )
157
+ const url = cluster . getApiEndpoint ( serviceName , stage , definition . getWorkspace ( ) || undefined )
194
158
const token = definition . getToken ( serviceName , stage )
195
159
const headers = token
196
160
? {
@@ -232,23 +196,17 @@ async function getEndpointsFromPath(
232
196
const stage = definition . stage !
233
197
const clusterName = definition . cluster
234
198
if ( ! clusterName ) {
235
- throw new Error (
236
- `No cluster set. Please set the "cluster" property in your prisma.yml` ,
237
- )
199
+ throw new Error ( `No cluster set. Please set the "cluster" property in your prisma.yml` )
238
200
}
239
- const cluster = definition . getCluster ( )
201
+ const cluster = await definition . getCluster ( )
240
202
if ( ! cluster ) {
241
203
throw new Error (
242
204
`Cluster ${ clusterName } provided in prisma.yml could not be found in global ~/.prisma/config.yml.
243
205
Please check in ~/.prisma/config.yml, if the cluster exists.
244
206
You can use \`docker-compose up -d\` to start a new cluster.` ,
245
207
)
246
208
}
247
- const url = cluster . getApiEndpoint (
248
- serviceName ,
249
- stage ,
250
- definition . getWorkspace ( ) || undefined ,
251
- )
209
+ const url = cluster . getApiEndpoint ( serviceName , stage , definition . getWorkspace ( ) || undefined )
252
210
const token = definition . getToken ( serviceName , stage )
253
211
const headers = token
254
212
? {
0 commit comments