Skip to content

Commit

Permalink
Fixed include functionality in urql-introspection (#6136)
Browse files Browse the repository at this point in the history
* add failing tests for `include` functionality

* remove duplicate minifyIntrospectionQuery

* add changeset
  • Loading branch information
aldrio authored Jun 16, 2021
1 parent b5d4b6a commit 794222e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-cherries-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/urql-introspection': patch
---

Fixed include functionality in urql-introspection
14 changes: 6 additions & 8 deletions packages/plugins/other/urql-introspection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,12 @@ export const plugin: PluginFunction = async (

const ext = extname(info.outputFile).toLowerCase();

const minifiedData = minifyIntrospectionQuery(
minifyIntrospectionQuery(getIntrospectedSchema(schema), {
includeDirectives: config.includeDirectives,
includeEnums: config.includeEnums,
includeInputs: config.includeInputs,
includeScalars: config.includeScalars,
})
);
const minifiedData = minifyIntrospectionQuery(getIntrospectedSchema(schema), {
includeDirectives: config.includeDirectives,
includeEnums: config.includeEnums,
includeInputs: config.includeInputs,
includeScalars: config.includeScalars,
});

const content = JSON.stringify(minifiedData, null, 2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,60 @@ export default ${introspection} as unknown as IntrospectionQuery;`;
expect(tsContent).toBeSimilarStringTo(output);
expect(tsxContent).toBeSimilarStringTo(output);
});

it('Should emit scalars if includeScalars config value is used', async () => {
const schema = buildSchema(`
scalar MyScalar
type Query {
myScalar: MyScalar
}
`);
const result = await plugin(schema, [], { includeScalars: true }, { outputFile: 'foo.ts' });

expect(result).toContain('MyScalar');
});

it('Should emit directives if includeDirectives config value is used', async () => {
const schema = buildSchema(`
directive @myDirective on FIELD_DEFINITION
type Query {
foo: Int @myDirective
}
`);
const result = await plugin(schema, [], { includeDirectives: true }, { outputFile: 'foo.ts' });

expect(result).toContain('myDirective');
});

it('Should emit enums if includeEnums config value is used', async () => {
const schema = buildSchema(`
enum MyEnum {
FOO
}
type Query {
myEnum: MyEnum
}
`);
const result = await plugin(schema, [], { includeEnums: true }, { outputFile: 'foo.ts' });

expect(result).toContain('MyEnum');
});

it('Should emit inputs if includeInputs config value is used', async () => {
const schema = buildSchema(`
input MyInput {
foo: Int
}
type Query {
foo(myInput: MyInput): Int
}
`);
const result = await plugin(schema, [], { includeInputs: true }, { outputFile: 'foo.ts' });

expect(result).toContain('MyInput');
});
});
});

0 comments on commit 794222e

Please sign in to comment.