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

Adds GraphQL support. #19

Open
wants to merge 6 commits into
base: master
from

Conversation

@mattstein
Copy link

mattstein commented Oct 2, 2019

This is my first attempt to add first-party GraphQL support to any plugin, but it works great locally. Any given Table Maker field can be queried for its rows, columns, or table markup. If the field handle is myTable, for example, a GraphQL query could include...

myTable {
  rows
  columns {
    heading
    width
    align
  }
  table
}

...and the response would be something like...

{
  "myTable": {
    "rows": [
      [
        "Vultr 32GB",
        "$160/month",
      ],
      [
        "Digital Ocean 16GB CPU",
        "$160/month",
      ],
      [
        "AWS m5.2xlarge",
        "$262.08/month",
      ],
      [
        "Digital Ocean 32GB",
        "$160/month",
      ],
      [
        "Linode 32GB",
        "$160/month",
      ]
    ],
    "columns": [
      {
        "heading": "Provider+Plan",
        "width": "",
        "align": "left"
      },
      {
        "heading": "Cost",
        "width": "",
        "align": "left"
      },
    ],
    "table": "\n            <table>\n                <thead>\n                    <tr>\n        <th align=\"left\" width=\"\">Provider+Plan</th><th align=\"left\" width=\"\">Xeon CPU</th><th align=\"left\" width=\"\">RAM</th><th align=\"left\" width=\"\">Storage</th><th align=\"left\" width=\"\">Cost</th><th align=\"left\" width=\"\">Location</th>\n                    </tr>\n                </thead>\n\n                <tbody>\n\n        <tr><td align=\"left\">Vultr 32GB</td><td align=\"left\">$160/month</td></tr><tr><td align=\"left\">Digital Ocean 16GB CPU</td><td align=\"left\">$160/month</td></tr><tr><td align=\"left\">AWS m5.2xlarge</td><td align=\"left\">$262.08/month</td></tr><tr><td align=\"left\">Digital Ocean 32GB</td><td align=\"left\">$160/month</td></tr><tr><td align=\"left\">Linode 32GB</td><td align=\"left\">$160/month</td></tr><tr>\n\n                </tbody>\n\n            </table>\n        "
  }
}
mattstein added 6 commits Oct 2, 2019
Create the schema type once and re-use that instance.
A type needs to be created or re-used for the nested list of columns. `TypeLoader::registerType()` is unnecessary as of Craft 3.3.12.
@jamesedmonston

This comment has been minimized.

Copy link

jamesedmonston commented Nov 15, 2019

@mattstein Testing this on a site I'm working on and it seems to be working great 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.