Note: If your question is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum
Which Category is your question related to?
Amplify CLI Version
4.18.1
You can use amplify -v to check the amplify cli version on your system
Provide additional details e.g. code snippets
type CampaignAdmin
@model
@key(fields: ["email"])
{
email: AWSEmail!
firstname: String!
lastname: String!
# CampaignAdmin and Volunteers have many to many relatinoship.
volunteers: [CampaignAdminVolunteer] @connection(keyName: "byCampaignAdmin", fields: ["email"])
}
type CampaignAdminVolunteer
@model(queries: null)
@key(name: "byVolunteer", fields: ["volunteerEmail", "adminEmail"])
@key(name: "byCampaignAdmin", fields: ["adminEmail", "volunteerEmail"])
{
id: ID!
adminEmail: AWSEmail!
volunteerEmail: AWSEmail!
volunteer: Volunteer! @connection(fields: ["volunteerEmail"])
campaignAdmin: CampaignAdmin! @connection(fields: ["adminEmail"])
}
type Volunteer
@model
@key(fields: ["email"])
{
email: AWSEmail!
firstname: String!
lastname: String!
campaignAdmins: [CampaignAdminVolunteer] @connection(keyName: "byVolunteer", fields: ["email"])
}
mutation CampaignAdminHasManyVolunteers {
ca1: createCampaignAdmin(input: {email: "[email protected]", firstname: "A", lastname: "BC"}) {
email
firstname
lastname
}
ca2: createCampaignAdmin(input: {email: "[email protected]", firstname: "B", lastname: "CD"}) {
email
firstname
lastname
}
}
mutation createVolunteer {
v1: createVolunteer(input: {email: "[email protected]", firstname: "v1", lastname: "z1"}) {
email
firstname
lastname
}
v2: createVolunteer(input: {email: "[email protected]", firstname: "v2", lastname: "z2"}) {
email
firstname
lastname
}
}
mutation MyMutation {
av1: createCampaignAdminVolunteer(input: {adminEmail: "[email protected]", volunteerEmail: "[email protected]", id: "av1"}) {
id
}
av2: createCampaignAdminVolunteer(input: {adminEmail: "[email protected]", volunteerEmail: "[email protected]", id: "av2"}) {
id
}
bv1: createCampaignAdminVolunteer(input: {adminEmail: "[email protected]", volunteerEmail: "[email protected]", id: "bv1"}) {
id
}
bv2: createCampaignAdminVolunteer(input: {adminEmail: "[email protected]", volunteerEmail: "[email protected]", id: "bv2"}) {
id
}
}
query MyQuery {
getVolunteer(email: "[email protected]") {
email
firstname
lastname
campaignAdmins {
items {
id
campaignAdmin {
firstname
email
lastname
}
}
}
}
}
{
"data": {
"getVolunteer": {
"email": "[email protected]",
"firstname": "v1",
"lastname": "z1",
"campaignAdmins": {
"items": [
{
"id": "av1",
"campaignAdmin": {
"firstname": "A",
"email": "[email protected]",
"lastname": "BC"
}
},
{
"id": "bv1",
"campaignAdmin": {
"firstname": "B",
"email": "[email protected]",
"lastname": "CD"
}
}
]
}
}
}
}
md5-31031e595d26d66bdaa975facb24ddae
```json
{
"data": {
"getCampaignAdmin": {
"email": "[email protected]",
"firstname": "A",
"lastname": "BC",
"volunteers": null
}
},
"errors": [
{
"errorType": "DynamoDB:ValidationException"
}
]
}
Error while executing Local DynamoDB
{
"version": "2017-02-28",
"operation": "Query",
"query": {
"expression": "#connectionAttribute = :connectionAttribute",
"expressionNames": {
"#connectionAttribute": "campaignAdminVolunteersCampaignAdminId"
},
"expressionValues": {
":connectionAttribute": {
"S": "[email protected]"
}
}
},
"scanIndexForward": true,
"filter": null,
"limit": 10,
"nextToken": null,
"index": "gsi-CampaignAdminVolunteers"
}
ValidationException: The table does not have the specified index: gsi-CampaignAdminVolunteers
Something similar is happening here: https://github.com/aws-amplify/amplify-cli/issues/4154
Man but the example is the documentation works perfectly with many to many - is there something wrong with my naming of index?
https://docs.amplify.aws/cli/graphql-transformer/directives#many-to-many-connections
# Schema Problems
## This Example Works:
```graphql
type Post @model {
id: ID!
title: String!
editors: [PostEditor] @connection(keyName: "byPost", fields: ["id"])
}
# Create a join model and disable queries as you don't need them
# and can query through Post.editors and User.posts
type PostEditor
@model(queries: null)
@key(name: "byPost", fields: ["postID", "editorID"])
@key(name: "byEditor", fields: ["editorID", "postID"]) {
id: ID!
postID: ID!
editorID: ID!
post: Post! @connection(fields: ["postID"])
editor: User! @connection(fields: ["editorID"])
}
type User @model {
id: ID!
username: String!
posts: [PostEditor] @connection(keyName: "byEditor", fields: ["id"])
}
mutation CreateData {
p1: createPost(input: { id: "P1", title: "Post 1" }) {
id
}
p2: createPost(input: { id: "P2", title: "Post 2" }) {
id
}
u1: createUser(input: { id: "U1", username: "user1" }) {
id
}
u2: createUser(input: { id: "U2", username: "user2" }) {
id
}
}
mutation CreateLinks {
p1u1: createPostEditor(input: { id: "P1U1", postID: "P1", editorID: "U1" }) {
id
}
p1u2: createPostEditor(input: { id: "P1U2", postID: "P1", editorID: "U2" }) {
id
}
p2u1: createPostEditor(input: { id: "P2U1", postID: "P2", editorID: "U1" }) {
id
}
}
query GetUserWithPosts {
getUser(id: "U1") {
id
username
posts {
items {
post {
title
}
}
}
}
}
I am pretty sure it's me - not the amplify :|
tagging you @yuth - since i see you comment on Schema kinda questions (sorry been stuck at this problems for days now) - need to make some progress on this project.
Can't believe it's actually the variable name that is causing the trouble. If I use a plural name - i get that exception and with singular name (though it should be plural - since it's an array) - IT WORKS :(
This is definitely a bug in the code or a bug in my brain.
Replace this in Schema
volunteers: [CampaignAdminVolunteer] @connection(keyName: "byCampaignAdmin", fields: ["email"])
To This
volunteer: [CampaignAdminVolunteer] @connection(keyName: "byCampaignAdmin", fields: ["email"])
@gautamkshitij is this happening only on mock? Do you see the same issue when you deploy the schema?
I tried using the schema on the first comment (with volunteers) and it worked. I believe this has to something with how mock is having issues generating GSIs.
I am going to mark this as a bug and I will investigate this further.
Yea i never do amplify push since I wanna develop things locally and don't wanna pay until I have a mini working solution. Maybe I should and save my time debugging.
Also here's another issue I filed https://github.com/aws-amplify/amplify-cli/issues/4154 - same as this one (can be marked as bug) @yuth
Most helpful comment
Can't believe it's actually the variable name that is causing the trouble. If I use a plural name - i get that exception and with singular name (though it should be plural - since it's an array) - IT WORKS :(
This is definitely a bug in the code or a bug in my brain.
Replace this in Schema
To This