Mirror: The small sibling of the graphql package, slimmed down for client-side libraries.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

handle inserted nodes with 'enter' correctly (#7)

authored by

Jovi De Croock and committed by
GitHub
22c4ab15 e9906c7f

+43 -2
+42 -1
alias/language/__tests__/visitor.test.js
··· 1 1 // See: https://github.com/graphql/graphql-js/blob/976d64b/src/language/__tests__/visitor-test.ts 2 2 3 - import { Kind, parse } from 'graphql'; 3 + import { Kind, parse, print } from 'graphql'; 4 4 import { visit, visitInParallel, BREAK } from '../visitor'; 5 5 6 6 const kitchenSinkQuery = String.raw` ··· 475 475 ['enter', 'Name', 'c'], 476 476 ['leave', 'SelectionSet', undefined], 477 477 ]); 478 + }); 479 + 480 + it('handles deep immutable edits correctly when using "enter"', () => { 481 + const formatNode = (node) => { 482 + if ( 483 + node.selectionSet && 484 + !node.selectionSet.selections.some( 485 + (node) => 486 + node.kind === Kind.FIELD && 487 + node.name.value === '__typename' && 488 + !node.alias 489 + ) 490 + ) { 491 + return { 492 + ...node, 493 + selectionSet: { 494 + ...node.selectionSet, 495 + selections: [ 496 + ...node.selectionSet.selections, 497 + { 498 + kind: Kind.FIELD, 499 + name: { 500 + kind: Kind.NAME, 501 + value: '__typename', 502 + }, 503 + }, 504 + ], 505 + }, 506 + }; 507 + } 508 + }; 509 + const ast = parse('{ players { nodes { id } } }'); 510 + const expected = parse( 511 + '{ players { nodes { id __typename } __typename } }' 512 + ); 513 + const visited = visit(ast, { 514 + Field: formatNode, 515 + InlineFragment: formatNode, 516 + }); 517 + 518 + expect(print(visited)).toEqual(print(expected)); 478 519 }); 479 520 480 521 it('visits kitchen sink', () => {
+1 -1
alias/language/visitor.mjs
··· 72 72 if (resultLeave !== undefined) { 73 73 return resultLeave; 74 74 } else if (resultEnter !== undefined) { 75 - return resultEnter; 75 + return hasEdited ? copy : resultEnter; 76 76 } else { 77 77 return hasEdited ? copy : node; 78 78 }