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

Is GraphQL Mutation working? #449

Open
scandella opened this issue Jan 21, 2022 · 3 comments
Open

Is GraphQL Mutation working? #449

scandella opened this issue Jan 21, 2022 · 3 comments

Comments

@scandella
Copy link

scandella commented Jan 21, 2022

I'm unable to get a GraphQL mutation working with Super Table using Craft 3.7.30.
I think the mutation syntax is OK and the query runs fine, the entry is created but the SuperTable field is never populated.

I've made a basic test, with a Matrix field and a SuperTable field:

mutation TestSupertable {
   title: "Test"
    matrixTest: {blocks: 
      {matrixtestbloc: {matrixtestfield: "Test Matrix", id: "New1"}}, sortOrder: "New1"}
    supertableTest: {blocks: 
      {supertableTest_0: {supertabletestfield: "Test SuperTable", id: "New2"}}, sortOrder: "New2"}
  ) {
    id
  }
}

The Matrix field is correctly populated, but the Super Table one remains empty.

Is mutation for Super Table working for you?

@engram-design
Copy link
Member

Looks like there might've been an issue with the Block Type ID handling in 2.7.1 which was to fix another error.

I can confirm the below works for a Super Table field, a Matrix field, and a Super Table + Matrix field (in that order, included for comparison).

mutation TestSupertable {
  save_sectionHandle_entryTypeHandle_Entry(
    title: "Test"
    matrixField: {
      blocks: {
        block1: {
          id: "new1",
          plainText: "Test Matrix"
        }
      },
      sortOrder: "new1"
    }
    superTableField: {
      blocks: {
        type_1234: {
          id: "new2",
          plainText: "Test SuperTable"
        }
      },
      sortOrder: "new2"
    }
    matrixSuperTableField: {
      blocks: {
        block1: {
          id: "new3",
          matrixSuperTableNestedField: {
            blocks: {
              type_4567: {
                id: "new4",
                plainText: "Test SuperTable"
              }
            },
            sortOrder: "new4"
          }
        }
      },
      sortOrder: "new3"
    }
  ) {
    id
    
    matrixField {
      ... on matrixField_block1_BlockType {
        id
      }
    }
    
    superTableField {
      ... on superTableField_BlockType {
        id
      }
    }
    
    matrixSuperTableField {
        ... on matrixSuperTableField_block1_BlockType {
          id
          
          matrixSuperTableNestedField {
            ... on matrixSuperTableNestedField_BlockType {
              id
              plainText
            }
          }
        }
      }
  }
}

You'll notice the above type_1234 and type_4567 keys, which mimics Matrix. But while Matrix has block handles, Super Table doesn't, and relies on IDs. We have to prefix them with type_ because of how typecasting works in GraphQL.

To get the fix early, change your verbb/super-table requirement in composer.json to:

"require": {
  "verbb/super-table": "dev-craft-3 as 2.7.1",
  "...": "..."
}

Then run composer update.

@vuolter
Copy link

vuolter commented Feb 8, 2022

Hello @engram-design , thank you for the hotfix and the hint!

I've tried the latest dev-craft-3 but I'm still experiencing the same behaviour reported by @scandella on craft 3.7.30 and 3.7.31.

The entry is created, in my case for a static super-table field, but it's never populated, other fields like title are filled in as usual.

@bzin
Copy link

bzin commented Jul 1, 2022

Hi @engram-design ,

I am also having the same issue as @vuolter and @scandella mentioned.

I am sending the data as you shown in your comment but it just returns me the data I currently have. I want to update the data of an exist entry without any success.

mutation SaveMatch($id: ID) {
  save_userMatch_match_Entry(
    id: $id
    matchPlayers: {blocks: [{type_12: {id: "new1", playerName: "Test", playerUid: "Test uid"}}, {type_12: {id: "new2", playerName: "Test", playerUid: "Test uid"}}]}
  ) {
    id
    matchPlayers {
      ... on matchPlayers_BlockType {
        playerUid
        playerName
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants