Skip to content

Commit c567aed

Browse files
committed
add --no-schema-sharing flag
1 parent 6e5e7a7 commit c567aed

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/cli.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import {
1414
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1515

1616
const WATCH_MODE = process.argv.includes('--watch');
17+
const ALLOW_SHARING_SCHEMAS = !process.argv.includes('--no-schema-sharing');
1718

1819
const SCHEMA_PATH =
1920
process.argv
2021
.slice(2)
21-
.filter((arg) => arg !== '--watch')
22+
.filter((arg) => arg !== '--watch' && arg !== '--no-schema-sharing')
2223
.at(0) || path.join(__dirname, '../dat-schema');
2324

2425
function read() {
@@ -32,7 +33,7 @@ function read() {
3233
});
3334

3435
try {
35-
return readSchemaSources(sources);
36+
return readSchemaSources(sources, ALLOW_SHARING_SCHEMAS);
3637
} catch (e) {
3738
if (e instanceof GraphQLError) {
3839
console.error(e.toString());

src/reader.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ const DIRECTIVE_INTERVAL = {
212212

213213
class VersionedTypedefNode<T> implements Iterable<[ValidFor, T]> {
214214
constructor (
215-
public vBase?: T,
216-
public vOverride?: T,
215+
public vBase: T | undefined,
216+
public vOverride: T | undefined,
217+
readonly allowSharing: boolean
217218
) {}
218219

219220
*[Symbol.iterator](): Iterator<[ValidFor, T]> {
@@ -223,20 +224,29 @@ class VersionedTypedefNode<T> implements Iterable<[ValidFor, T]> {
223224
} else if (this.vOverride != null) {
224225
yield [ValidFor.PoE2, this.vOverride];
225226
} else if (this.vBase != null) {
226-
yield [ValidFor.Common, this.vBase];
227+
if (this.allowSharing) {
228+
yield [ValidFor.Common, this.vBase];
229+
} else {
230+
yield [ValidFor.PoE1, this.vBase];
231+
}
227232
}
228233
}
229234
}
230235

231236
class VersionedTypedefMap<T extends TypeDefinitionNode> {
232237
readonly data = new Map<string, VersionedTypedefNode<T>>();
233238

239+
constructor (
240+
readonly allowSharing: boolean
241+
) {}
242+
234243
add(typeNode: T, override: boolean): boolean {
235244
const existingNode = this.data.get(typeNode.name.value);
236245
if (!existingNode) {
237246
this.data.set(typeNode.name.value, new VersionedTypedefNode(
238247
!override ? typeNode : undefined,
239248
override ? typeNode : undefined,
249+
this.allowSharing
240250
));
241251
} else if (override) {
242252
if (existingNode.vOverride != null) return false;
@@ -265,7 +275,11 @@ class ScopedTypedefMap<T> {
265275
if (this.ver === ValidFor.PoE1) {
266276
return node.vBase;
267277
} else {
268-
return node.vOverride ?? node.vBase;
278+
if (node.allowSharing) {
279+
return node.vOverride ?? node.vBase;
280+
} else {
281+
return node.vOverride;
282+
}
269283
}
270284
}
271285
}
@@ -281,10 +295,11 @@ interface Context {
281295
}
282296

283297
export function readSchemaSources(
284-
sources: readonly Source[]
298+
sources: readonly Source[],
299+
allowSharingSchemas: boolean
285300
): Pick<SchemaFile, 'tables' | 'enumerations'> {
286-
const typeDefsMap = new VersionedTypedefMap<ObjectTypeDefinitionNode>();
287-
const enumDefsMap = new VersionedTypedefMap<EnumTypeDefinitionNode>();
301+
const typeDefsMap = new VersionedTypedefMap<ObjectTypeDefinitionNode>(allowSharingSchemas);
302+
const enumDefsMap = new VersionedTypedefMap<EnumTypeDefinitionNode>(allowSharingSchemas);
288303

289304
for (const source of sources) {
290305
const doc = parse(source, { noLocation: false });

0 commit comments

Comments
 (0)