Skip to content

Setting field level auth rule for model makes resolver always null that field for Mutation responses #3343

@marmotgary

Description

@marmotgary

How did you install the Amplify CLI?

No response

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

No response

Amplify CLI Version

14.0.1

What operating system are you using?

Ubuntu

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

No

Describe the bug

Using GraphQL Transformer V1. Adding a field level auth rule for a model makes the given field always be null for mutations. I'm not sure if this is a bug or expected behavior? If it is expected, help me understand why does this happen.

Example of the generated resolver:

TestModel.authField.res.vtl

## [Start] Checking for allowed operations which can return this field **
#set( $operation = $util.defaultIfNull($context.source.operation, "null") )
#if( $operation == "Mutation" )
$util.toJson(null)
#else
  $util.toJson($context.source.authField)
#end
## [End] Checking for allowed operations which can return this field **

Expected behavior

The field with auth rule should be returned in the response of Mutations as well.

Reproduction steps

  1. Use transformer v1
  2. Add following to the schema
type TestModel
  @model
  {
  id: ID!
  authField: String
    @auth(
      rules: [
        { allow: public, operations: [read] }
      ]
    )
}
  1. Run codegen
  2. See how the generated resolver TestModel.authField.res.vtl always sets the field to null on Mutations.

Project Identifier

No response

Log output

Details
# Put your logs below this line


Additional information

We should be able to work around this by overwriting the resolvers (https://docs.amplify.aws/gen1/react/tools/cli-legacy/overwrite-customize-resolvers/#overwriting-resolvers)

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions