@@ -7,6 +7,7 @@ import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js';
77import { inspect } from '../../jsutils/inspect.js' ;
88import { promiseWithResolvers } from '../../jsutils/promiseWithResolvers.js' ;
99
10+ import type { FieldNode } from '../../language/ast.js' ;
1011import { Kind } from '../../language/kinds.js' ;
1112import { parse } from '../../language/parser.js' ;
1213
@@ -27,7 +28,9 @@ import {
2728} from '../../type/scalars.js' ;
2829import { GraphQLSchema } from '../../type/schema.js' ;
2930
30- import { execute , executeSync } from '../execute.js' ;
31+ import type { FieldDetailsList } from '../collectFields.js' ;
32+ import { execute , executeSync , validateExecutionArgs } from '../execute.js' ;
33+ import { collectSubfields } from '../Executor.js' ;
3134
3235describe ( 'Execute: Handles basic execution tasks' , ( ) => {
3336 it ( 'executes arbitrary code' , async ( ) => {
@@ -1412,4 +1415,53 @@ describe('Execute: Handles basic execution tasks', () => {
14121415 ] ,
14131416 } ) ;
14141417 } ) ;
1418+
1419+ it ( 'memoizes collectSubfields results' , ( ) => {
1420+ const deepType = new GraphQLObjectType ( {
1421+ name : 'DeepType' ,
1422+ fields : {
1423+ name : { type : GraphQLString } ,
1424+ } ,
1425+ } ) ;
1426+ const schema = new GraphQLSchema ( {
1427+ query : new GraphQLObjectType ( {
1428+ name : 'Query' ,
1429+ fields : {
1430+ deep : { type : deepType } ,
1431+ } ,
1432+ } ) ,
1433+ } ) ;
1434+ const document = parse ( '{ deep { name } }' ) ;
1435+ const validatedExecutionArgs = validateExecutionArgs ( {
1436+ schema,
1437+ document,
1438+ } ) ;
1439+
1440+ assert ( 'schema' in validatedExecutionArgs ) ;
1441+
1442+ const operation = validatedExecutionArgs . operation ;
1443+ const node = operation . selectionSet . selections [ 0 ] as FieldNode ;
1444+
1445+ const fieldDetailsList : FieldDetailsList = [ { node } ] ;
1446+
1447+ const first = collectSubfields (
1448+ validatedExecutionArgs ,
1449+ deepType ,
1450+ fieldDetailsList ,
1451+ ) ;
1452+
1453+ const second = collectSubfields (
1454+ validatedExecutionArgs ,
1455+ deepType ,
1456+ fieldDetailsList ,
1457+ ) ;
1458+
1459+ expect ( second ) . to . equal ( first ) ;
1460+
1461+ const third = collectSubfields ( validatedExecutionArgs , deepType , [
1462+ { node } ,
1463+ ] ) ;
1464+
1465+ expect ( third ) . to . not . equal ( first ) ;
1466+ } ) ;
14151467} ) ;
0 commit comments