Skip to content

Commit e529f11

Browse files
authored
[typescript-vue-apollo] Add Subscription Doc (dotansimha#4406)
1 parent 42552a0 commit e529f11

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

dev-test/githunt/types.vueApollo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export const OnCommentAddedDocument = gql`
340340
* When your component renders, `useOnCommentAddedSubscription` returns an object from Apollo Client that contains result, loading and error properties
341341
* you can use to render your UI.
342342
*
343-
* @param options that will be passed into the subscription, supported options are listed on: https://v4.apollo.vuejs.org/guide-composable/query.html#options;
343+
* @param options that will be passed into the subscription, supported options are listed on: https://v4.apollo.vuejs.org/guide-composable/subscription.html#options;
344344
*
345345
* @example
346346
* const { result, loading, error } = useOnCommentAddedSubscription(

packages/plugins/typescript/vue-apollo/src/visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class VueApolloVisitor extends ClientSideBaseVisitor<VueApolloRawPluginCo
119119
*${operationType === 'Mutation' ? mutationDescription : queryDescription}
120120
*
121121
* @param options that will be passed into the ${operationType.toLowerCase()}, supported options are listed on: https://v4.apollo.vuejs.org/guide-composable/${
122-
operationType === 'Mutation' ? 'mutation' : 'query'
122+
operationType === 'Mutation' ? 'mutation' : operationType === 'Subscription' ? 'subscription' : 'query'
123123
}.html#options;
124124
*
125125
* @example${operationType === 'Mutation' ? mutationExample : queryExample}

packages/plugins/typescript/vue-apollo/tests/vue-apollo.spec.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,23 @@ query MyFeed {
715715
* id: // value for 'id'
716716
* }
717717
* );
718+
*/`;
719+
720+
const subscriptionDocBlockSnapshot = `/**
721+
* __useCommentAddedSubscription__
722+
*
723+
* To run a query within a Vue component, call \`useCommentAddedSubscription\` and pass it any options that fit your needs.
724+
* When your component renders, \`useCommentAddedSubscription\` returns an object from Apollo Client that contains result, loading and error properties
725+
* you can use to render your UI.
726+
*
727+
* @param options that will be passed into the subscription, supported options are listed on: https://v4.apollo.vuejs.org/guide-composable/subscription.html#options;
728+
*
729+
* @example
730+
* const { result, loading, error } = useCommentAddedSubscription(
731+
* {
732+
* name: // value for 'name'
733+
* }
734+
* );
718735
*/`;
719736

720737
const mutationDocBlockSnapshot = `/**
@@ -747,6 +764,11 @@ query MyFeed {
747764
id
748765
}
749766
}
767+
subscription commentAdded($name: String) {
768+
commentAdded(repoFullName: $name) {
769+
id
770+
}
771+
}
750772
`);
751773

752774
const docs = [{ location: '', document: documents }];
@@ -761,12 +783,15 @@ query MyFeed {
761783
)) as Types.ComplexPluginOutput;
762784

763785
const queryDocBlock = extract(content.content.substr(content.content.indexOf('/**')));
764-
765786
expect(queryDocBlock).toEqual(queryDocBlockSnapshot);
766787

767-
const mutationDocBlock = extract(content.content.substr(content.content.lastIndexOf('/**')));
768-
788+
const mutationDocBlock = extract(
789+
content.content.substr(content.content.indexOf('/**', content.content.indexOf('/**') + 1))
790+
);
769791
expect(mutationDocBlock).toEqual(mutationDocBlockSnapshot);
792+
793+
const subscriptionDocBlock = extract(content.content.substr(content.content.lastIndexOf('/**')));
794+
expect(subscriptionDocBlock).toEqual(subscriptionDocBlockSnapshot);
770795
});
771796

772797
it('Should NOT generate JSDoc docblocks for composition functions if addDocBlocks is false', async () => {

0 commit comments

Comments
 (0)