After updating to NextJS 13.5 I started seeing these errors when deployed on Vercel (but works fine locally):
Error: Schema must contain uniquely named types but contains multiple types named "h". at new GraphQLSchema (/var/task/node_modules/.pnpm/[email protected]/node_modules/graphql/type/schema.js:219:15)
My init code is pretty straightforward in the serverless function:
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);
This seems to be related to Next optimisations given there are no types named 'h'. Is there a way to ensure every unique name generated as part of optimization's is unique?
The issue is from server side optimisation that minifies class names, which type-graphql relies on to generate its schema.
To disable serverside optimisation only (and prevent bloat on thefrontend) you can set this in your next.config
Looks like it was turned on in 13.5 by default and the cause of the issues.