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

feat: add metrics metadata for auth mode and custom operations #2966

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dpilch
Copy link
Member

@dpilch dpilch commented Oct 17, 2024

Description of changes

Add additional metrics metadata for authorizationMode and customOperations. The metric data is stored in the CFN stack description.

{
  "metadata": {
    "dataSources": "dynamodb,mysql,postgres", // exists today

    // new fields below
    /*
      Possible options
      'aws_iam',
      'openid_connect',
      'amazon_cognito_identity_pools',
      'amazon_congnito_user_pools',
      'api_key',
      'aws_lambda',
    */
    "authorizationModes", "api_key,aws_lambda",
    "customOperations": "queries,mutations"
  }
}
CDK / CloudFormation Parameters Changed

The metrics are stored in the CFN description. No real functional change, but the descriptions will be updated.

Issue #, if available

N/A

Description of how you validated changes

  • Unit tests

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

const template = Template.fromStack(stack);
expect(JSON.parse(template.toJSON().Description).metadata).toMatchInlineSnapshot(`
Object {
"authorizationModes": "api_key,aws_iam,aws_lambda",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This asserts order as well as content -- is that intentional?

apiKeyConfig: 'api_key',
lambdaConfig: 'aws_lambda',
};
const authModes = Object.keys(authorizationModes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the tests above asserts the order of the auth mode metric. Is that intentional? Should we sort the values here so we can provide a stable value irrespective of the order in which they are declared?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I will apply a sort.


export const getMetadataCustomOperations = (definition: IAmplifyGraphqlDefinition): string => {
const customOperations: string[] = [];
if (definition.schema.includes('type Query')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not subscriptions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't in the product requirements, but we should probably just add it.

@palpatim
Copy link
Member

As far as I can tell this is a typo in the PR description, but calling it out in case:

    /*
      Possible options
      'aws_iam',
      'openid_connect',
      'amazon_cognito_identity_pools',
      'amazon_congnit_user_pools',
      'api_key',
      'aws_lambda',
    */

@dpilch
Copy link
Member Author

dpilch commented Oct 18, 2024

Yes, typo in the description. We can see amazon_congnito_user_pools is set correctly in the unit test.

@dpilch dpilch marked this pull request as ready for review October 18, 2024 19:32
@dpilch dpilch requested a review from a team as a code owner October 18, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants