Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize apollo-utilities graphql transformation functionality #4233

Merged
merged 28 commits into from
Dec 20, 2018
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e8482a2
chore(deps): update dependency @types/graphql to v14
renovate-bot Dec 12, 2018
060f409
Merge branch 'master' into renovate/graphql-14.x
hwillson Dec 12, 2018
d81f876
Set new selection during FieldNode creation
hwillson Dec 17, 2018
76ff754
Convert `GraphQLError[]` use to `ReadonlyArray<GraphQLError>`
hwillson Dec 17, 2018
61fa175
Add `es7` lib to the typescript config
hwillson Dec 17, 2018
5164134
Rewrite transformation utils that were writing into the graphql AST
hwillson Dec 17, 2018
c7083c5
Merge branch 'master' into hwillson/graphql-updates
hwillson Dec 17, 2018
30b7b31
Remove `includes` and tsconfig `es7` use
hwillson Dec 20, 2018
67efcaa
Pull `visit` in via a direct nested import
hwillson Dec 20, 2018
f4e064e
Code cleanup to address outstanding code review comments
hwillson Dec 20, 2018
23bd862
Merge branch 'master' into hwillson/graphql-updates
hwillson Dec 20, 2018
aea4d3d
Replace isNotEmpty helper with simpler isEmpty helper.
benjamn Dec 20, 2018
8ac5d2d
Use boolean expression in directiveMatcher.
benjamn Dec 20, 2018
7eae13d
Use boolean expression in getArgumentMatcher.
benjamn Dec 20, 2018
760297d
Reuse same enter function in removeFragmentSpreadFromDocument.
benjamn Dec 20, 2018
7d17240
Reduce array creation in getAllFragmentSpreadsFromSelectionSet.
benjamn Dec 20, 2018
2a6e7b7
Simplify hasArgumentsInSelection.
benjamn Dec 20, 2018
aad9e9a
Eliminate unused hasArgumentsInSelection[Set] helper functions.
benjamn Dec 20, 2018
af76400
Simplify hasDirectivesInSelection helper function.
benjamn Dec 20, 2018
3b51ad5
Inline filterSelectionSet into sole remaining call site.
benjamn Dec 20, 2018
94eab29
Reuse getDirectiveMatcher in removeDirectivesFromDocument.
benjamn Dec 20, 2018
9a67fcc
Avoid unnecessary node.arguments.filter in removeDirectivesFromDocument.
benjamn Dec 20, 2018
0b6bc76
Extract nullIfDocIsEmpty helper function.
benjamn Dec 20, 2018
f3b640f
Use filterInPlace helper in removeDirectivesFromDocument.
benjamn Dec 20, 2018
131acdd
Make checkDocument(doc) return doc.
benjamn Dec 20, 2018
d8ed6c0
Simplify addTypenameToDocument.
benjamn Dec 20, 2018
60a2ddf
Inline variableDefinitions filter expression.
benjamn Dec 20, 2018
2d3df6e
Changelog updates
hwillson Dec 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reuse same enter function in removeFragmentSpreadFromDocument.
  • Loading branch information
benjamn committed Dec 20, 2018
commit 760297d2c5c7aa4ec7480e7047c4d5eeb248a0b9
35 changes: 11 additions & 24 deletions packages/apollo-utilities/src/transform.ts
Original file line number Diff line number Diff line change
@@ -446,32 +446,19 @@ export function removeArgumentsFromDocument(
export function removeFragmentSpreadFromDocument(
config: RemoveFragmentSpreadConfig[],
doc: DocumentNode,
): DocumentNode | null {
const modifiedDoc = visit(doc, {
FragmentSpread: {
enter(node) {
const fragSpreadFound = config.some(
fragSpread => fragSpread.name === node.name.value,
);
if (fragSpreadFound) {
return null;
}
},
},
): DocumentNode {
function enter(
node: FragmentSpreadNode | FragmentDefinitionNode,
): null | void {
if (config.some(def => def.name === node.name.value)) {
return null;
}
}

FragmentDefinition: {
enter(node) {
const fragDefFound = config.some(
fragDef => fragDef.name && fragDef.name === node.name.value,
);
if (fragDefFound) {
return null;
}
},
},
return visit(doc, {
FragmentSpread: { enter },
FragmentDefinition: { enter },
});

return modifiedDoc;
}

function getAllFragmentSpreadsFromSelectionSet(