Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Jun 20, 2021
1 parent 1d67a4f commit 1c695e5
Showing 1 changed file with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Types } from '@graphql-codegen/plugin-helpers';
import { buildSchema, parse } from 'graphql';
import { plugin } from '../src';

describe('TypeDocumentNode', () => {
describe('TypedDocumentNode', () => {
it('Should not output imports when there are no operations at all', async () => {
const result = (await plugin(null as any, [], {})) as Types.ComplexPluginOutput;
expect(result.content).toBe('');
Expand Down Expand Up @@ -31,6 +31,7 @@ describe('TypeDocumentNode', () => {
jobs {
...DataForPageA
...DataForPageB
...JobSimpleRecruiterData
}
}
Expand Down Expand Up @@ -59,6 +60,64 @@ describe('TypeDocumentNode', () => {
expect((res.content.match(/JobSimpleRecruiterDataFragmentDoc.definitions/g) || []).length).toBe(1);
});

it('Check with nested and recursive fragments handle (dedupeFragments=true)', async () => {
const schema = buildSchema(/* GraphQL */ `
type Query {
test: MyType
nested: MyOtherType
}
type MyOtherType {
myType: MyType!
myOtherTypeRecursive: MyOtherType!
}
type MyType {
foo: String!
}
`);

const ast = parse(/* GraphQL */ `
query test {
test {
...MyTypeFields
nested {
myOtherTypeRecursive {
myType {
...MyTypeFields
}
myOtherTypeRecursive {
...MyOtherTypeRecursiveFields
}
}
myType {
...MyTypeFields
}
}
}
}
fragment MyOtherTypeRecursiveFields on MyOtherType {
myType {
...MyTypeFields
}
}
fragment MyTypeFields on MyType {
foo
}
`);

const res = (await plugin(
schema,
[{ location: '', document: ast }],
{ dedupeFragments: true },
{ outputFile: '' }
)) as Types.ComplexPluginOutput;

expect((res.content.match(/MyTypeFieldsFragmentDoc.definitions/g) || []).length).toBe(1);
});

it('Ignore duplicated nested fragments handle (dedupeFragments=false)', async () => {
const schema = buildSchema(/* GraphQL */ `
schema {
Expand Down

0 comments on commit 1c695e5

Please sign in to comment.