tinacms / tina-graphql-gateway

Makes it easier to build TinaCMS websites with a GraphQL Layer.
https://tina.io/cloud
Apache License 2.0
6 stars 2 forks source link

bug: Error in generating forms while listing documents and using `unstable_defineSchema` #349

Closed logan-anderson closed 3 years ago

logan-anderson commented 3 years ago

Is there an existing issue for this?

Current Behavior

Get an error from the CMS that it could not generate forms when listing documents with the new unstable_defineSchema API. I am assuming this just has not been implemented yet @jeffsee55 ?

Expected Behavior

Should not get an error

Steps To Reproduce

Use a list query for example getPostsList in graphql

Environment

- Browser:
- OS: 
- Node: 
- npm:

Your Schema

import { unstable_defineSchema } from "tina-graphql-gateway-cli"

const makeColorField = (name: string, label: string) => {
  return {
    name,
    type: "string",
    label,
    ui: {
      component: "color",
    },
  }
}

const NavItemFields = [
  {
    name: "type",
    type: "string",
    label: "Type",
    options: ["link", "group"],
  },
  {
    name: "slug",
    label: "Slug",
    type: "string",
  },
  {
    name: "title",
    label: "Title",
    type: "string",
  },
  {
    name: "id",
    label: "id",
    type: "string",
  },
  {
    name: "page",
    label: "page",
    type: "reference",
    collections: ["docs"],
  },
]

export default unstable_defineSchema({
  collections: [
    {
      name: "styles",
      label: "Styles",
      path: "content/styles",
      format: "json",
      fields: [
        {
          name: "logo",
          label: "logo",
          type: "string",
        },
        {
          name: "siteName",
          label: "siteName",
          type: "string",
        },
        {
          name: "description",
          label: "description",
          type: "string",
        },
        {
          name: "lineHeights",
          label: "lineHeights",
          type: "object",
          fields: [
            {
              type: "string",
              name: "body",
              label: "body",
              ui: {
                component: "number",
              },
            },
            {
              type: "string",
              name: "heading",
              label: "heading",
              ui: {
                component: "number",
              },
            },
          ],
        },
        {
          name: "fontWeights",
          label: "Font Weights",
          type: "object",
          fields: [
            {
              type: "string",
              name: "body",
              label: "body",
              ui: {
                component: "number",
              },
            },
            {
              type: "string",
              name: "heading",
              label: "heading",
              ui: {
                component: "number",
              },
            },
            {
              type: "string",
              name: "bold",
              label: "Bold",
              ui: {
                component: "number",
              },
            },
          ],
        },
        {
          name: "colors",
          label: "Colors",
          type: "object",
          fields: [
            makeColorField("text", "Text Color"),
            makeColorField("background", "Background Color"),
            makeColorField("primary", "Primary Color"),
            makeColorField("secondary", "Secondary Color"),
            makeColorField("muted", "Muted Color"),
            makeColorField("highlight", "Highlight Color"),
            makeColorField("highlightBorder", "Highlight Border Color"),
            makeColorField("gray", "Gray Color"),
            makeColorField("accent", "Accent Color"),
          ],
        },
        {
          name: "fonts",
          label: "fonts",
          type: "object",
          fields: [
            {
              name: "body",
              label: "body",
              type: "string",
            },
            {
              name: "heading",
              label: "heading",
              type: "string",
            },
            {
              name: "monospace",
              label: "monospace",
              type: "string",
            },
          ],
        },
      ],
    },
    {
      name: "navigation",
      label: "Navigation",
      path: "content/config-sidebar",
      format: "json",
      fields: [
        {
          type: "object",
          list: true,
          label: "Configuration",
          name: "config",
          fields: [
            ...NavItemFields,
            {
              type: "object",
              list: true,
              label: "Child Pages",
              name: "children",
              fields: [
                ...NavItemFields,
                {
                  type: "object",
                  list: true,
                  label: "Child Pages",
                  name: "children",
                  fields: [...NavItemFields],
                },
              ],
            },
          ],
        },
      ],
    },
    {
      label: "Docs",
      name: "docs",
      path: "docs",
      fields: [
        {
          type: "string",
          name: "title",
          label: "Title of page",
        },
        {
          type: "string",
          name: "body",
          label: "Main text of the page",
          isBody: true,
          ui: {
            component: "markdown",
          },
        },
      ],
    },
    {
      label: "Blog Posts",
      name: "posts",
      path: "content/blog",
      fields: [
        {
          type: "string",
          label: "Title",
          name: "title",
        },
        {
          type: "string",
          label: "description",
          name: "description",
        },
        {
          type: "string",
          label: "author",
          name: "author",
        },
        {
          type: "datetime",
          label: "Date",
          name: "date",
          ui: {
            dateFormat: "MMMM DD YYYY",
            component: "date",
          },
        },
        {
          type: "string",
          label: "Body of blog post",
          name: "body",
          isBody: true,
          ui: {
            component: "markdown",
          },
        },
      ],
    },
  ],
})

Your GraphQL Query

query BlogPageQuery {
  getPostsList {
    edges {
      node {
        sys {
            filename
        }
        data {
          title
          author
          date
          description
        }
      }
    }
  }

Anything else?

No response