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

DataStore does not support connection directive with keyName #3909

Closed
apoorvmote opened this issue Apr 9, 2020 · 16 comments
Closed

DataStore does not support connection directive with keyName #3909

apoorvmote opened this issue Apr 9, 2020 · 16 comments
Assignees
Labels
feature-request Request a new feature

Comments

@apoorvmote
Copy link

Which Category is your question related to?
Datastore

Amplify CLI Version
4.18.0

What AWS Services are you utilizing?
API, Cognito

Provide additional details e.g. code snippets
Following schema used to work. But doesn't work anymore.

type Blog @model
  @auth(rules: [
    {allow: owner}
  ]) {
  id: ID!
  title: String!
  owner: String!
  comments: [Comment] @connection(keyName: "byBlog", fields: ["id"])
}
type Comment @model 
  @auth(rules: [
    {allow: owner}
  ])
  @key(name: "byBlog", fields: ["blogID"]) {
    id: ID!
    owner: String!
    content: String!
    blogID: ID!
}

Now if I do amplify codegen models I get following error
Error: DataStore does not support connection directive with keyName

My question is
"Is this permanant change? or you have plans to support connection directive with keyName for datastore in future?"

@mdoesburg
Copy link

I am having the same issue even though it was suggested here that it should work, and that the docs for DataStore are outdated.

@SwaySway SwaySway added DataStore pending-triage Issue is pending triage labels Apr 9, 2020
@saevarb
Copy link

saevarb commented Apr 13, 2020

The responsible code for this is here. I implemented this fix on my own as an experiment before finding this issue, and I can confirm that with this fix, the resulting models and schemas are generated fine.

                    "association": {
                        "connectionType": "HAS_MANY",
                        "associatedWith": "tag" // tag is a model
                    }

But of course I have no clue whether this is actually supported or not and whether something will break somewhere else down the line.
Can someone from the amplify team comment on this? It is super limiting to not be able to do this.

@saevarb
Copy link

saevarb commented Apr 14, 2020

Just noting that in my previous comment I believed this to be limiting because I believed this was the only way to implement M-M connections. However, I was misled by the new docs as they had two sections, one of which uses keyName and another which does not.

@faris-sa
Copy link

after upgrading amplify CLI to version: @aws-amplify/cli@4.18.1
I received this error:
DataStore does not support connection directive with keyName

@yuth
Copy link
Contributor

yuth commented Apr 30, 2020

@apoorvmote

My question is
"Is this permanant change? or you have plans to support connection directive with keyName for datastore in future?"

The DataStore client libraries never supported keyName, and model gen did not flag this. We updated the model gen to throw this as an error so that there are no surprises at later at run time.
This change is not permanent and we do have plans to support keyName in future releases

@borisdayma
Copy link

I'm still confused on the recommended way to do many-to-many relationships when we want Datastore support.

  • CLI doc suggests it is as detailed in this issue, ie @connection with keyName -> this was the previously recommended way from my understanding
  • some part of javascript doc use @connection with name parameter which was the "old way" and supposed to become obsolete
  • some part of javascript doc actually suggest a new simple use (not documented in previous doc) that does not require any parameter to @connection

I understand this is a complex issue, leading to several breaking changes. Keep up the great work! This library makes AWS much more accessible.

@blydewright
Copy link

@yuth is there an open issue tracking this future feature that we can track?

@Albert-Gao
Copy link

Albert-Gao commented May 2, 2020

Kind of confusing, I thought the DataStore is designed for working with Graphql API.
So not supporting means DateStore is not designed for use with GraphQL API?

Or, it is WIP?

@blydewright
Copy link

@Albert-Gao it can be confusing, but it is in fact supported by the legacy (and future-outdated name="" directives.. The fact that the amplify add api generates model schema based on the new directives keyName="" is also very misleading. Such is the reality with distributed services supported by distributed teams - things won't always be in sync even though it would be great if they were!

I'd suggest looking at the docs here and using the soon-to-be-deprecated name="" directives in place of @key and keyName directives. These seem to be supported and work. Although I personally have hit many speed bumps along the way.. specifically a very misleading error:

Error: Models are not topologically sortable. Please verify your schema.

@Albert-Gao
Copy link

@blydewright Thanks, now I have a working example now. :) But won't progress far since the issue here.

This is my 2nd try of Amplify, always stuck from the start for some feature. Hope this time it goes well.

@blydewright
Copy link

blydewright commented May 3, 2020

@Albert-Gao I also have run into many issues, however most of them seem to have been me doing this the wrong way. I think some better documentation steps, especially showing the ideal flow and process for setting things up in live and mock environments, would really help! But the AWS guys seem to be overloaded which is understandable.

@Albert-Gao I managed to sort out the issue with the Error: Models are not topologically sortable. Please verify your schema. error. It seemed that my schema didn't have valid relationship mappings.. The error was terribly misleading.

I've confirmed that there are definitely issues with DataStore in the mock environment. Better for you to run things in AWS cloud for now while these are addressed.

aws-amplify/amplify-category-api#322

@undefobj
Copy link
Contributor

Can you take a look at the latest docs for Relational modeling with DataStore and use the latest library version? We made some improvements to the CLI, the library on how it handles this internally, and tried to be explicit about schemas in the documentation including how to use @key.

@kldeb
Copy link
Contributor

kldeb commented May 16, 2020

@undefobj

When using the @key directive without a name property with DataStore, the first item in the fields array must be id, e.g. @key(fields: ["id", "content"]).

Does the field have to be named id or can it just be an ID field?

Would this work:

enum PostStatus {
  ACTIVE
  INACTIVE
}

type Post 
  @model 
  @key(fields: ["postID"])
{
  postID: ID!
  title: String!
  rating: Int!
  status: PostStatus!
  # New field with @connection
  comments: [Comment] @connection(keyName: "byPost", fields: ["postID"])
}

# New model
type Comment @model
  @key(fields: ["commentID"])
  @key(name: "byPost", fields: ["postID", "content"]) {
  commentID: ID!
  postID: ID!
  content: String!
}

@undefobj
Copy link
Contributor

As long as the key has a name, it can be anything. But if the name property is omitted, the first item in the fields array must be “id”.

@bernardnongpoh
Copy link

I updated to Amplify 4.20.0 with the following command. It works
npm i -g @aws-amplify/cli

@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 26, 2021
@josefaidt josefaidt added feature-request Request a new feature and removed enhancement labels Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests