aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

graphql-api-construct should output the codegen types. #2316

Open shobhanbiswas11 opened 8 months ago

shobhanbiswas11 commented 8 months ago

Describe the feature you'd like to request

new AmplifyGraphqlApi(this, "Api", {
      definition: <path-to-schema>,
     //There should be a feature like this
     codegenTypesOut: <path-to-d.ts>  
     //
      authorizationModes: {
        defaultAuthorizationMode: "API_KEY",
        apiKeyConfig: {
          expires: cdk.Duration.days(7),
        },
      },
    });

Need to use those type definition while working in the lambda resolvers.

Describe the solution you'd like

--

Describe alternatives you've considered

--

Additional context

Currently I'm doing it manually with the help of @graphql-codegen/cli

This is the codegen.ts file

import type { CodegenConfig } from "@graphql-codegen/cli";
import { existsSync, lstatSync, readdirSync } from "fs";
import { join, resolve } from "path";

function giveFilePathWithExtension(dir, extension) {
 //
}

const config: CodegenConfig = {
  schema: [
    giveFilePathWithExtension(resolve(__dirname, "./cdk.out"), ".graphql"),

    // Containing all the scalar
    "./appsync.graphql",
  ],
  // documents: ["src/api/graphql/**/*.graphql"],
  generates: {
    "appsync.d.ts": {
      plugins: ["typescript"],
    },
  },
  config: {
    scalars: {
      AWSJSON: "string",
      AWSDate: "string",
      AWSTime: "string",
      AWSDateTime: "string",
      AWSTimestamp: "number",
      AWSEmail: "string",
      AWSURL: "string",
      AWSPhone: "string",
      AWSIPAddress: "string",
    },
  },
};
export default config;

Is this something that you'd be interested in working on?

Would this feature include a breaking change?

AnilMaktala commented 8 months ago

Hey @shobhanbiswas11, Thank you for requesting this. We are marking this as a feature request for the team to evaluate further.