Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class VersionedTypedefNode<T> implements Iterable<[ValidFor, T]> {
constructor(
public vBase: T | undefined,
public vOverride: T | undefined,
readonly allowSharing: boolean
public allowSharing: boolean
) {}

*[Symbol.iterator](): Iterator<[ValidFor, T]> {
Expand All @@ -239,13 +239,14 @@ class VersionedTypedefMap<T extends TypeDefinitionNode> {

constructor(readonly allowSharing: boolean) {}

add(typeNode: T, override: boolean): boolean {
add(typeNode: T, override: boolean, otherMap: VersionedTypedefMap<any>): boolean {
const existingNode = this.data.get(typeNode.name.value);
const nodeInOtherMap = otherMap.data.get(typeNode.name.value);
if (!existingNode) {
this.data.set(typeNode.name.value, new VersionedTypedefNode(
!override ? typeNode : undefined,
override ? typeNode : undefined,
this.allowSharing
nodeInOtherMap != null ? false : this.allowSharing
));
} else if (override) {
if (existingNode.vOverride != null) return false;
Expand All @@ -254,6 +255,10 @@ class VersionedTypedefMap<T extends TypeDefinitionNode> {
if (existingNode.vBase != null) return false;
existingNode.vBase = typeNode;
}

if (nodeInOtherMap) {
nodeInOtherMap.allowSharing = false;
}
return true;
}
}
Expand Down Expand Up @@ -313,14 +318,14 @@ export function readSchemaSources(

const override = source.name.startsWith('poe2');
if (typeNode.kind === 'EnumTypeDefinition') {
if (!enumDefsMap.add(typeNode, override)) {
if (!enumDefsMap.add(typeNode, override, typeDefsMap)) {
throw new GraphQLError(
'Enum with this name has already been defined.',
{ nodes: typeNode.name }
);
}
} else if (typeNode.kind === 'ObjectTypeDefinition') {
if (!typeDefsMap.add(typeNode, override)) {
if (!typeDefsMap.add(typeNode, override, enumDefsMap)) {
throw new GraphQLError(
'Table with this name has already been defined.',
{ nodes: typeNode.name }
Expand Down