Skip to content

Commit ddbb23a

Browse files
committed
cleanup
1 parent 409a2fa commit ddbb23a

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

src/reader.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,16 @@ class VersionedTypedefNode<T> implements Iterable<[ValidFor, T]> {
237237
class VersionedTypedefMap<T extends TypeDefinitionNode> {
238238
readonly data = new Map<string, VersionedTypedefNode<T>>();
239239

240-
add(typeNode: T, override: boolean, allowSharing: boolean): boolean {
240+
constructor(readonly allowSharing: boolean) {}
241+
242+
add(typeNode: T, override: boolean, otherMap: VersionedTypedefMap<any>): boolean {
241243
const existingNode = this.data.get(typeNode.name.value);
244+
const nodeInOtherMap = otherMap.data.get(typeNode.name.value);
242245
if (!existingNode) {
243246
this.data.set(typeNode.name.value, new VersionedTypedefNode(
244247
!override ? typeNode : undefined,
245248
override ? typeNode : undefined,
246-
allowSharing
249+
nodeInOtherMap != null ? false : this.allowSharing
247250
));
248251
} else if (override) {
249252
if (existingNode.vOverride != null) return false;
@@ -252,6 +255,10 @@ class VersionedTypedefMap<T extends TypeDefinitionNode> {
252255
if (existingNode.vBase != null) return false;
253256
existingNode.vBase = typeNode;
254257
}
258+
259+
if (nodeInOtherMap) {
260+
nodeInOtherMap.allowSharing = false;
261+
}
255262
return true;
256263
}
257264
}
@@ -298,8 +305,8 @@ export function readSchemaSources(
298305
definitionOrderDelta: number;
299306
}
300307
): Pick<SchemaFile, 'tables' | 'enumerations'> {
301-
const typeDefsMap = new VersionedTypedefMap<ObjectTypeDefinitionNode>();
302-
const enumDefsMap = new VersionedTypedefMap<EnumTypeDefinitionNode>();
308+
const typeDefsMap = new VersionedTypedefMap<ObjectTypeDefinitionNode>(opts.allowSharingSchemas);
309+
const enumDefsMap = new VersionedTypedefMap<EnumTypeDefinitionNode>(opts.allowSharingSchemas);
303310

304311
for (const source of sources) {
305312
const doc = parse(source, { noLocation: false });
@@ -311,24 +318,14 @@ export function readSchemaSources(
311318

312319
const override = source.name.startsWith('poe2');
313320
if (typeNode.kind === 'EnumTypeDefinition') {
314-
const objectDefinition = typeDefsMap.data.get(typeNode.name.value);
315-
if(objectDefinition != undefined){
316-
objectDefinition.allowSharing = false;
317-
}
318-
let allowSharing = opts.allowSharingSchemas && objectDefinition == undefined;
319-
if (!enumDefsMap.add(typeNode, override, allowSharing)) {
321+
if (!enumDefsMap.add(typeNode, override, typeDefsMap)) {
320322
throw new GraphQLError(
321323
'Enum with this name has already been defined.',
322324
{ nodes: typeNode.name }
323325
);
324326
}
325327
} else if (typeNode.kind === 'ObjectTypeDefinition') {
326-
const enumDefinition = enumDefsMap.data.get(typeNode.name.value);
327-
if(enumDefinition != undefined){
328-
enumDefinition.allowSharing = false;
329-
}
330-
let allowSharing = opts.allowSharingSchemas && enumDefinition == undefined;
331-
if (!typeDefsMap.add(typeNode, override, allowSharing)) {
328+
if (!typeDefsMap.add(typeNode, override, enumDefsMap)) {
332329
throw new GraphQLError(
333330
'Table with this name has already been defined.',
334331
{ nodes: typeNode.name }

0 commit comments

Comments
 (0)