Skip to content

Commit

Permalink
add astNode correct to enum types
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Jul 14, 2020
1 parent 9983fda commit 2728b8c
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/utils/src/mapSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
InputValueDefinitionNode,
FieldDefinitionNode,
Kind,
EnumValueDefinitionNode,
} from 'graphql';

import {
Expand Down Expand Up @@ -155,10 +156,12 @@ function mapEnumValues(originalTypeMap: TypeMap, schema: GraphQLSchema, schemaMa
newEnumValueConfigMap[externalValue] = mappedEnumValue;
}
});
return new GraphQLEnumType({
...config,
values: newEnumValueConfigMap,
});
return correctASTNodes(
new GraphQLEnumType({
...config,
values: newEnumValueConfigMap,
})
);
},
},
type => isEnumType(type)
Expand Down Expand Up @@ -571,6 +574,29 @@ export function correctASTNodes(type: GraphQLNamedType): GraphQLNamedType {
}

return new GraphQLInputObjectType(config);
} else if (isEnumType(type)) {
const config = (type as GraphQLEnumType).toConfig();
if (config.astNode != null) {
const values: Array<EnumValueDefinitionNode> = [];
Object.values(config.values).forEach(enumValueConfig => {
if (enumValueConfig.astNode != null) {
values.push(enumValueConfig.astNode);
}
});
config.astNode = {
...config.astNode,
values,
};
}

if (config.extensionASTNodes != null) {
config.extensionASTNodes = config.extensionASTNodes.map(node => ({
...node,
values: undefined,
}));
}

return new GraphQLEnumType(config);
} else {
return type;
}
Expand Down

0 comments on commit 2728b8c

Please sign in to comment.