4. Wrap-up

Wrapping up

Our server implementation is looking good, but there's still a couple of places we're using old packages.


Let's jump into src/schema.js. At the top of the file, we'll see that we're requiring gql from apollo-server.

const { gql } = require("apollo-server");

This is where the graphql-tag package we installed comes in! Let's update the import to use this package instead. (And take note that we're now requiring gql as the default export!)

- const { gql } = require("apollo-server");
+ const gql = require("graphql-tag")

Under the hood, apollo-server (AS3) used gql from graphql-tag directly, and re-exported it for our use under the named export gql.

The new @apollo/server package no longer exports this utility directly; that's why we installed it ourselves. We can use the graphql-tag package directly and get the same functionality we had before.


For our final update, navigate to src/datasources/track-api.js. You'll find that we're requiring the old apollo-datasource-rest package.

This is a simple update! Let's swap it out for the new @apollo/datasource-rest package — everything else can stay the same.

- const { RESTDataSource } = require('apollo-datasource-rest');
+ const { RESTDataSource } = require('@apollo/datasource-rest');

Note: The new @apollo/datasource-rest package uses a slash (/) instead of a dash (-) between the words "apollo" and "datasource".

Launching the server

We've made all the necessary updates to implement the newest 4 packages and features. Let's take it for a spin!

In the root directory of your project, run npm start.

npm start

We should see the same message logging out where our server is running. But when we navigate to localhost:4000, we skip the landing page and go right to the Sandbox Explorer. Our server is ready to right away!

query GetTrackTitles {
tracksForHome {

Trying out the above , we get the exact same data back. Our server enjoys the same functionality as before, but under the hood we've got a lot more flexibility.

Servers built with 4 are easier to maintain and extend than ever before. These benefits prove vital for building a that can scale wherever your product — and imagination! — takes it.

To learn more about other features available now in , visit the official documentation on migrating to version 4.

Thanks for joining us, and we'll see you in the next one!


Share your questions and comments about this lesson

Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.

You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.