Skip to content

Commit 0a5b244

Browse files
committed
fix: fix build
1 parent a6796d3 commit 0a5b244

File tree

1 file changed

+26
-68
lines changed

1 file changed

+26
-68
lines changed

src/index.ts

Lines changed: 26 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
import {
2-
GraphQLConfig,
3-
GraphQLConfigData,
4-
GraphQLConfigEnpointsData,
5-
GraphQLProjectConfig,
6-
} from 'graphql-config'
1+
import { GraphQLConfig, GraphQLConfigData, GraphQLConfigEnpointsData, GraphQLProjectConfig } from 'graphql-config'
72
import { PrismaDefinitionClass, Environment } from 'prisma-yml'
83
import { set, values } from 'lodash'
94
import * as os from 'os'
105
import * as path from 'path'
116
import * as fs from 'fs'
127

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> {
1613
config = await patchEndpointsToConfig(config, cwd, envVars)
1714
config = patchDirectivesToConfig(config, cwd, envVars)
1815
return config
1916
}
2017

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 {
2423
config.config = patchDirectivesToConfigData(config.config, cwd, envVars)
2524
return config
2625
}
@@ -31,10 +30,7 @@ function patchDirectivesToConfigData(
3130
envVars?: { [key: string]: any },
3231
): GraphQLConfigData {
3332
// 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)]
3834
if (!allExtensions.some(e => e && e.prisma)) {
3935
return config
4036
}
@@ -49,11 +45,7 @@ function patchDirectivesToConfigData(
4945
Object.keys(newConfig.projects).map(projectName => {
5046
const project = newConfig.projects![projectName]
5147
if (project.extensions) {
52-
set(
53-
newConfig,
54-
['projects', projectName, 'extensions', 'customDirectives'],
55-
getCustomDirectives(),
56-
)
48+
set(newConfig, ['projects', projectName, 'extensions', 'customDirectives'], getCustomDirectives())
5749
}
5850
})
5951
}
@@ -78,20 +70,13 @@ export function getCustomDirectives(version?: string) {
7870
// TODO: Deprecate and remove this public API in favor
7971
// of patchConfig function in playground and other usages
8072
// of this project.
81-
export async function patchEndpointsToConfig<
82-
T extends GraphQLConfig | GraphQLProjectConfig
83-
>(
73+
export async function patchEndpointsToConfig<T extends GraphQLConfig | GraphQLProjectConfig>(
8474
config: T,
8575
cwd?: string,
8676
envVars?: { [key: string]: any },
8777
graceful?: boolean,
8878
): 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)
9580
return config
9681
}
9782

@@ -102,10 +87,7 @@ export async function patchEndpointsToConfigData(
10287
graceful?: boolean,
10388
): Promise<GraphQLConfigData> {
10489
// 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)]
10991
if (!allExtensions.some(e => e && e.prisma)) {
11092
return config
11193
}
@@ -115,19 +97,13 @@ export async function patchEndpointsToConfigData(
11597
const home = os.homedir()
11698

11799
const env = new Environment(home)
118-
await env.load(true)
100+
await env.load()
119101

120102
if (newConfig.extensions && newConfig.extensions.prisma) {
121103
set(
122104
newConfig,
123105
['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),
131107
)
132108
}
133109

@@ -139,13 +115,7 @@ export async function patchEndpointsToConfigData(
139115
set(
140116
newConfig,
141117
['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),
149119
)
150120
}
151121
}),
@@ -166,31 +136,25 @@ export async function makeConfigFromPath(
166136

167137
const home = os.homedir()
168138
const env = new Environment(home)
169-
await env.load(true)
139+
await env.load()
170140

171141
const definition = new PrismaDefinitionClass(env, ymlPath, envVars)
172142
await definition.load({})
173143
const serviceName = definition.service!
174144
const stage = definition.stage!
175145
const clusterName = definition.cluster
176146
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`)
180148
}
181-
const cluster = definition.getCluster()
149+
const cluster = await definition.getCluster()
182150
if (!cluster) {
183151
throw new Error(
184152
`Cluster ${clusterName} provided in prisma.yml could not be found in global ~/.prisma/config.yml.
185153
Please check in ~/.prisma/config.yml, if the cluster exists.
186154
You can use \`docker-compose up -d\` to start a new cluster.`,
187155
)
188156
}
189-
const url = cluster.getApiEndpoint(
190-
serviceName,
191-
stage,
192-
definition.getWorkspace() || undefined,
193-
)
157+
const url = cluster.getApiEndpoint(serviceName, stage, definition.getWorkspace() || undefined)
194158
const token = definition.getToken(serviceName, stage)
195159
const headers = token
196160
? {
@@ -232,23 +196,17 @@ async function getEndpointsFromPath(
232196
const stage = definition.stage!
233197
const clusterName = definition.cluster
234198
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`)
238200
}
239-
const cluster = definition.getCluster()
201+
const cluster = await definition.getCluster()
240202
if (!cluster) {
241203
throw new Error(
242204
`Cluster ${clusterName} provided in prisma.yml could not be found in global ~/.prisma/config.yml.
243205
Please check in ~/.prisma/config.yml, if the cluster exists.
244206
You can use \`docker-compose up -d\` to start a new cluster.`,
245207
)
246208
}
247-
const url = cluster.getApiEndpoint(
248-
serviceName,
249-
stage,
250-
definition.getWorkspace() || undefined,
251-
)
209+
const url = cluster.getApiEndpoint(serviceName, stage, definition.getWorkspace() || undefined)
252210
const token = definition.getToken(serviceName, stage)
253211
const headers = token
254212
? {

0 commit comments

Comments
 (0)