@@ -1276,6 +1276,87 @@ describe("codegenApolloMock", () => {
1276
1276
` ) ;
1277
1277
} ) ;
1278
1278
} ) ;
1279
+
1280
+ describe ( "with alias" , ( ) => {
1281
+ let document : DocumentNode ;
1282
+ let output : string ;
1283
+ let apolloMock : ApolloMockFn ;
1284
+
1285
+ beforeEach ( async ( ) => {
1286
+ document = parse ( `
1287
+ query authors {
1288
+ allAuthors: authors {
1289
+ idField
1290
+ }
1291
+ }
1292
+ ` ) ;
1293
+
1294
+ const documents = [ { document, location : "authors.gql" } ] ;
1295
+ const config = getConfig ( { documents } ) ;
1296
+
1297
+ output = await codegen ( config ) ;
1298
+ apolloMock = getApolloMock ( output ) ;
1299
+ } ) ;
1300
+
1301
+ it ( "should have matching operation" , ( ) => {
1302
+ expect ( output ) . toMatchInlineSnapshot ( `
1303
+ "import { createApolloMock } from 'apollo-typed-documents';
1304
+
1305
+ const operations = {};
1306
+
1307
+ export default createApolloMock(operations);
1308
+
1309
+ operations.authors = {};
1310
+ operations.authors.variables = (values = {}, options = {}) => {
1311
+ const __typename = '';
1312
+ values = (({ }) => ({ }))(values);
1313
+ values.__typename = __typename;
1314
+ return {
1315
+
1316
+ };
1317
+ };
1318
+ operations.authors.data = (values = {}, options = {}) => {
1319
+ const __typename = '';
1320
+ values = (({ allAuthors = null }) => ({ allAuthors }))(values);
1321
+ values.__typename = __typename;
1322
+ return {
1323
+ allAuthors: !values.allAuthors ? values.allAuthors : values.allAuthors.map(item => ((values = {}, options = {}) => {
1324
+ const __typename = 'Author';
1325
+ values = (({ idField = null }) => ({ idField }))(values);
1326
+ values.__typename = __typename;
1327
+ return {
1328
+ idField: (values.idField === null || values.idField === undefined) ? options.getDefaultScalarValue({ scalarTypeName: 'ID', mappedTypeName: 'string', fieldName: 'idField', __typename, scalarValues: options.scalarValues }) : values.idField,
1329
+ ...(options.addTypename ? { __typename } : {})
1330
+ };
1331
+ })(item, options))
1332
+ };
1333
+ };"
1334
+ ` ) ;
1335
+ } ) ;
1336
+
1337
+ it ( "should use alias for both input and output" , ( ) => {
1338
+ const result = apolloMock ( document , { } , { data : { allAuthors : [ { } ] } } ) ;
1339
+
1340
+ expect ( result ) . toMatchInlineSnapshot ( `
1341
+ {
1342
+ "request": {
1343
+ "query": "...",
1344
+ "variables": {}
1345
+ },
1346
+ "result": {
1347
+ "data": {
1348
+ "allAuthors": [
1349
+ {
1350
+ "idField": "Author-idField",
1351
+ "__typename": "Author"
1352
+ }
1353
+ ]
1354
+ }
1355
+ }
1356
+ }
1357
+ ` ) ;
1358
+ } ) ;
1359
+ } ) ;
1279
1360
} ) ;
1280
1361
1281
1362
describe ( "mutation" , ( ) => {
0 commit comments