Skip to content

[codegen] graphql config - multiple extension outputs from a project #49

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

Open
n10000k opened this issue Dec 31, 2020 · 8 comments
Open
Labels

Comments

@n10000k
Copy link

n10000k commented Dec 31, 2020

Is your feature request related to a problem? Please describe.
I want to output typescript types to lambda functions as well as my frontend application also.

Describe the solution you'd like
The ability to have many extensions with the same key as amplify within the same project:

projects:
  Workspaces:
    schemaPath: src/graphql/Workspaces/schema.json
    includes:
      - src/graphql/Workspaces/**/*.ts
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: typescript
        generatedFileName: src/utils/API.ts
        docsFilePath: src/graphql/Workspaces
        maxDepth: 2
      amplify:
        codeGenTarget: typescript
        generatedFileName: amplify/backend/foobar/API.ts
        docsFilePath: amplify/backend/foobar
        maxDepth: 2
extensions:
  amplify:
    version: 3

Describe alternatives you've considered
Having a folder in the root directory to allow types to be read from there, however it's not easy and requires extra permissions and npm won't let you read outside the main dir it's being ran from. So this will be an issue for lambda functions.

@n10000k
Copy link
Author

n10000k commented Dec 31, 2020

Alternative solution
This would work a better way instead of executing the extension many times;

projects:
  Workspaces:
    schemaPath: src/graphql/Workspaces/schema.json
    includes:
      - src/graphql/Workspaces/**/*.ts
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: typescript
        generatedFiles: 
          - src/utils/API.ts
          - amplify/backend/API.ts
        docsFilePaths:
          - src/graphql/Workspaces
          - amplify/backend/Workspaces
        maxDepth: 2
extensions:
  amplify:
    version: 3

An argument made this though could be that you're restricted to one language output at this point. Your frontend is javascript, but your lambda function is python.. it's not going to like the typescript output.

@AaronZyLee AaronZyLee transferred this issue from aws-amplify/amplify-cli Feb 3, 2021
@AaronZyLee AaronZyLee added amplify-codegen Issues on amplify-codegen feature-request New feature or request labels Feb 3, 2021
@phani-srikar
Copy link
Contributor

phani-srikar commented Feb 10, 2021

Hi @uncodable Thank you for taking time and requesting this feature. We are working on making the codegen configuration more flexible and customizable. Please look out for an RFC on this.
Meanwhile, if you hadn't figured out already, you could edit the .graphqlconfig.yml file in your project root, edit the path to generatedFiles and run amplify codegen to generate the code at a different place.

@n10000k
Copy link
Author

n10000k commented Feb 19, 2021

Thanks for the update @phani-srikar it's a blocker at the moment on my current project 👍🏻

@renebrandel
Copy link
Contributor

renebrandel commented Mar 18, 2021

@uncodable just wanted to let you know that we've publish an RFC to address this and other code generation issues. Would love to have your feedback! aws-amplify/amplify-cli#6898

@hackmajoris
Copy link

@uncodable just wanted to let you know that we've publish an RFC to address this and other code generation issues. Would love to have your feedback! aws-amplify/amplify-cli#6898

Any news when it will be ready? Some years already passed.

@vorant94
Copy link

vorant94 commented Jul 5, 2023

@hackmajoris as a workaround i found this to be working perfectly fine

(working only if you agree to generate all possible queries and types for some reason when you add/re-add codegen)

projects:
  functionsonsteroids:
    schemaPath: amplify/backend/api/functionsonsteroids/build/schema.graphql
    includes:
      - src/graphql/**/*.graphql
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: angular
        generatedFileName: src/app/API.service.ts
        docsFilePath: src/graphql
        region: eu-central-1
        apiId: null
        maxDepth: 2


  lambdaShared:
    schemaPath: amplify/backend/api/functionsonsteroids/build/schema.graphql
    includes:
      - projects/lambda-shared/src/lib/**/*.ts
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: typescript
        generatedFileName: projects/lambda-shared/src/lib/generated/app-sync.models.ts
        docsFilePath: projects/lambda-shared/src/lib/generated/
        region: eu-central-1
        apiId: null
        maxDepth: 2

extensions:
  amplify:
    version: 3

@hackmajoris
Copy link

hackmajoris commented Jul 5, 2023

@hackmajoris as a workaround i found this to be working perfectly fine

(working only if you agree to generate all possible queries and types for some reason when you add/re-add codegen)

projects:
  functionsonsteroids:
    schemaPath: amplify/backend/api/functionsonsteroids/build/schema.graphql
    includes:
      - src/graphql/**/*.graphql
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: angular
        generatedFileName: src/app/API.service.ts
        docsFilePath: src/graphql
        region: eu-central-1
        apiId: null
        maxDepth: 2


  lambdaShared:
    schemaPath: amplify/backend/api/functionsonsteroids/build/schema.graphql
    includes:
      - projects/lambda-shared/src/lib/**/*.ts
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: typescript
        generatedFileName: projects/lambda-shared/src/lib/generated/app-sync.models.ts
        docsFilePath: projects/lambda-shared/src/lib/generated/
        region: eu-central-1
        apiId: null
        maxDepth: 2

extensions:
  amplify:
    version: 3

Thank you. I have implemented the exact same approach and can confirm that it works fine.
PS: I do use Nx to manage the monorepo, and https://nx.dev/more-concepts/grouping-libraries comes in rescue when dealing with sharing libraries.

@charlieforward9
Copy link

What is the easiest way to get codeGenTarget: typescript #and graphql, to output all other things equal?

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

8 participants