question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@connection directive doesn't create an one-to-many relationship using primary key.

See original GitHub issue

Describe the bug @connection directive doesn’t create an one-to-many relationship using primary key.

To Reproduce

  1. Create two types (account and book) at schema.
  2. Account uses @key to declare userId as its simple primary key.
  3. Book uses @key to declare userId and createdAt as its composite primary key.
  4. Account uses @connection next to its books field to connect with book type with “userId” as primary key.
  5. Create an account followed by creating a book using the same userId .
  6. Query account and its books field shows null.
type account
	@model
	@key(fields: ["userId"])
	) {
	userId: String!
	books: [book] @connection(fields: ["userId"])
}

type book
	@model
	@key(fields: ["userId", "createdAt"])
	) {
	userId: String!
        createdAt: String!
	title: String
        author: String
}

Expected behavior When account is query, it’s books field should show the book created.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
xitangggcommented, Nov 10, 2020

I just checked. This issue has been resolved sometimes ago (idk by which commit). The documentation also makes a note If keyName is not provided, then @connection queries the target table’s primary index. Good work Amplify team!

0reactions
github-actions[bot]commented, May 25, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amplify GraphQL @connection Directive | Geek Culture
One -to-many connections require an index created with the @key on a connected object. In the schema below, the Comment object schema has...
Read more >
Create a one to many relationship using SQL Server
My professor at USC told us this simple rule: when there is one to many relationship, put the key of 'one' side as...
Read more >
API (GraphQL) - Data modeling - AWS Amplify Docs
A @hasOne relationship always uses a reference to the primary key of the related model, by default id unless overridden with the @primaryKey...
Read more >
Video: Create many-to-many relationships
To complete the many-to-many relationship, create a one-to-many relationship between the primary key field in each table and the matching field in the ......
Read more >
Datamodel (MySQL) - Prisma 1.34
"Post" ( "id" varchar(25) NOT NULL, "author" varchar(25), PRIMARY KEY ("id") );. Note that in this case the @relation directive could also be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found