next.js 具有graphql-codegen端点错误的Vercel应用程序找不到以下指针的任何GraphQL类型定义

hivapdat  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(118)

我加载我的GraphQL模式如下:

const schema = loadSchemaSync('./src/graphql/server/schema/*.gql', {
  loaders: [new GraphQLFileLoader()],
})

这在本地工作正常,但是当部署到vercel时,我得到错误:

Unable to find any GraphQL type definitions for the following pointers:
          - ./src/graphql/server/schema/*.gql

我认为这是因为vercel在构建后删除了相关文件?

snvhrwxg

snvhrwxg1#

问题是您无法在Vercel无服务器函数中使用dynamic loaders
此问题的解决方法是使用内联GraphQL模式。

// src/graphql/schema.ts

import { gql } from "apollo-server-core";

export default gql`
  type Query {
    greet: String!
  }
`;
// src/pages/api/graphql.ts

import { ApolloServerPluginLandingPageGraphQLPlayground } from "apollo-server-core";

import Schema from "../../graphql/schema";

const apolloServer = new ApolloServer({
  typeDefs: Schema,
  resolvers,
  plugins: [ApolloServerPluginLandingPageGraphQLPlayground],
  introspection: true,
});

如果您正在使用codegen等工具:

// codegen.ts

import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  schema: "src/graphql/schema.ts",
  documents: ["./src/**/*.{ts,tsx}"],
  ignoreNoDocuments: true,
  generates: {
    "src/graphql/types/server.ts": {
      plugins: [
        "@graphql-codegen/typescript",
        "@graphql-codegen/typescript-resolvers",
      ],
    },
    "src/graphql/types/client/": {
      preset: "client",
      plugins: [],
    },
  },
};

export default config;

相关问题