verbb / vizy

A flexible visual editor for Craft CMS
Other
44 stars 8 forks source link

When querying for the id or uid fields using graphql on Nodes you get an error #53

Closed Kethatril closed 3 years ago

Kethatril commented 3 years ago

Description When querying for the id and uid fields on Nodes in graphql you will get an error

Getting unknown property: verbb\vizy\nodes\Paragraph::id However the schema says that Nodes support those two fields.

Steps to reproduce

  1. Query for a vizy field in graphql and add the uid and/or id fields to the query of any node e.g:
    vizyField {
      nodes {
        ... on VizyNode_Paragraph {
          type
          content
          id
          uid
       }
     }
    }
  2. Notice the error Getting unknown property: verbb\\vizy\\nodes\\Paragraph::id

Additional info

engram-design commented 3 years ago

That'd be correct, the id and uid properties on a node doesn't exist. This is because each node is just an individual bit of JSON storing the attributes of a node. Basically: [{"type":"paragraph","content":[{"type":"text","text":"Some text"}]}] - which when unserialized, creates a Paragraph node instance, which is just a model.

Kethatril commented 3 years ago

Yeah I knew why, probably shouldn't part of the schema for Paragraphs if they throw errors though. (The graphql explorer auto adds the id field every time you add a node type atm)

Do any Node types have uid/id, if not it might be worth not merging in the parent field definitions here: https://github.com/verbb/vizy/blob/dc68f50efad565a53c5c205f484b2d793d559812/src/gql/interfaces/VizyNodeInterface.php#L50-L70 if they are never used to prevent them from coming up on the interface (If that works at least)?

engram-design commented 3 years ago

Ah, interesting, I forgot that it'll auto-suggest those attributes. I'll see what I can do to remove those, as they shouldn't be there. I imagine it's just inherited from the default interface - as you've mentioned.

engram-design commented 3 years ago

Fixed for the next release. To get the fix early, change your verbb/vizy requirement in composer.json to:

"require": {
  "verbb/vizy": "dev-craft-3 as 1.0.6",
  "...": "..."
}

Then run composer update.

engram-design commented 3 years ago

Fixed in 1.0.7