Skip to content

Commit faecd25

Browse files
committed
Minor refactoring tests
1 parent ed2a5c0 commit faecd25

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Similar to `@graphql-codegen/typescript-graphql-files-modules` (https://graphql-
1818

1919
The difference is that is uses generic types, so that you have type safety with Apollo (e.g. `useQuery` / `useMutation`).
2020

21+
The `apollo-typed-documents` plugin also accepts the same `modulePathPrefix`, `relativeToCwd` and `prefix` config settings as [typescript-graphql-files-modules](https://graphql-code-generator.com/docs/plugins/typescript-graphql-files-modules).
22+
2123
### Install
2224

2325
```sh
@@ -54,8 +56,6 @@ generates:
5456
```
5557
<!-- AUTO-GENERATED-CONTENT:END -->
5658
57-
The `apollo-typed-documents` plugin also accepts the same `modulePathPrefix`, `relativeToCwd` and `prefix` config settings as [typescript-graphql-files-modules](https://graphql-code-generator.com/docs/plugins/typescript-graphql-files-modules).
58-
5959
`tsconfig.json`:
6060

6161
Add `node_modules/apollo-typed-documents/lib/reactHooks.d.ts` in `include` to override the typings for `@apollo/react-hooks`, so that types can be inferred from typed documents.

src/__tests__/codegenTypedDocuments.test.ts

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,23 @@ const schema = buildSchema(`
2424
`);
2525

2626
const getConfig = (
27-
options: Partial<Types.GenerateOptions> = {}
27+
generateOptions: Partial<Types.GenerateOptions> = {},
28+
pluginOptions: Partial<codegenTypedDocuments.UserConfig> = {}
2829
): Types.GenerateOptions => ({
2930
filename: "not-relevant",
3031
schema: parse(printSchema(schema)),
31-
plugins: [{ codegenTypedDocuments: { typesModule: "@codegen-types" } }],
32+
plugins: [
33+
{
34+
codegenTypedDocuments: {
35+
typesModule: "@codegen-types",
36+
...pluginOptions,
37+
},
38+
},
39+
],
3240
pluginMap: { codegenTypedDocuments },
3341
config: {},
3442
documents: [],
35-
...options,
43+
...generateOptions,
3644
});
3745

3846
describe("codegenTypedDocuments", () => {
@@ -161,22 +169,8 @@ describe("codegenTypedDocuments", () => {
161169
{ document: mutationDocument, location: "mutations/createAuthor.gql" },
162170
];
163171

164-
const getPathConfig = (pluginConfig: Record<string, unknown>) => {
165-
return getConfig({
166-
documents,
167-
plugins: [
168-
{
169-
codegenTypedDocuments: {
170-
typesModule: "@codegen-types",
171-
...pluginConfig,
172-
},
173-
},
174-
],
175-
});
176-
};
177-
178172
it("wildcards the basename by default", async () => {
179-
const config = getPathConfig({});
173+
const config = getConfig({ documents });
180174
const output = await codegen(config);
181175

182176
expect(output).toMatchInlineSnapshot(`
@@ -197,7 +191,7 @@ describe("codegenTypedDocuments", () => {
197191
});
198192

199193
it("respects the relativeToCwd setting", async () => {
200-
const config = getPathConfig({ relativeToCwd: true });
194+
const config = getConfig({ documents }, { relativeToCwd: true });
201195
const output = await codegen(config);
202196

203197
expect(output).toEqual(
@@ -209,7 +203,7 @@ describe("codegenTypedDocuments", () => {
209203
});
210204

211205
it("respects the prefix setting", async () => {
212-
const config = getPathConfig({ prefix: "gql/" });
206+
const config = getConfig({ documents }, { prefix: "gql/" });
213207
const output = await codegen(config);
214208

215209
expect(output).toEqual(
@@ -220,8 +214,8 @@ describe("codegenTypedDocuments", () => {
220214
);
221215
});
222216

223-
it("even respects the superfluous modulePathPrefix setting", async () => {
224-
const config = getPathConfig({ modulePathPrefix: "stuff/" });
217+
it("respects the modulePathPrefix setting", async () => {
218+
const config = getConfig({ documents }, { modulePathPrefix: "stuff/" });
225219
const output = await codegen(config);
226220

227221
expect(output).toEqual(
@@ -233,11 +227,14 @@ describe("codegenTypedDocuments", () => {
233227
});
234228

235229
it("allows combining path settings", async () => {
236-
const config = getPathConfig({
237-
prefix: "",
238-
modulePathPrefix: "defs/",
239-
relativeToCwd: true,
240-
});
230+
const config = getConfig(
231+
{ documents },
232+
{
233+
prefix: "",
234+
modulePathPrefix: "defs/",
235+
relativeToCwd: true,
236+
}
237+
);
241238

242239
const output = await codegen(config);
243240

0 commit comments

Comments
 (0)