我的堆栈是:
阿波罗服务器,graphql,prisma,nextjs
我在resolver.ts下为graphql配置添加了一个/graphql和schema.ts
resolver.ts
export const resolvers = {
Query: {
books: () => books,
},
};
const books = [
{
title: 'The Awakening',
author: 'Kate Chopin',
},
{
title: 'City of Glass',
author: 'Paul Auster',
},
];schema.ts
import { gql } from "apollo-server-micro";
export const typeDefs = gql`
# This "Book" type defines the queryable fields for every book in our data source.
type Book {
title: String
author: String
}
# The "Query" type is special: it lists all of the available queries that
# clients can execute, along with the return type for each. In this
# case, the "books" query returns an array of zero or more Books (defined above).
type Query {
books: [Book]
}/pages/api/graphql.ts
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { ApolloServer } from 'apollo-server-micro';
import { typeDefs } from '../../graphql/schema';
import { resolvers } from '../../graphql/resolver';
const apolloServer = new ApolloServer ({typeDefs, resolvers});
const startServer = apolloServer.start();
export default async function handler(req, res) {
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader(
'Access-Control-Allow-Origin',
'https://studio.apollographql.com'
);
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
if (req.method === 'OPTIONS') {
res.end();
return false;
}
await startServer;
await apolloServer.createHandler({
path: "/api/graphql",
})(req, res);
}
export const config = {
api: {
bodyParse: false
}
}当我导航到api端点/api/graphql时,它会带我到阿波罗工作室浏览器,但它不会选择端点或模式。开发工具中的错误似乎是工作室库,特别是它们似乎没有多大帮助:
StaleWhileRevalidate.js:112 Uncaught (in promise) no-response: no-response :: [{"url":"https://cdn.segment.com/analytics.js/v1/xPczztcxJ39mG3oX3wle6XlgpwJ62XAA/analytics.min.js"}]
at O._handle (https://studio.apollographql.com/service-worker.js:2:71211)
at async O._getResponse (https://studio.apollographql.com/service-worker.js:2:47966)
_handle @ StaleWhileRevalidate.js:112
useTelemetryInitializer.ts:174 GET https://cdn.segment.com/analytics.js/v1/xPczztcxJ39mG3oX3wle6XlgpwJ62XAA/analytics.min.js net::ERR_FAILED我不认为这与prisma有任何关系,因为我所做的就是设置postgresql并定义一些基本模式。不要明白为什么工作室没有选择我的端点,它似乎不是与CORS相关的,因为我没有得到跨源错误。
工作室截图:

发布于 2022-07-11 15:14:06
如果为时已晚,我很抱歉,但唯一能帮我解决问题的方法是清理网站的存储空间。
https://stackoverflow.com/questions/71450834
复制相似问题