DEV Community

Cover image for Upgrading from graphql-yoga v2 to v4
Ken Fukuyama
Ken Fukuyama

Posted on

Upgrading from graphql-yoga v2 to v4

Key Points on Upgrading from graphql-yoga v2 to v4

This article outlines a tricky point when upgrading graphql-yoga v2 to v4. For a comprehensive migration guide, please refer to the official migration guide.

1. Removal of endpoint and graphiql.endpoint options

One of the significant changes in v4 is the removal of the endpoint and graphiql.endpoint options. This can have implications, especially for those using express alongside.

2. Changes in the Configuration Approach

The configuration method in v2 was as follows:

const graphQLServer = createServer({
  //... previous configuration details
})
Enter fullscreen mode Exit fullscreen mode

In v4, the new configuration method is:

const graphQLServer = createYoga({
  schema: createSchema({
    //... new configuration details
  }),
});
Enter fullscreen mode Exit fullscreen mode

3. Changes regarding the Endpoint

In v4, the default endpoint is set to /graphql. If you want to use an alternate endpoint, you'll need to explicitly specify it using the graphqlEndpoint option.

For instance, in v2, setting the endpoint to /graphql-other worked seamlessly:

//... 
app.use('/graphql-other', graphQLOtherServer);
Enter fullscreen mode Exit fullscreen mode

However, with the same setup in v4, you would encounter a NOT FOUND error.

The solution is:

const graphQLOtherServer = createYoga({
  graphqlEndpoint: '/graphql-other', // explicitly setting the endpoint
  //... other configurations
});

app.use('/graphql-other', graphQLOtherServer);
Enter fullscreen mode Exit fullscreen mode

This change can be a bit tricky, so it's crucial to be aware to avoid potential pitfalls during the upgrade.


I hope this sheds light on some nuances of the upgrade process and helps you navigate any challenges smoothly.

Top comments (0)