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: `unstable_defineSchema` does not start #344

Closed logan-anderson closed 3 years ago

logan-anderson commented 3 years ago

Is there an existing issue for this?

Current Behavior

When using the new unstable_defineSchema from tina-graphql-gateway-cli it will not launch the dev server.

Expected Behavior

It should start the graphql server.

Steps To Reproduce

With this package.json

{
  "name": "tina-alpaca",
  "version": "0.1.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "next",
    "debug": "NODE_OPTIONS='--inspect' next",
    "build": "next build",
    "start": "cross-env NODE_ENV=production next start",
    "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
    "create-indices": "npx babel-node ./indices/createIndices.js",
    "tina-dev": "yarn tina-gql server:start -c \"next dev\"",
    "tina-build": "yarn tina-gql server:start -c \"next build\"",
    "tina-start": "yarn tina-gql server:start -c \"next start\""
  },
  "keywords": [
    "nextjs",
    "tinaCMS"
  ],
  "author": "Forestry.io",
  "license": "MIT",
  "dependencies": {
    "@tinacms/api-git": "^0.39.0",
    "@tinacms/git-client": "^0.39.0",
    "@zeit/next-sass": "^1.0.1",
    "algoliasearch": "^4.1.0",
    "axios": "^0.21.1",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "fast-glob": "^3.2.5",
    "file-loader": "^6.0.0",
    "final-form-calculate": "^1.3.1",
    "gray-matter": "^4.0.2",
    "markdown-toc": "^1.2.0",
    "moment": "^2.24.0",
    "next": "^10.1.3",
    "next-svgr": "^0.0.2",
    "next-tinacms-github": "0.41.1",
    "next-tinacms-json": "^0.40.0",
    "next-tinacms-markdown": "0.41.1",
    "node-sass": "^4.13.1",
    "raw-loader": "^4.0.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-instantsearch-dom": "^6.8.3",
    "react-markdown": "^4.3.1",
    "react-syntax-highlighter": "^12.2.1",
    "react-textarea-autosize": "^8.2.0",
    "react-tinacms-editor": "0.41.1",
    "react-tinacms-github": "0.41.1",
    "react-tinacms-inline": "0.41.1",
    "remarkable": "^2.0.0",
    "slugify": "^1.4.6",
    "styled-components": "^5.3.0",
    "styled-normalize": "^8.0.7",
    "tina-graphql-gateway": "^0.0.0-2021612235411",
    "tina-graphql-gateway-cli": "^0.0.0-2021612235411",
    "tinacms": "0.41.1",
    "typeface-source-code-pro": "^1.1.3"
  },
  "devDependencies": {
    "@babel/core": "^7.12.10",
    "@babel/node": "^7.12.10",
    "@types/node": "^14.14.22",
    "babel-eslint": "^10.1.0",
    "babel-plugin-inline-react-svg": "^1.1.2",
    "babel-plugin-styled-components": "^1.10.7",
    "cross-env": "^7.0.3",
    "eslint": "^7.5.0",
    "eslint-config-prettier": "^6.10.1",
    "eslint-plugin-prettier": "^3.1.4",
    "eslint-plugin-react": "^7.20.3",
    "husky": "^4.3.8",
    "hygen-next-tinacms-github": "https://github.com/dwalkr/hygen-next-tinacms-github",
    "lint-staged": "^10.5.3",
    "prettier": "2.0.2"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "**/*.{js,jsx,json}": [
      "prettier --write"
    ]
  }
}

and this Schema.ts


import { defineSchema, unstable_defineSchema } from "tina-graphql-gateway-cli";

export default unstable_defineSchema({
  collections: [
    {
      label: "Docs",
      name: "docs",
      path: "docs",
      templates:[
        {
          name: 'doc',
          label: 'doc',
          fields: [
            {
              type: 'text',
              name: "title",
              label: "Title of page",
            },
          ]
        }
        ]
    },
    {
      label: "Blog Posts",
      name: "posts",
      path: "content/posts",
      templates: [
        {
          label: "Article",
          name: "article",
          fields: [
            {
              type: "text",
              label: "Title",
              name: "title",
            },
          ],
        },
      ],
    },
  ],
});

Note that this works with defineSchema but not with unstable_defineSchema. This error happens when the dev servers starts.

➜  forestry-handbook git:(tina-cloud) ✗ yarn tina-dev
yarn run v1.22.10
warning ../../../package.json: No license field
$ yarn tina-gql server:start -c "next dev"
warning ../../../package.json: No license field
$ /Users/logananderson-forestry-mac/dev/forestry.io/forestry-handbook/node_modules/.bin/tina-gql server:start -c 'next dev'

Started Filesystem GraphQL server on port: 4001
Visit the playground at http://localhost:4001/altair/
Generating Tina config
Compiling...
Transpiling...
Cannot read property 'collections' of undefined
✨  Done in 10.17s.

Environment

- Browser: Brave
- OS: MAC
- Node: v14.15.0
- npm: npm@6.14.8

Your Schema

import { defineSchema, unstable_defineSchema } from "tina-graphql-gateway-cli";

export default unstable_defineSchema({
  collections: [
    {
      label: "Docs",
      name: "docs",
      path: "docs",
      templates:[
        {
          name: 'doc',
          label: 'doc',
          fields: [
            {
              type: 'text',
              name: "title",
              label: "Title of page",
            },
            // {
            //   type: 'textarea',
            //   name: "body",
            //   label: "Main text of the page",
              // isBody: true,
              // ui: {
              //   component: 'markdown'
              // }
            // }
          ]
        }
        ]
    },
    {
      label: "Blog Posts",
      name: "posts",
      path: "content/posts",
      templates: [
        {
          label: "Article",
          name: "article",
          fields: [
            {
              type: "text",
              label: "Title",
              name: "title",
            },
          ],
        },
      ],
    },
  ],
});

Your GraphQL Query

No response

Anything else?

No response

logan-anderson commented 3 years ago

Found the issue (this is my fault) I needed to add the --experimental flag in my dev script.

"tina-dev": "yarn tina-gql server:start -c \"next dev\" --experimental","
tina-build": "yarn tina-gql server:start -c \"next build\" --experimental",
"tina-start": "yarn tina-gql server:start -c \"next start\" --experimental"