Skip to content

Commit

Permalink
Update ResultType tests for completeness
Browse files Browse the repository at this point in the history
  • Loading branch information
eddeee888 committed Jul 15, 2019
1 parent 0f84fcb commit 474a951
Showing 1 changed file with 66 additions and 15 deletions.
81 changes: 66 additions & 15 deletions packages/plugins/typescript/react-apollo/tests/react-apollo.spec.ts
Expand Up @@ -840,7 +840,23 @@ export function useListenToCommentsSubscription(baseOptions?: ReactApolloHooks.S
withMutationOptionsType: false,
};

it('should generate ResultType for Query', async () => {
const mutationDoc = parse(/* GraphQL */ `
mutation test($name: String) {
submitRepository(repoFullName: $name) {
id
}
}
`);

const subscriptionDoc = parse(/* GraphQL */ `
subscription test($name: String) {
commentAdded(repoFullName: $name) {
id
}
}
`);

it('should generate ResultType for Query if withResultType is true', async () => {
const docs = [{ filePath: '', content: basicDoc }];
const content = (await plugin(
schema,
Expand All @@ -856,14 +872,23 @@ export function useListenToCommentsSubscription(baseOptions?: ReactApolloHooks.S
await validateTypeScript(content, schema, docs, {});
});

it('should generate ResultType for Mutation', async () => {
const mutationDoc = parse(/* GraphQL */ `
mutation test($name: String) {
submitRepository(repoFullName: $name) {
id
}
it('should NOT generate ResultType for Query if withResultType is false', async () => {
const docs = [{ filePath: '', content: basicDoc }];
const content = (await plugin(
schema,
docs,
{ ...config, withResultType: false },
{
outputFile: 'graphql.tsx',
}
`);
)) as Types.ComplexPluginOutput;

expect(content.prepend).not.toContain(`import * as ReactApollo from 'react-apollo';`);
expect(content.content).not.toContain(`export type TestQueryResult = ReactApollo.QueryResult<TestQuery, TestQueryVariables>;`);
await validateTypeScript(content, schema, docs, {});
});

it('should generate ResultType for Mutation if withResultType is true', async () => {
const docs = [{ filePath: '', content: mutationDoc }];

const content = (await plugin(
Expand All @@ -880,15 +905,24 @@ export function useListenToCommentsSubscription(baseOptions?: ReactApolloHooks.S
await validateTypeScript(content, schema, docs, {});
});

it('should generate ResultType for Subscription', async () => {
const subscriptionDoc = parse(/* GraphQL */ `
subscription test($name: String) {
commentAdded(repoFullName: $name) {
id
}
it('should NOT generate ResultType for Mutation if withResultType is false', async () => {
const docs = [{ filePath: '', content: mutationDoc }];

const content = (await plugin(
schema,
docs,
{ ...config, withResultType: false },
{
outputFile: 'graphql.tsx',
}
`);
)) as Types.ComplexPluginOutput;

expect(content.prepend).not.toContain(`import * as ReactApollo from 'react-apollo';`);
expect(content.content).not.toContain(`export type TestMutationResult = ReactApollo.MutationResult<TestMutation>;`);
await validateTypeScript(content, schema, docs, {});
});

it('should generate ResultType for Subscription if withResultType is true', async () => {
const docs = [{ filePath: '', content: subscriptionDoc }];

const content = (await plugin(
Expand All @@ -904,6 +938,23 @@ export function useListenToCommentsSubscription(baseOptions?: ReactApolloHooks.S
expect(content.content).toContain(`export type TestSubscriptionResult = ReactApollo.SubscriptionResult<TestSubscription>;`);
await validateTypeScript(content, schema, docs, {});
});

it('should NOT generate ResultType for Subscription if withResultType is false', async () => {
const docs = [{ filePath: '', content: subscriptionDoc }];

const content = (await plugin(
schema,
docs,
{ ...config, withResultType: false },
{
outputFile: 'graphql.tsx',
}
)) as Types.ComplexPluginOutput;

expect(content.prepend).not.toContain(`import * as ReactApollo from 'react-apollo';`);
expect(content.content).not.toContain(`export type TestSubscriptionResult = ReactApollo.SubscriptionResult<TestSubscription>;`);
await validateTypeScript(content, schema, docs, {});
});
});

describe('MutationOptions', () => {
Expand Down

0 comments on commit 474a951

Please sign in to comment.