GraphQL #

Vizy fields support being queried via GraphQL. To give you the utmost flexibility with rendering content, we provide the full, raw node structure for you to handle however you like.

Using nodes to query your data is the most common scenario.

Query #

{
  entries(section:"blog") {
    ... on vizy_blog_Entry {
      vizyField {
        nodes {
          ... on VizyNode_Paragraph {
            type
            html
          }
          
          ... on vizyField_mediaWithImage_BlockType {
            enabled
            collapsed
            blockTypeId
            blockTypeHandle
            
            plainText
            media {
              id
              title
              url
            }
          }
        }
      }
    }
  }
}

Response #

{
  "data": {
    "entries": [
      {
        "vizyField": {
          "nodes": [
            {
              "type": "paragraph",
              "html": "<p>Wait until you get a load of this</p>"
            },
            {
              "enabled": true,
              "collapsed": false,
              "blockTypeId": "type-yHLnqH7UvJ",
              "blockTypeHandle": "mediaWithImage",
              "plainText": "Where summer happens yo.",
              "media": [
                {
                  "id": "251",
                  "title": "Chilling on the beach",
                  "url": "beach-chill.jpg"
                }
              ]
            }
          ]
        }
      }
    ]
  }
}

In the above example, we're using inline fragments to access the different types of nodes available.

In addition, for a Vizy Block node, we define inline fragments for each block type handle. You'll have access to some attributes of a Vizy Block node, as well as any custom fields. The above example has plainText and media as a Plain Text field and Assets field respectively.

The VizyNodeInterface interface #

This is the interface implemented by all nodes.

FieldTypeDescription
typestringThe type of the node.
tagNamestringThe HTML tag name of the node.
attrsjsonThe attributes of the node.
marksjsonThe marks of the node.
contentjsonThe content of the node as structured node JSON, including nested marks and text content.
htmlstringThe content of the node as rendered HTML.
textstringThe inner text of the node, if applicable.
rawNodejsonThe raw JSON structure for the node, as stored in the database.

Available node type fragments are:

  • VizyNode_Blockquote
  • VizyNode_BulletList
  • VizyNode_CodeBlock
  • VizyNode_HardBreak
  • VizyNode_Heading
  • VizyNode_HorizontalRule
  • VizyNode_Iframe
  • VizyNode_Image
  • VizyNode_ListItem
  • VizyNode_OrderedList
  • VizyNode_Paragraph

The VizyBlockInterface interface #

This is the interface implemented by all Vizy Block nodes.

FieldTypeDescription
typestringThe type of the node.
tagNamestringThe HTML tag name of the node.
attrsarrayThe attributes of the node.
marksarrayThe marks of the node.
contentstringThe content of the node.
enabledbooleanWhether the block is enabled.
collapsedbooleanWhether the block is collapsed.
blockTypeIdstringThe ID of the block type.
blockTypeHandlestringThe handle of the block type.

You can use the rawNodes to return the entire node structure as a JSON string.

Query #

{
  entries(section:"blog") {
    ... on vizy_blog_Entry {
      vizyField {
        rawNodes
      }
    }
  }
}

Response #

{
  "vizyField": {
    "rawNodes": "[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":\"left\"},\"content\":[{\"type\":\"text\",\"text\":\"The name \"},{\"type\":\"text\",\"marks\":[{\"type\":\"link\",\"attrs\":{\"href\":\"https://en.wikipedia.org/wiki/Gin\",\"target\":\"_blank\"}}],\"text\":\"gin\"},{\"type\":\"text\",\"text\":\" is a \"},{\"type\":\"text\",\"marks\":[{\"type\":\"bold\"}],\"text\":\"shortened\"},{\"type\":\"text\",\"text\":\" form of the \"},{\"type\":\"text\",\"marks\":[{\"type\":\"italic\"}],\"text\":\"older\"},{\"type\":\"text\",\"text\":\" English word genever.\"}]}]"
  }
}

Or, you can use renderHtml to return the generated HTML, as determined by Craft.

Query #

{
  entries(section:"blog") {
    ... on vizy_blog_Entry {
      vizyField {
        renderHtml
      }
    }
  }
}

Response #

{
  "vizyField": {
    "renderHtml": "<p class=\"text-left\">The name <a href=\"https://en.wikipedia.org/wiki/Gin\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">gin</a> is a <strong>shortened</strong> form of the <em>older</em> English word genever.</p>"
  }
}

Get started with Vizy

Available for Craft 3. Get it from the plugin store.