@@ -96,7 +96,17 @@ describe('Introspection', () => {
9696 } ,
9797 {
9898 name : 'types' ,
99- args : [ ] ,
99+ args : [
100+ {
101+ name : 'includeDeprecated' ,
102+ type : {
103+ kind : 'SCALAR' ,
104+ name : 'Boolean' ,
105+ ofType : null ,
106+ } ,
107+ defaultValue : 'false' ,
108+ } ,
109+ ] ,
100110 type : {
101111 kind : 'NON_NULL' ,
102112 name : null ,
@@ -286,7 +296,17 @@ describe('Introspection', () => {
286296 } ,
287297 {
288298 name : 'possibleTypes' ,
289- args : [ ] ,
299+ args : [
300+ {
301+ name : 'includeDeprecated' ,
302+ type : {
303+ kind : 'SCALAR' ,
304+ name : 'Boolean' ,
305+ ofType : null ,
306+ } ,
307+ defaultValue : 'false' ,
308+ } ,
309+ ] ,
290310 type : {
291311 kind : 'LIST' ,
292312 name : null ,
@@ -372,6 +392,28 @@ describe('Introspection', () => {
372392 isDeprecated : false ,
373393 deprecationReason : null ,
374394 } ,
395+ {
396+ name : 'isDeprecated' ,
397+ args : [ ] ,
398+ type : {
399+ kind : 'SCALAR' ,
400+ name : 'Boolean' ,
401+ ofType : null ,
402+ } ,
403+ isDeprecated : false ,
404+ deprecationReason : null ,
405+ } ,
406+ {
407+ name : 'deprecationReason' ,
408+ args : [ ] ,
409+ type : {
410+ kind : 'SCALAR' ,
411+ name : 'String' ,
412+ ofType : null ,
413+ } ,
414+ isDeprecated : false ,
415+ deprecationReason : null ,
416+ } ,
375417 ] ,
376418 inputFields : null ,
377419 interfaces : [ ] ,
@@ -956,6 +998,7 @@ describe('Introspection', () => {
956998 'ARGUMENT_DEFINITION' ,
957999 'INPUT_FIELD_DEFINITION' ,
9581000 'ENUM_VALUE' ,
1001+ 'OBJECT' ,
9591002 ] ,
9601003 args : [
9611004 {
@@ -1231,6 +1274,153 @@ describe('Introspection', () => {
12311274 } ) ;
12321275 } ) ;
12331276
1277+ it ( 'identifies deprecated objects' , ( ) => {
1278+ const schema = buildSchema ( `
1279+ type Query {
1280+ dragon: [Dragon]
1281+ }
1282+ type Dragon @deprecated(reason: "No longer known to exist") {
1283+ name: String
1284+ }
1285+ ` ) ;
1286+
1287+ const source = `
1288+ {
1289+ __schema {
1290+ types(includeDeprecated: true) {
1291+ name
1292+ isDeprecated
1293+ deprecationReason
1294+ }
1295+ }
1296+ dragon: __type(name: "Dragon") {
1297+ name
1298+ isDeprecated
1299+ deprecationReason
1300+ }
1301+ }
1302+ ` ;
1303+
1304+ interface IntrospectionResponse {
1305+ __schema : {
1306+ types : [
1307+ { name : string ; isDeprecated : boolean ; deprecationReason : string } ,
1308+ ] ;
1309+ } ;
1310+ dragon : { name : string ; isDeprecated : boolean ; deprecationReason : string } ;
1311+ }
1312+
1313+ const resp = graphqlSync ( { schema, source } )
1314+ . data as unknown as IntrospectionResponse ;
1315+
1316+ expect ( resp . __schema . types ) . to . deep . include . members ( [
1317+ {
1318+ name : 'Dragon' ,
1319+ isDeprecated : true ,
1320+ deprecationReason : 'No longer known to exist' ,
1321+ } ,
1322+ ] ) ;
1323+ expect ( resp . dragon ) . to . deep . equal ( {
1324+ name : 'Dragon' ,
1325+ isDeprecated : true ,
1326+ deprecationReason : 'No longer known to exist' ,
1327+ } ) ;
1328+ } ) ;
1329+
1330+ it ( 'respects the includeDeprecated parameter for types' , ( ) => {
1331+ const schema = buildSchema ( `
1332+ type Query {
1333+ dragon: [Dragon]
1334+ }
1335+ type Dragon @deprecated(reason: "No longer known to exist") {
1336+ name: String
1337+ }
1338+ ` ) ;
1339+
1340+ const source = `
1341+ {
1342+ __schema {
1343+ trueTypes: types(includeDeprecated: true) {
1344+ name
1345+ }
1346+ falseTypes: types(includeDeprecated: false) {
1347+ name
1348+ }
1349+ omittedTypes: types {
1350+ name
1351+ }
1352+ }
1353+ }
1354+ ` ;
1355+
1356+ interface IntrospectionResponse {
1357+ __schema : {
1358+ trueTypes : [ { name : string } ] ;
1359+ falseTypes : [ { name : string } ] ;
1360+ omittedTypes : [ { name : string } ] ;
1361+ } ;
1362+ }
1363+
1364+ const response = graphqlSync ( { schema, source } )
1365+ . data as unknown as IntrospectionResponse ;
1366+ expect ( response . __schema . trueTypes ) . to . deep . include . members ( [
1367+ { name : 'Dragon' } ,
1368+ ] ) ;
1369+ expect ( response . __schema . falseTypes ) . to . not . deep . include . members ( [
1370+ { name : 'Dragon' } ,
1371+ ] ) ;
1372+ expect ( response . __schema . omittedTypes ) . to . not . deep . include . members ( [
1373+ { name : 'Dragon' } ,
1374+ ] ) ;
1375+ } ) ;
1376+
1377+ it ( 'respects the includeDeprecated parameter for possibleTypes' , ( ) => {
1378+ const schema = buildSchema ( `
1379+ type Query {
1380+ animals: [Animal]
1381+ }
1382+
1383+ interface Animal {
1384+ name: String
1385+ }
1386+
1387+ type Dog implements Animal {
1388+ name: String
1389+ }
1390+
1391+ type Dragon implements Animal @deprecated(reason: "No longer known to exist") {
1392+ name: String
1393+ }
1394+ ` ) ;
1395+
1396+ const source = `
1397+ {
1398+ animal: __type(name: "Animal") {
1399+ trueTypes: possibleTypes(includeDeprecated: true) {
1400+ name
1401+ }
1402+ falseTypes: possibleTypes(includeDeprecated: false) {
1403+ name
1404+ }
1405+ omittedTypes: possibleTypes {
1406+ name
1407+ }
1408+ }
1409+ }
1410+ ` ;
1411+
1412+ const result = graphqlSync ( { schema, source } ) ;
1413+ const animal = result . data ?. animal ;
1414+ // @ts -expect-error
1415+ expect ( animal . trueTypes ) . to . deep . include . members ( [ { name : 'Dragon' } ] ) ;
1416+ // @ts -expect-error
1417+ expect ( animal . falseTypes ) . to . not . deep . include . members ( [ { name : 'Dragon' } ] ) ;
1418+ // @ts -expect-error
1419+ expect ( animal . omittedTypes ) . to . not . deep . include . members ( [
1420+ { name : 'Dragon' } ,
1421+ ] ) ;
1422+ } ) ;
1423+
12341424 it ( 'identifies deprecated args' , ( ) => {
12351425 const schema = buildSchema ( `
12361426 type Query {
0 commit comments