无法从端点下载 GraphQL 架构

Cannot download GraphQL schema from endpoint

我目前正在使用 graphql-cli from Prisma 从端点下载架构。但是,即使我部署了对模式所做的更改(部署成功),每当我尝试下载模式时,我都会得到 project prisma - No changes。并且生成的 prisma.graphql 保持不变。

我使用以下命令下载架构:

graphql get-schema -p prisma --dotenv config/dev.env

dev.env简单来说就是获取PRISMA_ENDPOINT=http://localhost:4466/环境变量。

我尝试通过在 prisma.yml 中添加以下内容以不同的方式生成 prisma.graphql

endpoint: ${env:PRISMA_ENDPOINT}
datamodel: datamodel.prisma
generate:
   - generator: graphql-schema
     output: ./generated/

并执行prisma generate,但我得到错误:

▸ [WARNING] in /Users/F/Documents/d/server/prisma/prisma.yml: A valid environment ▸ variable to satisfy the declaration 'env:PRISMA_ENDPOINT' could not be found.

尝试停止并重新创建 Docker 以及删除 node_module 并重新安装,但无济于事。

我的package.json:

{
  "name": "graphql-basics",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node dist/index.js",
    "heroku-postbuild": "babel src --out-dir dist --copy-files",
    "dev": "env-cmd ./config/dev.env nodemon src/index.js --ext js,graphql --exec babel-node",
    "test": "env-cmd ./config/test.env jest --watch --runInBand",
    "get-schema": "graphql get-schema -p prisma --dotenv config/dev.env"
  },
  "jest": {
    "globalSetup": "./tests/jest/globalSetup.js",
    "globalTeardown": "./tests/jest/globalTeardown.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/polyfill": "^7.0.0",
    "babel-cli": "^6.26.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-register": "^6.26.0",
    "bcryptjs": "^2.4.3",
    "cross-fetch": "^2.2.2",
    "env-cmd": "^8.0.2",
    "google-auth-library": "^4.2.3",
    "graphql-cli": "^3.0.14",    
    "graphql-yoga": "^1.14.10",
    "jsonwebtoken": "^8.3.0",
    "prisma-binding": "^2.1.1"
  },
  "devDependencies": {
    "babel-plugin-transform-es2015-destructuring": "^6.23.0",
    "jest": "^23.5.0",
    "nodemon": "^1.17.5"
  },
  "resolutions": {
    "graphql": "^14.5.8"
  }
}

要修复调用 prisma generate 时的错误 "variable to satisfy the declaration 'env:PRISMA_ENDPOINT' could not be found.",您应该手动设置 PRISMA_ENDPOINT 变量或通过 dotenv 加载它。例如,您可以 运行 npx dotenv -- prisma generate 从您的 .env 文件加载环境变量。

要通过 graphql get-schema 从端点下载架构,请确保提供正确配置的 .graphqlconfig.yml 并提供正确的项目。 Prisma 项目的示例配置可能如下所示:

projects:
  prisma:
    schemaPath: 'src/schema.graphql'
    extensions:
      endpoints:
        default: 'http://localhost:4000/graphql'
  database:
    schemaPath: 'src/generated/prisma.graphql'
    extensions:
      prisma: 'database/prisma.yml'
      endpoints:
        default: 'http://localhost:4466'