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

typescript-apollo-angular ignores importOperationTypesFrom #4719

Closed
jbarrus opened this issue Sep 8, 2020 · 2 comments
Closed

typescript-apollo-angular ignores importOperationTypesFrom #4719

jbarrus opened this issue Sep 8, 2020 · 2 comments
Labels

Comments

@jbarrus
Copy link
Contributor

jbarrus commented Sep 8, 2020

Describe the bug
https://graphql-code-generator.com/docs/plugins/typescript-apollo-angular lists importOperationTypesFrom as a valid config but it is ignored

To Reproduce
Steps to reproduce the behavior:

schema: "schema.graphql"
generates:
  types.ts:
    plugins:
      - "typescript"
  operations.ts:
    documents: "document.graphql"
    config:
      documentMode: graphQLTag
    presetConfig:
      baseTypesPath: types.ts
    plugins:
      - "typescript-operations"
      - "typed-document-node"
  angular.ts:
    documents: "document.graphql"
    config:
      documentMode: external
      importOperationTypesFrom: "Operations"
      importDocumentNodeExternallyFrom: "./document.generated"
    plugins:
      - "typescript-apollo-angular"

https://codesandbox.io/s/hungry-saha-4t2pq?file=/angular.ts

Additional Context
I'm trying to generate types and operations in one lib and angular services in another to segregate the angular dependency (i.e. I want to be able to import operations from non-angular code and not pull in angular as a dependency). The examples for this are somewhat limited, so I may be doing this wrong, but I think I have the right config but the "importOperationTypesFrom" doesn't seem to be implemented in the typescript-apollo-angular plugin.
https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/typescript/apollo-angular/src/visitor.ts#L263

As a note, this does appear to be implemented in the typescript-apollo-react plugin:
https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/typescript/react-apollo/src/visitor.ts#L442

@jbarrus
Copy link
Contributor Author

jbarrus commented Sep 9, 2020

Sorry to pollute this issue, I can submit another, but I'm having another problem with this approach as well - when documentMode is set to external for the angular.ts output, the document names do not match in angular.ts.

angular.ts example service when generated in the same file as operations

export const UserDocument = gql`
    query user {
  user(id: 1) {
    id
    username
    email
  }
}
    `;

  @Injectable({
    providedIn: 'root'
  })
  export class UserGQL extends Apollo.Query<UserQuery, UserQueryVariables> {
    document = UserDocument;
    
    constructor(apollo: Apollo.Apollo) {
      super(apollo);
    }
  }

when imported from a separate file using documentMode external

  @Injectable({
    providedIn: 'root'
  })
  export class UserGQL extends Apollo.Query<UserQuery, UserQueryVariables> {
    document = Operations.user;
    
    constructor(apollo: Apollo.Apollo) {
      super(apollo);
    }
  }

expected is

  @Injectable({
    providedIn: 'root'
  })
  export class UserGQL extends Apollo.Query<UserQuery, UserQueryVariables> {
    document = Operations.UserDocument;
    
    constructor(apollo: Apollo.Apollo) {
      super(apollo);
    }
  }

dotansimha pushed a commit that referenced this issue Nov 4, 2020
… related to #4719 (#4765)

* modify apollo angular visitor to allow external opration definitions

* handle document

* fix document

* resolve unit test failures

* add unit test

* reset version

* add changeset

* add a warning for importOperationTypesFrom, update apollo-angular documentation

* more warnings and tests to help get configuration correct

* more eslint ignores

* update documentation for external documentMode

* more readme updates

* more readme updates
dotansimha added a commit that referenced this issue Nov 4, 2020
* Bump eslint-config-standard from 14.1.1 to 16.0.1

Bumps [eslint-config-standard](https://github.com/standard/eslint-config-standard) from 14.1.1 to 16.0.1.
- [Release notes](https://github.com/standard/eslint-config-standard/releases)
- [Changelog](https://github.com/standard/eslint-config-standard/blob/master/CHANGELOG.md)
- [Commits](standard/eslint-config-standard@v14.1.1...v16.0.1)

Signed-off-by: dependabot[bot] <support@github.com>

* Improve typescript vue apollo plugin (#5007)

* feat: support type imports

Closes #5006

* fix: do not use undefined for variables generic and parameter

Not using undefined for variables generic fixes the following issue:
Type 'undefined' does not satisfy the constraint 'Record<string, any>'

Not using undefined for variables parameter fixes the following issue:
Argument of type 'undefined' is not assignable to parameter of type 'VariablesParameter<Exact<{ [key: string]: never; }>>'

* feat: improve jsdoc formatting

* Remove newlines before and after the first argument in the example code.
* Add @param variables where applicable.

* chore: add changeset

* chore: update dev-test examples

* fix(cli): resolve modules provided through the -r flags relative to the cwd (#4983)

* fix(cli): require -r flags relative to the cwd

* chore: disable eslint for import

* fix(cli): resolve from folders correctly (#5032)

* fix(cli): resolve from folders correctly

* chore: changesets

* modify apollo angular visitor to allow external operation definitions related to #4719 (#4765)

* modify apollo angular visitor to allow external opration definitions

* handle document

* fix document

* resolve unit test failures

* add unit test

* reset version

* add changeset

* add a warning for importOperationTypesFrom, update apollo-angular documentation

* more warnings and tests to help get configuration correct

* more eslint ignores

* update documentation for external documentMode

* more readme updates

* more readme updates

* fix(vue-apollo): regression, respect omitOperationSuffix even with dedupeOperationSuffix enabled (#5015)

* fix(vue-apollo): regression, respect omitOperationSuffix even with dedupeOperationSuffix enabled

* updated changeset

* fix changeset

Co-authored-by: Dotan Simha <dotansimha@gmail.com>

* Bump graphql from 15.3.0 to 15.4.0 (#5008)

* Bump graphql from 15.3.0 to 15.4.0

Bumps [graphql](https://github.com/graphql/graphql-js) from 15.3.0 to 15.4.0.
- [Release notes](https://github.com/graphql/graphql-js/releases)
- [Commits](graphql/graphql-js@v15.3.0...v15.4.0)

Signed-off-by: dependabot[bot] <support@github.com>

* update all snapshot
fix for patches

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dotan Simha <dotansimha@gmail.com>

* Bump eslint-config-standard from 14.1.1 to 16.0.1

Bumps [eslint-config-standard](https://github.com/standard/eslint-config-standard) from 14.1.1 to 16.0.1.
- [Release notes](https://github.com/standard/eslint-config-standard/releases)
- [Changelog](https://github.com/standard/eslint-config-standard/blob/master/CHANGELOG.md)
- [Commits](standard/eslint-config-standard@v14.1.1...v16.0.1)

Signed-off-by: dependabot[bot] <support@github.com>

* fixes for lint issues

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Pascal Sthamer <sthamer.pascal@gmail.com>
Co-authored-by: Kristoffer K <merceyz@users.noreply.github.com>
Co-authored-by: Jeffrey Barrus <1044815+jbarrus@users.noreply.github.com>
Co-authored-by: JoeSchr <JoeSchr@users.noreply.github.com>
Co-authored-by: Dotan Simha <dotansimha@gmail.com>
@dotansimha
Copy link
Owner

Fixed in @graphql-codegen/typescript-apollo-angular@2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants