Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
5 changes: 5 additions & 0 deletions .changeset/brave-modules-skip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/graphql-modules-preset': patch
---

Skip sources without a `location` when grouping sources by module, instead of throwing from `path.normalize`, and skip sources without a `document` AST when building each module's document. Generated output from the CLI is unchanged.
4 changes: 2 additions & 2 deletions packages/presets/graphql-modules/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export function buildModule(
defined.objects.push(name);
collectFields(node, picks.objects);

if (node.interfaces?.length > 0) {
if ((node.interfaces?.length ?? 0) > 0) {
withIsTypeOf.objects.push(name);
}

Expand Down Expand Up @@ -495,7 +495,7 @@ export function buildModule(

pushUnique(extended.objects, name);

if (node.interfaces?.length > 0) {
if ((node.interfaces?.length ?? 0) > 0) {
pushUnique(withIsTypeOf.objects, name);
}

Expand Down
8 changes: 5 additions & 3 deletions packages/presets/graphql-modules/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const preset: Types.OutputPreset<ModulesConfig> = {
buildGeneratesSection: options => {
const { baseOutputDir } = options;
const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
const useGraphQLModules = getConfigValue(options?.presetConfig.useGraphQLModules, true);
const useGraphQLModules = options?.presetConfig.useGraphQLModules ?? true;
Comment thread
eddeee888 marked this conversation as resolved.
Outdated
const requireRootResolvers = getConfigValue(options?.presetConfig.requireRootResolvers, false);
const useTypeImports = getConfigValue(options?.config.useTypeImports, false) || false;

Expand Down Expand Up @@ -94,7 +94,9 @@ export const preset: Types.OutputPreset<ModulesConfig> = {
normalize(join(relativePath, baseTypesFilename));
const sources = sourcesByModuleMap[moduleName];

const moduleDocument = concatAST(sources.map(source => source.document));
const moduleDocument = concatAST(
sources.flatMap(source => (source.document ? [source.document] : [])),
);

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

Expand Down Expand Up @@ -125,7 +127,7 @@ export const preset: Types.OutputPreset<ModulesConfig> = {
schema.getQueryType()?.name,
schema.getMutationType()?.name,
schema.getSubscriptionType()?.name,
].filter(Boolean),
].filter((name): name is string => !!name),
Comment thread
eddeee888 marked this conversation as resolved.
Outdated
useTypeImports,
}),
},
Expand Down
4 changes: 4 additions & 0 deletions packages/presets/graphql-modules/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ export function groupSourcesByModule(
const grouped: Record<string, Source[]> = {};

for (const source of sources) {
if (!source.location) {
continue;
}

const relativePath = getRelativePath(source.location, basePath);

if (relativePath) {
Expand Down
Loading