Skip to content

Commit

Permalink
fix(fragment): fix filter function logic for PR #94 and issue #90
Browse files Browse the repository at this point in the history
  • Loading branch information
evenchange4 committed May 21, 2019
1 parent 3e11be6 commit c085590
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/__snapshots__/macro.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const query = {
}
}]
}
}].concat(frag1.definitions, frag2.definitions).reduce((acc, definition) => definition.kind !== "FragmentDefinition" || acc.find(curDef => curDef.name.value === definition.name.value) ? acc : acc.concat(definition), []),
}].concat(frag1.definitions, frag2.definitions).reduce((acc, definition) => definition.kind === 'FragmentDefinition' && acc.find(curDef => curDef.kind === 'FragmentDefinition' && curDef.name.value === definition.name.value) ? acc : acc.concat(definition), []),
"loc": {
"start": 0,
"end": 39,
Expand Down Expand Up @@ -262,7 +262,7 @@ const query = {
}
}]
}
}].concat(userFragment.definitions).reduce((acc, definition) => definition.kind !== "FragmentDefinition" || acc.find(curDef => curDef.name.value === definition.name.value) ? acc : acc.concat(definition), []),
}].concat(userFragment.definitions).reduce((acc, definition) => definition.kind === 'FragmentDefinition' && acc.find(curDef => curDef.kind === 'FragmentDefinition' && curDef.name.value === definition.name.value) ? acc : acc.concat(definition), []),
"loc": {
"start": 0,
"end": 82,
Expand Down
9 changes: 7 additions & 2 deletions src/utils/compileWithFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import serialize from 'babel-literal-to-ast';
import template from '@babel/template';

/**
* TODO: Reduce runtime to improve performance
* ref: https://github.com/gajus/babel-plugin-graphql-tag/blob/35edbae44990bf20be2de7139dc0ce5843f70bff/src/index.js#L25
*/
const uniqueFn = template.ast(`
(acc, definition) =>
definition.kind !== "FragmentDefinition" ||
acc.find(curDef => curDef.name.value === definition.name.value)
definition.kind === 'FragmentDefinition' &&
acc.find(
curDef =>
curDef.kind === 'FragmentDefinition' &&
curDef.name.value === definition.name.value,
)
? acc
: acc.concat(definition)
`);
Expand Down

0 comments on commit c085590

Please sign in to comment.