Skip to content

Commit

Permalink
Remove location data from loaded documents to reduce document size (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jun 23, 2020
1 parent 163f714 commit 7566aaf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
4 changes: 3 additions & 1 deletion packages/import/src/index.ts
Expand Up @@ -102,7 +102,9 @@ function visitFile(
const fileDefinitionMap = new Map<string, Set<DefinitionNode>>();
// To prevent circular dependency
visitedFiles.set(filePath, fileDefinitionMap);
const document = parse(new Source(otherLines, filePath));
const document = parse(new Source(otherLines, filePath), {
noLocation: true,
});
for (const definition of document.definitions) {
if ('name' in definition || definition.kind === Kind.SCHEMA_DEFINITION) {
const definitionName = 'name' in definition ? definition.name.value : 'schema';
Expand Down
4 changes: 4 additions & 0 deletions packages/relay-operation-optimizer/src/index.ts
Expand Up @@ -20,6 +20,10 @@ export function optimizeDocuments(
documents: DocumentNode[],
options: OptimizeDocumentsOptions = {}
) {
options = {
noLocation: true,
...options,
};
// @TODO way for users to define directives they use, otherwise relay will throw an unknown directive error
// Maybe we can scan the queries and add them dynamically without users having to do some extra stuff
// transformASTSchema creates a new schema instance instead of mutating the old one
Expand Down
6 changes: 5 additions & 1 deletion packages/webpack-loader/package.json
Expand Up @@ -20,10 +20,14 @@
"dependencies": {
"@graphql-tools/load": "6.0.10",
"@graphql-tools/graphql-file-loader": "6.0.10",
"loader-utils": "2.0.0",
"tslib": "~2.0.0"
},
"devDependencies": {
"@types/loader-utils": "1.1.3"
},
"publishConfig": {
"access": "public",
"directory": "dist"
}
}
}
7 changes: 6 additions & 1 deletion packages/webpack-loader/src/index.ts
@@ -1,17 +1,22 @@
import { loadTypedefs } from '@graphql-tools/load';
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { concatAST } from 'graphql';
import { getOptions } from 'loader-utils';

export default function (this: any, path: string) {
const callback = this.async();

this.cacheable();

const options = getOptions(this);

loadTypedefs(path, {
loaders: [new GraphQLFileLoader()],
noLocation: true,
...options,
}).then(sources => {
const documents = sources.map(source => source.document);
const mergedDoc = concatAST(documents);
return callback(null, `module.exports = ${JSON.stringify(mergedDoc)}`);
return callback(null, `export default ${JSON.stringify(mergedDoc)}`);
});
}
38 changes: 29 additions & 9 deletions yarn.lock
Expand Up @@ -2056,6 +2056,14 @@
"@types/koa-compose" "*"
"@types/node" "*"

"@types/loader-utils@1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@types/loader-utils/-/loader-utils-1.1.3.tgz#82b9163f2ead596c68a8c03e450fbd6e089df401"
integrity sha512-euKGFr2oCB3ASBwG39CYJMR3N9T0nanVqXdiH7Zu/Nqddt6SmFRxytq/i2w9LQYNQekEtGBz+pE3qG6fQTNvRg==
dependencies:
"@types/node" "*"
"@types/webpack" "*"

"@types/lodash@4.14.156":
version "4.14.156"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.156.tgz#cbe30909c89a1feeb7c60803e785344ea0ec82d1"
Expand Down Expand Up @@ -2209,6 +2217,18 @@
"@types/source-list-map" "*"
source-map "^0.6.1"

"@types/webpack@*":
version "4.41.17"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.17.tgz#0a69005e644d657c85b7d6ec1c826a71bebd1c93"
integrity sha512-6FfeCidTSHozwKI67gIVQQ5Mp0g4X96c2IXxX75hYEQJwST/i6NyZexP//zzMOBb+wG9jJ7oO8fk9yObP2HWAw==
dependencies:
"@types/anymatch" "*"
"@types/node" "*"
"@types/tapable" "*"
"@types/uglify-js" "*"
"@types/webpack-sources" "*"
source-map "^0.6.0"

"@types/webpack@^4.41.0", "@types/webpack@^4.41.8":
version "4.41.13"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.13.tgz#988d114c8913d039b8a0e0502a7fe4f1f84f3d5e"
Expand Down Expand Up @@ -8241,6 +8261,15 @@ loader-utils@1.2.3:
emojis-list "^2.0.0"
json5 "^1.0.1"

loader-utils@2.0.0, loader-utils@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.0.tgz#e4cace5b816d425a166b5f097e10cd12b36064b0"
integrity sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==
dependencies:
big.js "^5.2.2"
emojis-list "^3.0.0"
json5 "^2.1.2"

loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.0.tgz#c579b5e34cb34b1a74edc6c1fb36bfa371d5a613"
Expand All @@ -8250,15 +8279,6 @@ loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4.0:
emojis-list "^3.0.0"
json5 "^1.0.1"

loader-utils@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.0.tgz#e4cace5b816d425a166b5f097e10cd12b36064b0"
integrity sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==
dependencies:
big.js "^5.2.2"
emojis-list "^3.0.0"
json5 "^2.1.2"

locate-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
Expand Down

0 comments on commit 7566aaf

Please sign in to comment.