@@ -16,6 +16,7 @@ import * as util from './util.js';
1616class IdField {
1717 static BYTES = Symbol ( 'Bytes' ) ;
1818 static STRING = Symbol ( 'String' ) ;
19+ static INT8 = Symbol ( 'Int8' ) ;
1920
2021 private kind : typeof IdField . BYTES | typeof IdField . STRING ;
2122
@@ -27,35 +28,99 @@ class IdField {
2728 throw Error ( 'id field must be a named type' ) ;
2829 }
2930 const typeName = idField . type . type . name . value ;
30- this . kind = typeName === 'Bytes' ? IdField . BYTES : IdField . STRING ;
31+ switch ( typeName ) {
32+ case 'Bytes' :
33+ this . kind = IdField . BYTES ;
34+ break ;
35+ case 'Int8' :
36+ this . kind = IdField . INT8 ;
37+ break ;
38+ default :
39+ this . kind = IdField . STRING ;
40+ break ;
41+ }
3142 }
3243
3344 typeName ( ) {
34- return this . kind === IdField . BYTES ? 'Bytes' : 'string' ;
45+ switch ( this . kind ) {
46+ case IdField . BYTES :
47+ return 'Bytes' ;
48+ case IdField . INT8 :
49+ return 'Int8' ;
50+ case IdField . STRING :
51+ return 'string' ;
52+ default :
53+ return 'string' ;
54+ }
3555 }
3656
3757 gqlTypeName ( ) {
38- return this . kind === IdField . BYTES ? 'Bytes' : 'String' ;
58+ switch ( this . kind ) {
59+ case IdField . BYTES :
60+ return 'Bytes' ;
61+ case IdField . INT8 :
62+ return 'Int8' ;
63+ case IdField . STRING :
64+ return 'String' ;
65+ default :
66+ return 'String' ;
67+ }
3968 }
4069
4170 tsNamedType ( ) {
4271 return tsCodegen . namedType ( this . typeName ( ) ) ;
4372 }
4473
4574 tsValueFrom ( ) {
46- return this . kind === IdField . BYTES ? 'Value.fromBytes(id)' : 'Value.fromString(id)' ;
75+ switch ( this . kind ) {
76+ case IdField . BYTES :
77+ return 'Value.fromBytes(id)' ;
78+ case IdField . INT8 :
79+ return 'Value.fromI64(id)' ;
80+ case IdField . STRING :
81+ return 'Value.fromString(id)' ;
82+ default :
83+ return 'Value.fromString(id)' ;
84+ }
4785 }
4886
4987 tsValueKind ( ) {
50- return this . kind === IdField . BYTES ? 'ValueKind.BYTES' : 'ValueKind.STRING' ;
88+ switch ( this . kind ) {
89+ case IdField . BYTES :
90+ return 'ValueKind.BYTES' ;
91+ case IdField . INT8 :
92+ return 'ValueKind.INT8' ;
93+ case IdField . STRING :
94+ return 'ValueKind.STRING' ;
95+ default :
96+ return 'ValueKind.STRING' ;
97+ }
5198 }
5299
53100 tsValueToString ( ) {
54- return this . kind == IdField . BYTES ? 'id.toBytes().toHexString()' : 'id.toString()' ;
101+ switch ( this . kind ) {
102+ case IdField . BYTES :
103+ return 'id.toBytes().toHexString()' ;
104+ case IdField . INT8 :
105+ return 'id.toI64().toString()' ;
106+ case IdField . STRING :
107+ return 'id.toString()' ;
108+ default :
109+ return 'id.toString()' ;
110+ }
55111 }
56112
57113 tsToString ( ) {
58- return this . kind == IdField . BYTES ? 'id.toHexString()' : 'id' ;
114+ switch ( this . kind ) {
115+ case IdField . BYTES :
116+ return 'id.toHexString()' ;
117+ case IdField . INT8 :
118+ return 'id.toString()' ;
119+ case IdField . STRING :
120+ return 'id' ;
121+ default :
122+ return 'id' ;
123+ }
59124 }
60125
61126 static fromFields ( fields : readonly FieldDefinitionNode [ ] | undefined ) {
0 commit comments