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
88 stars 76 forks source link

Allow global config that allows selection between uuid vs ksuid vs ulid. #2456

Open harshit9715 opened 5 months ago

harshit9715 commented 5 months ago

Describe the feature you'd like to request

I can see the documentation allows all 3 types of IDs.

currently it uses uuid as default and there is no override option.

Describe the solution you'd like

we can provide a global config or translation behaviour option to provide an option to select an enum from one of uuid / ksuid and ulid?

Describe alternatives you've considered

I was able to override it for my specific use case.

const graphApi = new AmplifyGraphqlApi(stack, "GraphqlApi", {
    definition: AmplifyGraphqlDefinition.fromFiles(
      "stacks/amplify-schema.graphql"
    ),
    apiName: "GraphqlApi",
    translationBehavior: {},
    transformerPlugins: [],
    functionSlots: [
      "createQuestionTags",
      "createQuestion",
      "createTag",
      "createUser",
      "createAnswer",
    ].map((fieldName) => ({
      fieldName: fieldName,
      function: {
        requestMappingTemplate:
          MappingTemplate.fromString(`## [Start] Request mapping template.
## get the "fieldName" from ctx.stash and add it as a prefix to id.. make sure to replace 'create' word with ''
$util.qr($ctx.stash.defaultValues.put("id", "$util.autoUlid()"))
## [End] Initialization default values. **
{}`),
      },
      slotIndex: 0,
      slotName: "init",
      typeName: "Mutation",
    })),
    authorizationModes: {
      apiKeyConfig: {
        expires: Duration.days(365),
        description: "API Key for GraphQL API - " + stack.stage,
      },
      defaultAuthorizationMode: "OPENID_CONNECT",
      oidcConfig: {
        oidcIssuerUrl: process.env.CLERK_ISSUER_BASE_URL!,
        oidcProviderName: "Clerk",
        tokenExpiryFromAuth: Duration.millis(0),
        tokenExpiryFromIssue: Duration.millis(0),
      },
    },
  });

it does require a management overhead. to keep that array of models updated.

Additional context

No response

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

Would this feature include a breaking change?

AnilMaktala commented 5 months ago

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