【问题标题】:Apollo Server studio not picking up schema from apollo set upApollo Server studio 未从 apollo 设置中获取模式
【发布时间】:2022-07-11 23:14:06
【问题描述】:

我的堆栈是:

阿波罗服务器, 图形, 棱镜, 下一个js

我在 /graphql 下为我的 graphql 配置添加了 resolver.ts 和 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 时,它会将我带到 apollo studio explorer,但它没有获取端点或架构。开发工具中的错误似乎是工作室库,特别是它们似乎没有多大帮助:

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 无关,因为我没有收到跨源错误。

工作室截图:

【问题讨论】:

    标签: javascript graphql next.js apollo-server prisma


    【解决方案1】:

    如果为时已晚,我很抱歉,但为我解决此问题的一件事是清理网站的存储

    【讨论】:

      猜你喜欢
      • 2021-07-31
      • 2019-02-13
      • 2020-09-25
      • 2020-11-08
      • 2021-02-05
      • 2021-01-09
      • 1970-01-01
      • 2022-06-30
      相关资源
      最近更新 更多