Skip to content

Commit

Permalink
Fix Dependency Injection issue in Apollo Angular when targeting ES5 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Aug 4, 2020
1 parent bc6e5c0 commit b9113da
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-experts-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/typescript-apollo-angular': patch
---

Fix Dependency Injection issue in Apollo Angular when targeting ES5
28 changes: 28 additions & 0 deletions dev-test/githunt/types.apolloAngular.sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ export class OnCommentAddedGQL extends Apollo.Subscription<
OnCommentAddedSubscriptionVariables
> {
document = OnCommentAddedDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const CommentDocument = gql`
query Comment($repoFullName: String!, $limit: Int, $offset: Int) {
Expand Down Expand Up @@ -378,6 +382,10 @@ export const CommentDocument = gql`
})
export class CommentGQL extends Apollo.Query<CommentQuery, CommentQueryVariables> {
document = CommentDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const CurrentUserForProfileDocument = gql`
query CurrentUserForProfile {
Expand All @@ -396,6 +404,10 @@ export class CurrentUserForProfileGQL extends Apollo.Query<
CurrentUserForProfileQueryVariables
> {
document = CurrentUserForProfileDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const FeedDocument = gql`
query Feed($type: FeedType!, $offset: Int, $limit: Int) {
Expand All @@ -414,6 +426,10 @@ export const FeedDocument = gql`
})
export class FeedGQL extends Apollo.Query<FeedQuery, FeedQueryVariables> {
document = FeedDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const SubmitRepositoryDocument = gql`
mutation submitRepository($repoFullName: String!) {
Expand All @@ -428,6 +444,10 @@ export const SubmitRepositoryDocument = gql`
})
export class SubmitRepositoryGQL extends Apollo.Mutation<SubmitRepositoryMutation, SubmitRepositoryMutationVariables> {
document = SubmitRepositoryDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const SubmitCommentDocument = gql`
mutation submitComment($repoFullName: String!, $commentContent: String!) {
Expand All @@ -443,6 +463,10 @@ export const SubmitCommentDocument = gql`
})
export class SubmitCommentGQL extends Apollo.Mutation<SubmitCommentMutation, SubmitCommentMutationVariables> {
document = SubmitCommentDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const VoteDocument = gql`
mutation vote($repoFullName: String!, $type: VoteType!) {
Expand All @@ -461,6 +485,10 @@ export const VoteDocument = gql`
})
export class VoteGQL extends Apollo.Mutation<VoteMutation, VoteMutationVariables> {
document = VoteDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
Expand Down
28 changes: 28 additions & 0 deletions dev-test/githunt/types.apolloAngular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ export class OnCommentAddedGQL extends Apollo.Subscription<
OnCommentAddedSubscriptionVariables
> {
document = OnCommentAddedDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const CommentDocument = gql`
query Comment($repoFullName: String!, $limit: Int, $offset: Int) {
Expand Down Expand Up @@ -377,6 +381,10 @@ export const CommentDocument = gql`
})
export class CommentGQL extends Apollo.Query<CommentQuery, CommentQueryVariables> {
document = CommentDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const CurrentUserForProfileDocument = gql`
query CurrentUserForProfile {
Expand All @@ -395,6 +403,10 @@ export class CurrentUserForProfileGQL extends Apollo.Query<
CurrentUserForProfileQueryVariables
> {
document = CurrentUserForProfileDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const FeedDocument = gql`
query Feed($type: FeedType!, $offset: Int, $limit: Int) {
Expand All @@ -413,6 +425,10 @@ export const FeedDocument = gql`
})
export class FeedGQL extends Apollo.Query<FeedQuery, FeedQueryVariables> {
document = FeedDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const SubmitRepositoryDocument = gql`
mutation submitRepository($repoFullName: String!) {
Expand All @@ -427,6 +443,10 @@ export const SubmitRepositoryDocument = gql`
})
export class SubmitRepositoryGQL extends Apollo.Mutation<SubmitRepositoryMutation, SubmitRepositoryMutationVariables> {
document = SubmitRepositoryDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const SubmitCommentDocument = gql`
mutation submitComment($repoFullName: String!, $commentContent: String!) {
Expand All @@ -442,6 +462,10 @@ export const SubmitCommentDocument = gql`
})
export class SubmitCommentGQL extends Apollo.Mutation<SubmitCommentMutation, SubmitCommentMutationVariables> {
document = SubmitCommentDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const VoteDocument = gql`
mutation vote($repoFullName: String!, $type: VoteType!) {
Expand All @@ -460,4 +484,8 @@ export const VoteDocument = gql`
})
export class VoteGQL extends Apollo.Mutation<VoteMutation, VoteMutationVariables> {
document = VoteDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
3 changes: 3 additions & 0 deletions packages/plugins/typescript/apollo-angular/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ export class ApolloAngularVisitor extends ClientSideBaseVisitor<
export class ${serviceName} extends Apollo.${operationType}<${operationResultType}, ${operationVariablesTypes}> {
document = ${this._getDocumentNodeVariable(node, documentVariableName)};
${this._namedClient(node)}
constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}`;

return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ describe('Apollo Angular', () => {
await validateTypeScript(content, schema, docs, {});
});

it(`should add a constructor and super call (Issue #4366)`, async () => {
const docs = [{ location: '', document: basicDoc }];
const content = (await plugin(
schema,
docs,
{},
{
outputFile: 'graphql.ts',
}
)) as Types.ComplexPluginOutput;

expect(content.content).toBeSimilarStringTo(`
constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
`);
await validateTypeScript(content, schema, docs, {});
});

it(`should add the correct angular imports with override`, async () => {
const docs = [{ location: '', document: basicDoc }];
const content = (await plugin(
Expand Down

0 comments on commit b9113da

Please sign in to comment.