diff --git a/.changeset/fuzzy-sheep-smoke.md b/.changeset/fuzzy-sheep-smoke.md new file mode 100644 index 00000000000..983b37ee856 --- /dev/null +++ b/.changeset/fuzzy-sheep-smoke.md @@ -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 diff --git a/packages/graphql-codegen-cli/package.json b/packages/graphql-codegen-cli/package.json index 56e16ecda63..fe2310fda59 100644 --- a/packages/graphql-codegen-cli/package.json +++ b/packages/graphql-codegen-cli/package.json @@ -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", @@ -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", diff --git a/packages/presets/graphql-modules/package.json b/packages/presets/graphql-modules/package.json index e49a5b30186..0502d280004 100644 --- a/packages/presets/graphql-modules/package.json +++ b/packages/presets/graphql-modules/package.json @@ -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" diff --git a/packages/presets/graphql-modules/src/index.ts b/packages/presets/graphql-modules/src/index.ts index d0deb43bf9f..53fc7bd9748 100644 --- a/packages/presets/graphql-modules/src/index.ts +++ b/packages/presets/graphql-modules/src/index.ts @@ -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'; @@ -24,7 +24,7 @@ export const preset: Types.OutputPreset = { 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, {}); @@ -78,13 +78,7 @@ export const preset: Types.OutputPreset = { 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'); diff --git a/packages/presets/graphql-modules/src/utils.ts b/packages/presets/graphql-modules/src/utils.ts index 788c417bce6..cd090bdd931 100644 --- a/packages/presets/graphql-modules/src/utils.ts +++ b/packages/presets/graphql-modules/src/utils.ts @@ -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 = '/'; @@ -146,11 +146,11 @@ export function groupSourcesByModule(sources: Source[], basePath: string): Recor const grouped: Record = {}; 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] = []; diff --git a/yarn.lock b/yarn.lock index ae3e17654b5..77e8184d5c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== @@ -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== @@ -2065,10 +2065,10 @@ 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" @@ -2076,7 +2076,7 @@ p-limit "3.1.0" tslib "~2.3.0" -"@graphql-tools/merge@6.2.16", "@graphql-tools/merge@^6.2.15", "@graphql-tools/merge@^6.2.16", "@graphql-tools/merge@^6.2.4": +"@graphql-tools/merge@6.2.16", "@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== @@ -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== @@ -3207,7 +3207,12 @@ dependencies: "@types/node" "*" -"@types/node@*", "@types/node@14.17.7", "@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/node@14.17.7", "@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== @@ -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" @@ -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" @@ -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" -safe-buffer@5.1.2, 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: +safe-buffer@5.1.2, 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==