Amplify-js: @key on field annotated with @connection

Created on 29 Jun 2019  路  4Comments  路  Source: aws-amplify/amplify-js

* Which Category is your question related to? *
GraphQL Schema

* What AWS Services are you utilizing? *
API, AppSync

* Provide additional details e.g. code snippets *

The below produces this expected error on amplify push:
Expected scalar and got User

type Membership @model @key(fields: ["user"], name: "ByUser", queryField: "membershipsByUser") {
  id: ID! 
  channel: Channel @connection(name: "channelMemberships")
  user: User @connection(name: "userMemberships")
}

Can we create a gsi on a connection field? Ultimately it's represented by the id.

All 4 comments

I realized I'm approaching this the wrong way. Too much friction. Please ignore. If anyone comes across a similar requirement, hit me up.

I realized I'm approaching this the wrong way. Too much friction. Please ignore. If anyone comes across a similar requirement, hit me up.

Here :) so how did you fix this? i need to use @key, but than i need a connection for a field inside

I realized I'm approaching this the wrong way. Too much friction. Please ignore. If anyone comes across a similar requirement, hit me up.

I'm also interested to see how you resolved this. Thanks!

oh wow sorry guys just saw this @davidbiller @amirmishani
If I remember correctly I wanted to be able to query the table with the non key field which was a @connection field. No point to create a gsi around, since @connection I believe creates a gsi under the hood. So You really just need to go to the table being referenced. In my case for example, table User has memberships and if I say user.memberships, that will give me all the user memberships I need. That's technically a query using a gsi in the membership table.

So long story short, don't use a @key on @connection.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

callmekatootie picture callmekatootie  路  3Comments

shinnapatthesix picture shinnapatthesix  路  3Comments

josoroma picture josoroma  路  3Comments

benevolentprof picture benevolentprof  路  3Comments

TheRealRed7 picture TheRealRed7  路  3Comments