Skip to content

Commit 7afeac8

Browse files
committed
fix invalid type of __typename and __isAbstractType
1 parent d1e43aa commit 7afeac8

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/schema-scanner.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ describe('getTypeInfos', () => {
417417
}
418418
`);
419419
});
420-
// FIXME
421420
it('does not effect to __typename and __is<AbstractType>', () => {
422421
const schema = buildSchema(`
423422
type Type {
@@ -434,11 +433,11 @@ describe('getTypeInfos', () => {
434433
[
435434
{
436435
"name": "__typename",
437-
"typeString": "'type'",
436+
"typeString": "'Type'",
438437
},
439438
{
440439
"name": "__isUnion",
441-
"typeString": "'type'",
440+
"typeString": "'Type'",
442441
},
443442
{
444443
"comment": undefined,
@@ -480,7 +479,6 @@ describe('getTypeInfos', () => {
480479
}
481480
`);
482481
});
483-
// FIXME
484482
it('does not effect to __typename and __is<AbstractType>', () => {
485483
const schema = buildSchema(`
486484
type Type {
@@ -497,11 +495,11 @@ describe('getTypeInfos', () => {
497495
[
498496
{
499497
"name": "__typename",
500-
"typeString": "'IType'",
498+
"typeString": "'Type'",
501499
},
502500
{
503501
"name": "__isUnion",
504-
"typeString": "'IType'",
502+
"typeString": "'Type'",
505503
},
506504
{
507505
"comment": undefined,
@@ -543,7 +541,6 @@ describe('getTypeInfos', () => {
543541
}
544542
`);
545543
});
546-
// FIXME
547544
it('does not effect to __typename and __is<AbstractType>', () => {
548545
const schema = buildSchema(`
549546
type Type {
@@ -560,11 +557,11 @@ describe('getTypeInfos', () => {
560557
[
561558
{
562559
"name": "__typename",
563-
"typeString": "'TypeI'",
560+
"typeString": "'Type'",
564561
},
565562
{
566563
"name": "__isUnion",
567-
"typeString": "'TypeI'",
564+
"typeString": "'Type'",
568565
},
569566
{
570567
"comment": undefined,

src/schema-scanner.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ function parseTypeNode(node: TypeNode, config: Config): string {
5151

5252
function parseFieldOrInputValueDefinition(
5353
node: FieldDefinitionNode | InputValueDefinitionNode,
54-
objectTypeName: string,
54+
convertedTypeName: string,
5555
config: Config,
5656
userDefinedTypeNames: string[],
5757
): { typeString: string; comment: string | undefined } {
5858
const comment = node.description ? transformComment(node.description) : undefined;
5959
if (isTypeBasedOnUserDefinedType(node.type, userDefinedTypeNames)) {
6060
return { typeString: `${parseTypeNode(node.type, config)} | undefined`, comment };
6161
} else {
62-
return { typeString: `${objectTypeName}['${node.name.value}'] | undefined`, comment };
62+
return { typeString: `${convertedTypeName}['${node.name.value}'] | undefined`, comment };
6363
}
6464
}
6565

@@ -69,19 +69,20 @@ function parseObjectTypeOrInputObjectTypeDefinition(
6969
userDefinedTypeNames: string[],
7070
getAbstractTypeNames: (type: ObjectTypeDefinitionNode) => string[],
7171
): TypeInfo {
72-
const objectTypeName = convertName(node.name.value, config);
72+
const originalTypeName = node.name.value;
73+
const convertedTypeName = convertName(originalTypeName, config);
7374
const comment = node.description ? transformComment(node.description) : undefined;
7475
const abstractTypeNames = node.kind === Kind.OBJECT_TYPE_DEFINITION ? getAbstractTypeNames(node) : [];
7576
return {
76-
name: objectTypeName,
77+
name: convertedTypeName,
7778
fields: [
78-
...(!config.skipTypename ? [{ name: '__typename', typeString: `'${objectTypeName}'` }] : []),
79+
...(!config.skipTypename ? [{ name: '__typename', typeString: `'${originalTypeName}'` }] : []),
7980
...(!config.skipIsAbstractType
80-
? abstractTypeNames.map((name) => ({ name: `__is${name}`, typeString: `'${objectTypeName}'` }))
81+
? abstractTypeNames.map((name) => ({ name: `__is${name}`, typeString: `'${originalTypeName}'` }))
8182
: []),
8283
...(node.fields ?? []).map((field) => ({
8384
name: field.name.value,
84-
...parseFieldOrInputValueDefinition(field, objectTypeName, config, userDefinedTypeNames),
85+
...parseFieldOrInputValueDefinition(field, convertedTypeName, config, userDefinedTypeNames),
8586
})),
8687
],
8788
comment,

0 commit comments

Comments
 (0)