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

Codegen does not produce compilable typescript queries.ts code #1960

Closed
2 tasks done
hisham opened this issue Oct 17, 2023 · 3 comments
Closed
2 tasks done

Codegen does not produce compilable typescript queries.ts code #1960

hisham opened this issue Oct 17, 2023 · 3 comments
Assignees
Labels
bug Something isn't working codegen p2

Comments

@hisham
Copy link

hisham commented Oct 17, 2023

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

18.16.1

Amplify CLI Version

12.7.0

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

After running amplify codgen to produce typescript code for a graphql API, the queries.ts file does not compile if the GraphQL API has a query function with no parameters.

Specifically the queries.ts code will have code like so that has a ts error:

` as GeneratedQuery<
  APITypes.GetProductsQueryVariables,
  APITypes.GetProductsQuery

The error is './graphql-schema' has no exported member APITypes.GetProductsQueryVariables

If you check the graphql-schema.ts file, you'll see there is no APITypes.GetProductsQueryVariables type defined. I assume because this function has no parameters and therefore there are no input variables to define.

Expected behavior

amplify codegen should produce syntactically correct queries.ts file.

Reproduction steps

  1. Make sure you have a function in your graphql API that does not have any parameters, e.g:
type Query { 
     getProducts: [Product!] @function(name: 'MyLambda-${env}')
}
  1. Configure your .graphqlconfig.yml file to produce typescript graphql schema code like so:
projects:
   myGraphQLSchema:
    schemaPath: amplify/backend/api/MyAPI/build/schema.graphql
    includes:
      - frontend/projects/shared/graphql/**/*.graphql
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: typescript
        generatedFileName: /my-graphql/graphql-schema.ts
        docsFilePath: my-graphql/
        region: us-east-1
        apiId: null
        maxDepth: 7
extensions:
  amplify:
     version: 3
  1. Run amplify codegen and examine the resulting queries.ts file

Project Identifier

3def1a2bd59d61900f734d59f169a578

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@AnilMaktala
Copy link
Member

AnilMaktala commented Oct 17, 2023

Hey @hisham, Thank you for bringing this matter to our attention. Following the instructions outlined in the issue, we observed that amplify codegen is not generating the code for custom queries as expected. Therefore, we're categorizing this as a bug for the team to conduct further investigation.

Here's a snippet of the schema and .graphqlconfig.yml used:

Schema:

input AMPLIFY {
  globalAuthRule: AuthRule = { allow: public }
} # FOR TESTING ONLY!
type Todo @model {
  id: ID!
  name: String!
  description: String
}

type Query {
  getTodos: [Todo!] @function(name: "test-${env}")
}

.graphqlconfig.yml:

projects:
  "1960":
    schemaPath: amplify/backend/api/1960/build/schema.graphql
    includes:
      - src/graphql/**/*.ts
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: typescript
        generatedFileName: src/graphql-schema.ts
        docsFilePath: src/graphql
extensions:
  amplify:
    version: 3

Upon running amplify codegen, the expected code generation did not occur.

@AnilMaktala AnilMaktala added bug Something isn't working p2 and removed pending-triage labels Oct 17, 2023
@hisham
Copy link
Author

hisham commented Nov 21, 2023

looks like this has been fixed in the latest release btw.

@nogeek
Copy link

nogeek commented Oct 17, 2024

This is still happening on a mac on release 12.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working codegen p2
Projects
None yet
Development

No branches or pull requests

4 participants