next.js InvalidDatasourceError:数据库URL必须使用prisma:// protocol

px9o7tmv  于 2024-01-07  发布在  其他
关注(0)|答案(1)|浏览(77)

我开发了一个Nextjs应用程序。该应用程序在本地工作,无论是在开发和生产模式下,使用云中的数据。在vercel上构建工作,应用程序工作,但如果我尝试使用我的数据库,我会在日志中得到这个错误:
InvalidDatasourceError:当使用--accelerate或--data-proxy时,数据库URL必须使用prisma:// protocol

API/graphql:加载资源失败:服务器响应状态为405
在浏览器控制台上。
/graphql/builder.ts:

import SchemaBuilder from '@pothos/core';
import PrismaPlugin from '@pothos/plugin-prisma';
import RelayPlugin from '@pothos/plugin-relay';
import type PrismaTypes from '@pothos/plugin-prisma/generated';
import prisma from '../lib/prisma';

export const builder = new SchemaBuilder<{
  PrismaTypes: PrismaTypes;
}>({
  plugins: [PrismaPlugin, RelayPlugin],
  relayOptions: {},
  prisma: {
    client: prisma,
  },
});

builder.queryType({});
builder.mutationType({});

字符串
/lib/apollo.ts:

import { ApolloClient, InMemoryCache } from '@apollo/client';

export const apolloClient = new ApolloClient({
  uri: '/api/graphql',
  cache: new InMemoryCache(),
});


/lib/prisma.ts:

import { PrismaClient } from '@prisma/client';

let prisma: PrismaClient;

declare global {
  var prisma: PrismaClient;
}

if (process.env.NODE_ENV === 'production') {
  prisma = new PrismaClient();
} else {
  if (!global.prisma) {
    global.prisma = new PrismaClient();
  }
  prisma = global.prisma;
}

export default prisma;


/API/graphql.ts:

import { schema } from '../../graphql/schema';
import { createYoga } from 'graphql-yoga';
import { NextApiRequest, NextApiResponse } from 'next';

export default createYoga<{
  req: NextApiRequest;
  res: NextApiResponse;
}>({
  schema,
  graphqlEndpoint: process.env.GRAPHQL_API,
});

export const config = {
  api: {
    bodyParser: false,
  },
};


/prisma/schema.prisma:

generator client {
  provider = "prisma-client-js"
}

generator pothos {
  provider = "prisma-pothos-types"
}

datasource db {
  provider     = "mysql"
  url          = env("DATABASE_URL")
  relationMode = "prisma"
}


My.env:

DATABASE_URL_development=mysql://<user>:<pass>@<host>/<myDB>?sslaccept=strict


package.json:

...
[email protected]
[email protected]
[email protected]
@apollo/[email protected]
@apollo/[email protected]
@prisma/[email protected]
[email protected]
...


和生产构建脚本:

"vercel-build": "npx prisma generate --data-proxy && next build",


任何提示都很感激。谢谢。

j8yoct9x

j8yoct9x1#

你需要链接如上所述的plantscale的新连接字符串,并将其与Prisma中的数据代理链接,然后当你试图生成数据时,你将使用mysql://,并且你需要使用prisma/client/edge
你还需要编辑连接字符串回到prisma://
更新
Prisma已将DataProxy迁移到与DataProxy类似的Accelerate

相关问题