Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions packages/quicktype-core/src/Type/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ function identityAttributes(attributes: TypeAttributes): TypeAttributes {
return mapFilter(attributes, (_, kind) => kind.inIdentity);
}

export function haveSameIdentityAttributes(a: Type, b: Type): boolean {
return areEqual(
identityAttributes(a.getAttributes()),
identityAttributes(b.getAttributes()),
);
}

export function primitiveTypeIdentity(
kind: PrimitiveTypeKind,
attributes: TypeAttributes,
Expand Down
11 changes: 9 additions & 2 deletions packages/quicktype-core/src/rewrites/CombineClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type ClassProperty,
ClassType,
type Type,
haveSameIdentityAttributes,
setOperationCasesEqual,
} from "../Type/Type.js";
import type { TypeGraph } from "../Type/TypeGraph.js";
Expand Down Expand Up @@ -110,14 +111,20 @@ function tryAddToClique(
onlyWithSameProperties: boolean,
): boolean {
for (const prototype of clique.prototypes) {
if (prototype.structurallyCompatible(c)) {
if (
haveSameIdentityAttributes(prototype, c) &&
prototype.structurallyCompatible(c)
) {
clique.members.push(c);
return true;
}
}

for (const prototype of clique.prototypes) {
if (canBeCombined(prototype, c, onlyWithSameProperties)) {
if (
haveSameIdentityAttributes(prototype, c) &&
canBeCombined(prototype, c, onlyWithSameProperties)
) {
clique.prototypes.push(c);
clique.members.push(c);
return true;
Expand Down
22 changes: 20 additions & 2 deletions packages/quicktype-graphql-input/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type Input,
type RunContext,
StringTypes,
TypeAttributeKind,
type TypeAttributes,
type TypeBuilder,
TypeNames,
Expand Down Expand Up @@ -77,6 +78,22 @@ function getField(t: GQLType, name: string): Field {
return panic(`Required field ${name} not defined on type ${t.name}.`);
}

class GraphQLTypeNameTypeAttributeKind extends TypeAttributeKind<string> {
public constructor() {
super("graphqlTypeName");
}

public get inIdentity(): boolean {
return true;
}

public combine(names: string[]): string {
return names[0];
}
}

const graphQLTypeNameTypeAttributeKind = new GraphQLTypeNameTypeAttributeKind();

function makeNames(
name: string,
fieldName: string | null,
Expand Down Expand Up @@ -422,10 +439,11 @@ class GQLQuery {
}
}

return builder.getClassType(
const attributes = new Map(
makeNames(nameOrOverride, containingFieldName, containingTypeName),
properties,
);
attributes.set(graphQLTypeNameTypeAttributeKind, gqlType.name);
return builder.getClassType(attributes, properties);
};

public makeType(
Expand Down
Loading
Loading