Skip to content

Commit

Permalink
fix(graphql-modules-preset): do not parse SDL and use extendedSources… (
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan authored Aug 3, 2021
1 parent c1c5b5a commit edd029e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .changeset/fuzzy-sheep-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-codegen/cli': patch
'@graphql-codegen/graphql-modules-preset': patch
---

fix(graphql-modules-preset): do not parse SDL and use extendedSources that have parsed document already
4 changes: 2 additions & 2 deletions packages/graphql-codegen-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@graphql-tools/github-loader": "^7.0.1",
"@graphql-tools/graphql-file-loader": "^7.0.1",
"@graphql-tools/json-file-loader": "^7.0.1",
"@graphql-tools/load": "^7.0.1",
"@graphql-tools/load": "^7.1.0",
"@graphql-tools/prisma-loader": "^7.0.1",
"@graphql-tools/url-loader": "^7.0.3",
"@graphql-tools/utils": "^8.0.1",
Expand All @@ -63,7 +63,7 @@
"detect-indent": "^6.0.0",
"glob": "^7.1.6",
"globby": "^11.0.4",
"graphql-config": "^4.0.0",
"graphql-config": "^4.0.1",
"inquirer": "^7.3.3",
"is-glob": "^4.0.1",
"json-to-pretty-yaml": "^1.2.2",
Expand Down
1 change: 1 addition & 0 deletions packages/presets/graphql-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dependencies": {
"@graphql-codegen/plugin-helpers": "^2.0.0",
"@graphql-codegen/visitor-plugin-common": "2.0.0",
"@graphql-tools/utils": "8.0.1",
"parse-filepath": "^1.0.2",
"change-case-all": "1.0.14",
"tslib": "~2.3.0"
Expand Down
12 changes: 3 additions & 9 deletions packages/presets/graphql-modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Types } from '@graphql-codegen/plugin-helpers';
import { concatAST, isScalarType, parse } from 'graphql';
import { concatAST, isScalarType } from 'graphql';
import { resolve, relative, join } from 'path';
import { groupSourcesByModule, stripFilename, normalize, isGraphQLPrimitive } from './utils';
import { buildModule } from './builder';
Expand All @@ -24,7 +24,7 @@ export const preset: Types.OutputPreset<ModulesConfig> = {
throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
}

const sourcesByModuleMap = groupSourcesByModule(options.schemaAst!.extensions.sources, baseOutputDir);
const sourcesByModuleMap = groupSourcesByModule(options.schemaAst!.extensions.extendedSources, baseOutputDir);
const modules = Object.keys(sourcesByModuleMap);

const baseVisitor = new BaseVisitor(options.config, {});
Expand Down Expand Up @@ -78,13 +78,7 @@ export const preset: Types.OutputPreset<ModulesConfig> = {
const importPath = options.presetConfig.importBaseTypesFrom || normalize(join(relativePath, baseTypesFilename));
const sources = sourcesByModuleMap[moduleName];

const moduleDocument = concatAST(
sources.map(source =>
parse(source.body, {
noLocation: true,
})
)
);
const moduleDocument = concatAST(sources.map(source => source.document));

const shouldDeclare = filename.endsWith('.d.ts');

Expand Down
6 changes: 3 additions & 3 deletions packages/presets/graphql-modules/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
InputValueDefinitionNode,
Kind,
NamedTypeNode,
Source,
TypeNode,
} from 'graphql';
import { Source } from '@graphql-tools/utils';
import parse from 'parse-filepath';

const sep = '/';
Expand Down Expand Up @@ -146,11 +146,11 @@ export function groupSourcesByModule(sources: Source[], basePath: string): Recor
const grouped: Record<string, Source[]> = {};

sources.forEach(source => {
const relativePath = getRelativePath(source.name, basePath);
const relativePath = getRelativePath(source.location, basePath);

if (relativePath) {
// PERF: we could guess the module by matching source.location with a list of already resolved paths
const mod = extractModuleDirectory(source.name, basePath);
const mod = extractModuleDirectory(source.location, basePath);

if (!grouped[mod]) {
grouped[mod] = [];
Expand Down
52 changes: 26 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@
cross-fetch "3.1.4"
tslib "~2.3.0"

"@graphql-tools/graphql-file-loader@^7.0.0", "@graphql-tools/graphql-file-loader@^7.0.1":
"@graphql-tools/graphql-file-loader@^7.0.1":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@graphql-tools/graphql-file-loader/-/graphql-file-loader-7.0.1.tgz#fc14da0c4c775c81b834cb7fcd50733fe1e10838"
integrity sha512-gSYh+W86GcR/TP8bLCPuNdAUeV1/y3+0czM32r6VxqZNiJjiSF6k68rb4F7M6jJ/1dA/SAEZpXLd94Dokc2s/g==
Expand Down Expand Up @@ -2042,7 +2042,7 @@
resolve-from "5.0.0"
tslib "~2.2.0"

"@graphql-tools/json-file-loader@^7.0.0", "@graphql-tools/json-file-loader@^7.0.1":
"@graphql-tools/json-file-loader@^7.0.1":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@graphql-tools/json-file-loader/-/json-file-loader-7.0.1.tgz#cdac2e967eb190154e55325535399ed651b0f1e6"
integrity sha512-UfZ3vA37d0OG28p8GijyIo5zRMXozz9f1TBcb++k0cQKmElILrnBHD4ZiNkWTFz5VBSKSjk4gpJD89D8BKKDyg==
Expand All @@ -2065,18 +2065,18 @@
unixify "1.0.0"
valid-url "1.0.9"

"@graphql-tools/load@^7.0.0", "@graphql-tools/load@^7.0.1":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@graphql-tools/load/-/load-7.0.1.tgz#39b1a0ebfb762cb41448ec50db0349407fe82d27"
integrity sha512-TiHgGRWhHHRdhWyVlZrF9PT6NqGG0NRL0XLY6IYWzinNMuPAOyYcp6zwtPxgDbfeRQMO41/4QTIkR6mCLHrcRQ==
"@graphql-tools/load@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@graphql-tools/load/-/load-7.1.0.tgz#dc561684faff70a7d4e98257f3886e6817a4589e"
integrity sha512-THh07BQ6Fmv9wCUIONWXFgkBe/3H9jB67aV7FJ+t+snACYvPhB7kDX8D6VC6RjCfcoaI1MNyHIgNR5JZ5GJ1ng==
dependencies:
"@graphql-tools/merge" "^6.2.16"
"@graphql-tools/utils" "8.0.1"
import-from "4.0.0"
p-limit "3.1.0"
tslib "~2.3.0"

"@graphql-tools/[email protected]", "@graphql-tools/merge@^6.2.15", "@graphql-tools/merge@^6.2.16", "@graphql-tools/merge@^6.2.4":
"@graphql-tools/[email protected]", "@graphql-tools/merge@^6.2.16", "@graphql-tools/merge@^6.2.4":
version "6.2.16"
resolved "https://registry.yarnpkg.com/@graphql-tools/merge/-/merge-6.2.16.tgz#5dd5f582075c21ef4d74ef84dfcc4e8d0c2db186"
integrity sha512-KjZ1pppzKcr2Uspgb53p8uw5yhWVuGIL+sEroar7vLsClSsuiGib8OKVICAGWjC9wrCxGaL9SjJGavfXpJMQIg==
Expand Down Expand Up @@ -2157,7 +2157,7 @@
tslib "~2.2.0"
value-or-promise "1.0.6"

"@graphql-tools/url-loader@^7.0.2", "@graphql-tools/url-loader@^7.0.3":
"@graphql-tools/url-loader@^7.0.3":
version "7.0.3"
resolved "https://registry.yarnpkg.com/@graphql-tools/url-loader/-/url-loader-7.0.3.tgz#3f1ea7a0987af8cf84e6a2c0e4670380f5690fa9"
integrity sha512-9QhYaA6nCAleFSw5WvNgwy/ixkcJTrMfFAP3Ofsgk9Cau0iUesrgRYEYNJldf0NevP7wHzaVuWqRP/xHLqW2iw==
Expand Down Expand Up @@ -3207,7 +3207,12 @@
dependencies:
"@types/node" "*"

"@types/node@*", "@types/[email protected]", "@types/node@^14.14.33":
"@types/node@*", "@types/node@^15.0.1":
version "15.6.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.6.0.tgz#f0ddca5a61e52627c9dcb771a6039d44694597bc"
integrity sha512-gCYSfQpy+LYhOFTKAeE8BkyGqaxmlFxe+n4DKM6DR0wzw/HISUE/hAmkC/KT8Sw5PCJblqg062b3z9gucv3k0A==

"@types/[email protected]", "@types/node@^14.14.33":
version "14.17.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.17.7.tgz#e106997493e617edeba52fdbd965930da494113b"
integrity sha512-SYTdMaW47se8499q8m0fYKZZRlmq0RaRv6oYmlVm6DUm31l0fhOl1D03X8hGxohCKTI2Bg6w7W0TiYB51aJzag==
Expand All @@ -3222,11 +3227,6 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.16.tgz#1acf34f6456208f495dac0434dd540488d17f991"
integrity sha512-6CLxw83vQf6DKqXxMPwl8qpF8I7THFZuIwLt4TnNsumxkp1VsRZWT8txQxncT/Rl2UojTsFzWgDG4FRMwafrlA==

"@types/node@^15.0.1":
version "15.6.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.6.0.tgz#f0ddca5a61e52627c9dcb771a6039d44694597bc"
integrity sha512-gCYSfQpy+LYhOFTKAeE8BkyGqaxmlFxe+n4DKM6DR0wzw/HISUE/hAmkC/KT8Sw5PCJblqg062b3z9gucv3k0A==

"@types/normalize-package-data@^2.4.0":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
Expand Down Expand Up @@ -7891,18 +7891,18 @@ grapheme-splitter@^1.0.4:
resolved "https://registry.yarnpkg.com/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz#9cf3a665c6247479896834af35cf1dbb4400767e"
integrity sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==

graphql-config@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/graphql-config/-/graphql-config-4.0.0.tgz#412c93f5565d8a57cd962998b0944ef60b12ee88"
integrity sha512-gU0R5rWf0OLDlK1cRhj42SSfXZbtnl6WIjhwhrxFV0MhhQW/s0XQvXjG77O5ntUaXq1JPJKhV6+oYaELGs0Mrg==
graphql-config@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/graphql-config/-/graphql-config-4.0.1.tgz#4ce43cb54f3f39dde5f023d6f8f04064edc16e6e"
integrity sha512-JdXxFzBwjujJMGLHUZom9SrmP/M4gF57iTDa3fJVm3Q85+Xw2kj9jZIygaaSLpDKhaPnMQZqfJ5Hmc6afKxS9w==
dependencies:
"@endemolshinegroup/cosmiconfig-typescript-loader" "3.0.2"
"@graphql-tools/graphql-file-loader" "^7.0.0"
"@graphql-tools/json-file-loader" "^7.0.0"
"@graphql-tools/load" "^7.0.0"
"@graphql-tools/merge" "^6.2.15"
"@graphql-tools/url-loader" "^7.0.2"
"@graphql-tools/utils" "^8.0.0"
"@graphql-tools/graphql-file-loader" "^7.0.1"
"@graphql-tools/json-file-loader" "^7.0.1"
"@graphql-tools/load" "^7.1.0"
"@graphql-tools/merge" "^6.2.16"
"@graphql-tools/url-loader" "^7.0.3"
"@graphql-tools/utils" "^8.0.1"
cosmiconfig "7.0.0"
cosmiconfig-toml-loader "1.0.0"
minimatch "3.0.4"
Expand Down Expand Up @@ -13205,12 +13205,12 @@ rxjs@^6.3.3, rxjs@^6.4.0, rxjs@^6.5.1, rxjs@^6.6.0, rxjs@^6.6.3, rxjs@^6.6.7:
dependencies:
tslib "^1.9.0"

[email protected], safe-buffer@>=5.1.0, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
[email protected], safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==

safe-buffer@^5.2.0, safe-buffer@~5.2.0:
safe-buffer@>=5.1.0, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
Expand Down

0 comments on commit edd029e

Please sign in to comment.