Skip to content

next.js 15 build errorΒ #3454

@rfw

Description

@rfw

Describe the bug

// Next.js Custom Route Handler: https://nextjs.org/docs/app/building-your-application/routing/router-handlers
import { createSchema, createYoga } from 'graphql-yoga'
import type { NextApiRequest, NextApiResponse } from 'next'

const { handleRequest } = createYoga({
  schema: createSchema<{
    req: NextApiRequest
    res: NextApiResponse
  }>({
    typeDefs: /* GraphQL */ `
      type Query {
        greetings: String
      }
    `,
    resolvers: {
      Query: {
        greetings: () => 'This is the `greetings` field of the root `Query` type'
      }
    }
  }),

  // While using Next.js file convention for routing, we need to configure Yoga to use the correct endpoint
  graphqlEndpoint: '/api/graphql',

  // Yoga needs to know how to create a valid Next response
  fetchAPI: {
    Response: Response,
    Request: Request,
  },
})

export { handleRequest as GET, handleRequest as POST, handleRequest as OPTIONS }

Error log

yarn build
yarn run v1.22.22
$ next build
   β–² Next.js 15.0.2
   - Environments: .env.local, .env

   Creating an optimized production build ...
 βœ“ Compiled successfully
   Linting and checking validity of types  .Failed to compile.

.next/types/app/api/graphql/route.ts:49:7
Type error: Type '{ __tag__: "GET"; __param_position__: "second"; __param_type__: Partial<ServerAdapterInitialContext>; }'
 does not satisfy the constraint 'ParamCheck<RouteContext>'.
  Types of property '__param_type__' are incompatible.
    Property 'params' is missing in type 'Partial<ServerAdapterInitialContext>' but required in type 'RouteContext'.

  47 |     Diff<
  48 |       ParamCheck<RouteContext>,
> 49 |       {
     |       ^
  50 |         __tag__: 'GET'
  51 |         __param_position__: 'second'
  52 |         __param_type__: SecondArg<MaybeField<TEntry, 'GET'>>
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Your Example Website or App

not

Steps to Reproduce the Bug or Issue

nextjs 15

https://the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-nextjs

Expected behavior

No error

Screenshots or Videos

image

Platform

  • OS: Windows
  • NodeJS: 21.7.3
  • @graphql-yoga/* version(s):5.8.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions