Skip to content

Commit dee0a8d

Browse files
committed
feat(endpoints): only create GraphQLEndpoint if endpoint is not already GraphQLEndpoint
The current implementation assumed an endpoint to be GraphQLConfigEndpointConfig. However, if an extension has already resolved the endpoint configuration to an actual GraphQLEndpoint, this will overwrite that. The new implementation only creates a new GraphQLEndpoint object, if the endpoint was not already resolved.
1 parent 3d8594c commit dee0a8d

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/extensions/endpoints/EndpointsExtension.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type GraphQLConfigEnpointsMapData = {
2626
}
2727

2828
export type GraphQLConfigEnpointsMap = {
29-
[env: string]: GraphQLConfigEnpointConfig
29+
[env: string]: GraphQLConfigEnpointConfig | GraphQLEndpoint
3030
}
3131

3232
export type GraphQLConfigEnpointsData = GraphQLConfigEnpointsMapData
@@ -68,7 +68,11 @@ export class GraphQLEndpointsExtension {
6868
): GraphQLEndpoint {
6969
const endpoint = this.getRawEndpoint(endpointName)
7070
try {
71-
return new GraphQLEndpoint(resolveEnvsInValues(endpoint, env))
71+
const resolved = resolveEnvsInValues(endpoint, env)
72+
if (!(resolved instanceof GraphQLEndpoint)) {
73+
return new GraphQLEndpoint(resolved)
74+
}
75+
return resolved
7276
} catch (e) {
7377
e.message = `${this.configPath}: ${e.message}`
7478
throw e
@@ -99,7 +103,7 @@ export class GraphQLEndpointsExtension {
99103
)
100104
}
101105

102-
if (!endpoint.url) {
106+
if (!endpoint.url && !(endpoint instanceof GraphQLEndpoint)) {
103107
throw new Error(
104108
`${this
105109
.configPath}: "url" is required but is not specified for "${endpointName}" endpoint`,

src/extensions/endpoints/resolveRefString.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export function resolveEnvsInValues<T extends any>(
1515
config: T,
1616
env: { [name: string]: string | undefined },
1717
): T {
18-
config = Object.assign({}, config)
1918
for (let key in config) {
2019
const value = config[key]
2120
if (typeof value === 'string') {

0 commit comments

Comments
 (0)