Skip to content

Commit aee9e3d

Browse files
authored
Merge pull request #83 from graphcool/feature/customendpointclasses
feat(endpoints): only create GraphQLEndpoint if endpoint is not already GraphQLEndpoint
2 parents 3d8594c + 92a3ed9 commit aee9e3d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/extensions/endpoints/EndpointsExtension.ts

Lines changed: 11 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,15 @@ 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+
73+
// graphql-config extensions might have already instantiated a GraphQLEndpoint
74+
// or derived class from the GraphQLConfigEndpointConfig data. In that case,
75+
// getRawEndpoint will already return a GraphQLEndpoint and it should not be overwritten.
76+
if (!(resolved instanceof GraphQLEndpoint)) {
77+
return new GraphQLEndpoint(resolved)
78+
}
79+
return resolved
7280
} catch (e) {
7381
e.message = `${this.configPath}: ${e.message}`
7482
throw e
@@ -99,7 +107,7 @@ export class GraphQLEndpointsExtension {
99107
)
100108
}
101109

102-
if (!endpoint.url) {
110+
if (!endpoint.url && !(endpoint instanceof GraphQLEndpoint)) {
103111
throw new Error(
104112
`${this
105113
.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)