Skip to content

Commit

Permalink
Merge pull request #83 from graphcool/feature/customendpointclasses
Browse files Browse the repository at this point in the history
feat(endpoints): only create GraphQLEndpoint if endpoint is not already GraphQLEndpoint
  • Loading branch information
schickling authored Jan 29, 2018
2 parents 3d8594c + 92a3ed9 commit aee9e3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/extensions/endpoints/EndpointsExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type GraphQLConfigEnpointsMapData = {
}

export type GraphQLConfigEnpointsMap = {
[env: string]: GraphQLConfigEnpointConfig
[env: string]: GraphQLConfigEnpointConfig | GraphQLEndpoint
}

export type GraphQLConfigEnpointsData = GraphQLConfigEnpointsMapData
Expand Down Expand Up @@ -68,7 +68,15 @@ export class GraphQLEndpointsExtension {
): GraphQLEndpoint {
const endpoint = this.getRawEndpoint(endpointName)
try {
return new GraphQLEndpoint(resolveEnvsInValues(endpoint, env))
const resolved = resolveEnvsInValues(endpoint, env)

// graphql-config extensions might have already instantiated a GraphQLEndpoint
// or derived class from the GraphQLConfigEndpointConfig data. In that case,
// getRawEndpoint will already return a GraphQLEndpoint and it should not be overwritten.
if (!(resolved instanceof GraphQLEndpoint)) {
return new GraphQLEndpoint(resolved)
}
return resolved
} catch (e) {
e.message = `${this.configPath}: ${e.message}`
throw e
Expand Down Expand Up @@ -99,7 +107,7 @@ export class GraphQLEndpointsExtension {
)
}

if (!endpoint.url) {
if (!endpoint.url && !(endpoint instanceof GraphQLEndpoint)) {
throw new Error(
`${this
.configPath}: "url" is required but is not specified for "${endpointName}" endpoint`,
Expand Down
1 change: 0 additions & 1 deletion src/extensions/endpoints/resolveRefString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function resolveEnvsInValues<T extends any>(
config: T,
env: { [name: string]: string | undefined },
): T {
config = Object.assign({}, config)
for (let key in config) {
const value = config[key]
if (typeof value === 'string') {
Expand Down

0 comments on commit aee9e3d

Please sign in to comment.