Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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/few-queens-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-modules': patch
---

Make replaceExtensions work with inheritTypeDefs
18 changes: 9 additions & 9 deletions packages/graphql-modules/src/testing/test-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ export function testModule(testedModule: Module, config?: TestModuleConfig) {
function transformModule(mod: Module, config?: TestModuleConfig) {
const transforms: ((m: Module) => Module)[] = [];

if (config?.replaceExtensions) {
transforms.push((m) =>
moduleFactory({
...m.config,
typeDefs: replaceExtensions(m.typeDefs),
})
);
}

if (config?.typeDefs) {
transforms.push((m) =>
moduleFactory({
Expand Down Expand Up @@ -117,6 +108,15 @@ function transformModule(mod: Module, config?: TestModuleConfig) {
});
}

if (config?.replaceExtensions) {
transforms.push((m) =>
moduleFactory({
...m.config,
typeDefs: replaceExtensions(m.typeDefs),
})
);
}

if (transforms) {
return transforms.reduce((m, transform) => transform(m), mod);
}
Expand Down
63 changes: 62 additions & 1 deletion packages/graphql-modules/tests/testing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'reflect-metadata';
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
import { concatAST } from 'graphql';
import { concatAST, printSchema } from 'graphql';
import {
createApplication,
createModule,
Expand All @@ -13,6 +13,10 @@ import {
Scope,
} from '../src';

function normalizeSDL(sdl: string): string {
return sdl.replace(/\s+/g, ' ').trim();
}

describe('testModule', () => {
test('should replace extensions with definitions on demand', () => {
const initialModule = createModule({
Expand Down Expand Up @@ -581,4 +585,61 @@ describe('mockApplication', () => {
extraEnv: 'mocked',
});
});

test('replaceExtensions should work with inheritTypeDefs', () => {
const listModule = createModule({
id: 'list',
typeDefs: gql`
extend type Query {
list: List!
}

type List {
id: ID!
title: String!
}
`,
});

const productModule = createModule({
id: 'product',
typeDefs: gql`
extend type Query {
product: Product!
}

type Product {
id: ID!
}

extend type List {
product: Product!
}
`,
});

const app = testkit.testModule(productModule, {
replaceExtensions: true,
inheritTypeDefs: [listModule],
});

expect(() => app.schema).not.toThrow();
expect(normalizeSDL(printSchema(app.schema))).toMatch(
normalizeSDL(`
type Query {
product: Product!
}

type Product {
id: ID!
}

type List {
id: ID!
title: String!
product: Product!
}
`)
);
});
});