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

Mixed authentication (public/private) with a many-to-many schema fails #6104

Closed
josh-tncarry opened this issue Dec 8, 2020 · 3 comments · Fixed by #5655
Closed

Mixed authentication (public/private) with a many-to-many schema fails #6104

josh-tncarry opened this issue Dec 8, 2020 · 3 comments · Fixed by #5655
Assignees
Labels
bug Something isn't working @connection Issues tied to @connection directive graphql-transformer-v1 Issue related to GraphQL Transformer v1
Projects

Comments

@josh-tncarry
Copy link

Describe the bug
When creating a simple many-to-many schema, it appears that the compiled graphql schema does not include the appropriate permission attributes necessary for handling an API that supports both public and private use.

Given a many to many relationship using only Cognito auth modes, everything works as expected, but the minute you introduce:

{ allow: public, operations: [read], provider: iam }

Into the model, it appears that the linking model is not decorated in the final output with any authorization attributes, causing it to throw errors for both authenticated as well as unauthenticated users.

Amplify CLI Version
4.37.0

To Reproduce

  1. Create a simple amplify project
  2. amplify add api
  3. configure both Cognito authentication as well as IAM
  4. Use the following graphql schema:
type User
  @model
  @key(fields: ["username"])
  @auth(
    rules: [
      { allow: owner, operations: [create, delete, update] }
      { allow: private, operations: [read] }
      { allow: public, operations: [read], provider: iam }
    ]
  ) {
  username: String!
  postLikes: [PostLike] @connection(keyName: "byUsername", fields: ["username"])
}

type Post
  @model
  @auth(
    rules: [
      { allow: owner, operations: [create, delete, update] }
      { allow: private, operations: [read] }
      { allow: public, operations: [read], provider: iam }
    ]
  ) {
  id: ID!
  body: String!
  username: String!
  user: User! @connection(fields: ["username"])
  userLikes: [PostLike] @connection(keyName: "byPostId", fields: ["id"])
}

type PostLike
  @model(queries: null)
  @auth(
    rules: [
      { allow: owner, operations: [create, delete, update] }
      { allow: private, operations: [read] }
      { allow: public, operations: [read], provider: iam }
    ]
  )
  @key(name: "byPostId", fields: ["postId", "username"])
  @key(name: "byUsername", fields: ["username", "postId"]) {
  id: ID!
  postId: ID!
  username: String!
  post: Post! @connection(fields: ["postId"])
  user: User! @connection(fields: ["username"])
}
  1. Compile the graphql schema with amplify api gql-compile
  2. Observe that the model ModelPostLikeConnection does not have any auth attributes
type ModelPostLikeConnection {
  items: [PostLike]
  nextToken: String
}

When querying the Post model and trying to also pull in all userLikes the query will fail with a message of Not Authorized to access nextToken on type ModelPostLikeConnection

Expected behavior
The linking table should look like this:

type ModelPostLikeConnection @aws_iam @aws_cognito_user_pools {
  items: [PostLike]
  nextToken: String
}

Desktop (please complete the following information):

  • Windows
  • 15.3.0

Additional context
A minimal repo with the graphql schema necessary to reproduce the bug can be found here: https://github.com/josh-tncarry/many-to-many-amplify-bug

@attilah attilah added this to To do in Bug bash via automation Dec 10, 2020
@attilah attilah added @connection Issues tied to @connection directive bug Something isn't working graphql-transformer-v1 Issue related to GraphQL Transformer v1 labels Dec 10, 2020
@attilah
Copy link
Contributor

attilah commented Dec 10, 2020

@josh-tncarry thanks for reporting we'll look into it!

@josh-tncarry
Copy link
Author

Ok, as an update, it would appear that if you remove the (queries: null) part on the PostLike model, then the correct auth attributes will be generated.

I can probably further simplify this example given this information.

@akshbhu akshbhu self-assigned this Jan 15, 2021
@akshbhu akshbhu moved this from To do to In progress in Bug bash Jan 15, 2021
@akshbhu akshbhu moved this from In progress to Review in Bug bash Jan 15, 2021
Bug bash automation moved this from Review to Done Jan 20, 2021
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working @connection Issues tied to @connection directive graphql-transformer-v1 Issue related to GraphQL Transformer v1
Projects
Bug bash
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants