NextJS 13.5 导致 graphql 架构错误

问题描述 投票:0回答:1

更新到 NextJS 13.5 后,我在 Vercel 上部署时开始看到这些错误(但在本地工作正常):

错误:模式必须包含唯一命名的类型,但包含多个 名为“h”的类型。 在新的 GraphQLSchema (/var/task/node_modules/.pnpm/[email protected]/node_modules/graphql/type/schema.js:219:15)

我的初始化代码在无服务器功能中非常简单:

const schema = buildSchemaSync({
        authChecker: UserAuthority,
        resolvers: [...]
    });

    const plugins = [
        // Install a landing page plugin based on NODE_ENV
        process.env.NODE_ENV === 'production'
            ? ApolloServerPluginLandingPageProductionDefault({
                graphRef: 'my-graph-id@my-graph-variant',
                footer: false,
            })
            : ApolloServerPluginLandingPageLocalDefault({ footer: false }),
    ];

    const server = new ApolloServer({
        schema,
        introspection: true,
        csrfPrevention: true,
        plugins,
        cache: 'bounded'
        // enable GraphQL Playground
    });

    const handler = startServerAndCreateNextHandler(server, {
        context
    })
    await handler(req, res);

这似乎与下一步优化有关,因为没有名为“h”的类型。有没有办法确保优化过程中生成的每个唯一名称都是唯一的?

next.js graphql apollo vercel typegraphql
1个回答
0
投票

这可能有点激烈,但您可以尝试在 Next.js 的 Webpack 配置中禁用最小化。

next.config.js

config.optimization.minimize = false;

根据https://webpack.js.org/configuration/optimization/#optimizationminimize

如果不出意外,它可能有助于缩小您现在收到的错误的原因。

© www.soinside.com 2019 - 2024. All rights reserved.