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

unable to set api key auth on custom mutation #14226

Open
3 tasks done
dreamorosi opened this issue Feb 20, 2025 · 0 comments
Open
3 tasks done

unable to set api key auth on custom mutation #14226

dreamorosi opened this issue Feb 20, 2025 · 0 comments
Labels
GraphQL Related to GraphQL API issues pending-maintainer-response Issue is pending a response from the Amplify team. pending-triage Issue is pending triage

Comments

@dreamorosi
Copy link

dreamorosi commented Feb 20, 2025

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

Not applicable

Backend

Amplify Gen 2

Environment information

# Put output below this line

@aws-amplify/backend: ^1.14.0 => 1.14.0 
    @aws-amplify/backend-cli: ^1.4.9 => 1.4.10 
    @aws-amplify/ui-react: ^6.9.1 => 6.9.1 
    @aws-amplify/ui-react-internal:  undefined ()
    @aws-amplify/ui-react-server:  undefined ()
    @types/react: ^19.0.8 => 19.0.8 
    @types/react-dom: ^19.0.4 => 19.0.4 
    @vitejs/plugin-react: ^4.3.4 => 4.3.4 
    aws-amplify: ^6.13.0 => 6.13.0 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/adapter-core/internals:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/internals:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    aws-cdk: ^2.179.0 => 2.179.0 
    aws-cdk-lib: ^2.179.0 => 2.179.0 
    constructs: ^10.4.2 => 10.4.2 
    react: ^19.0.0 => 19.0.0 (18.3.1)
    react-dom: ^19.0.0 => 19.0.0 (18.3.1)
    react-icons: ^5.4.0 => 5.4.0 
    vite: ^6.1.0 => 6.1.0 

Describe the bug

I have this schema:

const schema = a.schema({
  /*
    Creates a database table for 'Feedback' to store the feedbacks
    submitted through our web application.
  */
  Feedback: a
    .model({
      id: a.id(),
      content: a.string(),
      sentiment: a.string()
    })
    .authorization((allow) => [allow.publicApiKey()]),
  /*
    Create a new 'Execution' type that will be returned by our call
    to the Step Functions workflow.
  */
  Execution: a.customType({
    name: a.string(),
    status: a.string(),
    input: a.string(),
    executionArn: a.string(),
    startDate: a.string(),
    stopDate: a.string(),
    output: a.string(),
  }),
  /*
    Mutation that triggers the synchronous execution of our Step
    Functions workflow.
  */
  executeStateMachine: a
    .mutation()
    .arguments({input: a.string()})
    .returns(a.ref('Execution'))
});

And I am unable to set .authorization((allow) => [allow.publicApiKey()]), on the executeStateMachine mutation.

I am getting this error:

InvalidSchemaError: Custom operation executeStateMachine requires both an authorization rule and a handler reference

Expected behavior

I should be able to set my API Key as authorization to the custom operation without the need of specifying a custom authorization handler and deploy a function.

As a matter of fact, if I go on the AppSync console and manually add @aws_api_key to the schema and deploy it manually, everything works.

This used to work in a previous version of Amplify Gen 2, but at some point it broke.

Reproduction steps

See the code above.

Code Snippet

See above, or look at this aws-samples repo that got broken as result.

Log output

// Put your logs below this line
Uncaught AmplifyError InvalidSchemaError: Custom operation executeStateMachine requires both an authorization rule and a handler reference
    at generateContainerEntry (/Users/aamorosi/Codes/repros/aws-amplify-stepfunctions-example/node_modules/@aws-amplify/backend-data/lib/factory.js:96:19)
    at getOrCompute (/Users/aamorosi/Codes/repros/aws-amplify-stepfunctions-example/node_modules/@aws-amplify/backend/lib/engine/singleton_construct_container.js:30:57)
    at getInstance (/Users/aamorosi/Codes/repros/aws-amplify-stepfunctions-example/node_modules/@aws-amplify/backend-data/lib/factory.js:56:35)
    at <anonymous> (/Users/aamorosi/Codes/repros/aws-amplify-stepfunctions-example/node_modules/@aws-amplify/backend/lib/backend_factory.js:67:61)
    at BackendFactory (/Users/aamorosi/Codes/repros/aws-amplify-stepfunctions-example/node_modules/@aws-amplify/backend/lib/backend_factory.js:64:44)
    at defineBackend (/Users/aamorosi/Codes/repros/aws-amplify-stepfunctions-example/node_modules/@aws-amplify/backend/lib/backend_factory.js:98:21)
    at <anonymous> (/Users/aamorosi/Codes/repros/aws-amplify-stepfunctions-example/amplify/backend.ts:8:17)
    at run (<node_internals>/internal/modules/esm/module_job:268:25)
    --- await ---
    at runEntryPointWithESMLoader (<node_internals>/internal/modules/run_main:138:19)
    at executeUserEntryPoint (<node_internals>/internal/modules/run_main:175:5)
    at <anonymous> (<node_internals>/internal/main/run_main_module:36:49)

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending a response from the Amplify team. labels Feb 20, 2025
@jjarvisp jjarvisp added the GraphQL Related to GraphQL API issues label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GraphQL Related to GraphQL API issues pending-maintainer-response Issue is pending a response from the Amplify team. pending-triage Issue is pending triage
Projects
None yet
Development

No branches or pull requests

2 participants