Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

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

Golf code size of collectTypesFromResponse

+7 -6
+7 -6
packages/core/src/utils/typenames.ts
··· 12 12 __typename: string | null | void; 13 13 } 14 14 15 - const collectTypes = (obj: EntityLike | EntityLike[], types: string[] = []) => { 15 + const collectTypes = ( 16 + obj: EntityLike | EntityLike[], 17 + types: { [typename: string]: unknown } 18 + ) => { 16 19 if (Array.isArray(obj)) { 17 - obj.forEach(inner => { 18 - collectTypes(inner, types); 19 - }); 20 + for (let i = 0; i < obj.length; i++) collectTypes(obj[i], types); 20 21 } else if (typeof obj === 'object' && obj !== null) { 21 22 for (const key in obj) { 22 23 if (key === '__typename' && typeof obj[key] === 'string') { 23 - types.push(obj[key] as string); 24 + types[obj[key] as string] = 0; 24 25 } else { 25 26 collectTypes(obj[key], types); 26 27 } ··· 31 32 }; 32 33 33 34 export const collectTypesFromResponse = (response: object) => 34 - collectTypes(response as EntityLike).filter((v, i, a) => a.indexOf(v) === i); 35 + Object.keys(collectTypes(response as EntityLike, {})); 35 36 36 37 const formatNode = (node: FieldNode | InlineFragmentNode) => { 37 38 if (