Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix fragments with noGraphQlTag #2106

Merged
merged 1 commit into from Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -91,10 +91,26 @@ export class ClientSideBaseVisitor<TRawConfig extends RawClientSideBasePluginCon

protected _includeFragments(fragments: string[]): string {
if (fragments && fragments.length > 0) {
return `${fragments
.filter((name, i, all) => all.indexOf(name) === i)
.map(name => '${' + name + '}')
.join('\n')}`;
if (this.config.noGraphQLTag) {
return `${fragments
.filter((name, i, all) => all.indexOf(name) === i)
.map(name => {
const found = this._fragments.find(f => `${f.name}FragmentDoc` === name);

if (found) {
return print(found.node);
}

return null;
})
.filter(a => a)
.join('\n')}`;
} else {
return `${fragments
.filter((name, i, all) => all.indexOf(name) === i)
.map(name => '${' + name + '}')
.join('\n')}`;
}
}

return '';
Expand Down
Expand Up @@ -32,6 +32,47 @@ describe('React Apollo', () => {
validateTs(merged, undefined, true);
};

describe('Issues', () => {
it('Issue #2080 - noGraphQLTag does not work with fragments correctly', async () => {
const docs = [
{
filePath: '',
content: parse(/* GraphQL */ `
query test {
feed {
id
commentCount
repository {
...RepositoryFields
}
}
}

fragment RepositoryFields on Repository {
full_name
html_url
owner {
avatar_url
}
}
`),
},
];
const content = (await plugin(
schema,
docs,
{
noGraphQLTag: true,
},
{
outputFile: 'graphql.tsx',
}
)) as Types.ComplexPluginOutput;
// make sure the fragment is there twice.
expect(content.content.split('{"kind":"FragmentDefinition","name":{"kind":"Name","value":"RepositoryFields"}').length).toBe(3);
});
});

describe('Imports', () => {
it('should import React and ReactApollo dependencies', async () => {
const docs = [{ filePath: '', content: basicDoc }];
Expand Down