When building GraphQL APIs, a common pain point is maintaining your schema, types, and resolvers separately—and keeping them in sync.

That’s where Nexus comes in.


🧠 What is nexus?

Nexus is a code-first GraphQL schema builder for JavaScript and TypeScript.

Instead of writing your schema as a GraphQL string, you define it using TypeScript functions. This means:

  • Your types and resolvers live together
  • You get full type safety
  • Your IDE can help you autocomplete, refactor, and navigate the code easily

💡 Why use nexus?

Here’s what makes Nexus popular:

  • 🔒 Strongly typed: Your schema is backed by TypeScript, so you catch errors early.
  • 🚫 No SDL required: You don't need to write separate schema files.
  • 🧩 Composable and modular: You can organize your schema in small, reusable parts.
  • 🤝 Works great with Prisma: Nexus can use your Prisma models to auto-generate GraphQL fields.

🧪 Example: defining a type and a query

Let’s say you want to expose a User type and a me query that returns it.

With Nexus, it looks like this:

import { objectType, queryType, makeSchema } from 'nexus';

const User = objectType({
  name: 'User',
  definition(t) {
    t.id('id');
    t.string('name');
    t.string('email');
  }
});

const Query = queryType({
  definition(t) {
    t.field('me', {
      type: 'User',
      resolve: () => ({
        id: '1',
        name: 'Marta',
        email: 'marta@example.com'
      })
    });
  }
});

This defines both your GraphQL types and the resolver logic in one place—and it’s fully typed.


⚡ Bonus: nexus + prisma

If you use Prisma as your ORM, Nexus becomes even more powerful with the nexus-prisma plugin.

This allows you to do things like:

t.model.name();
t.model.email();

...and automatically connect your Prisma models to your GraphQL schema.

No need to repeat yourself—your database schema and your API stay perfectly aligned.


🧰 When should you use nexus?

You should consider Nexus if:

  • You're working with TypeScript
  • You prefer code-first over SDL
  • You're using Prisma
  • You want scalable, type-safe APIs that are easy to refactor

It’s especially useful in larger projects or teams where type safety and maintainability matter.


✅ Summary

  • Nexus lets you build GraphQL APIs using code instead of SDL
  • It gives you full type safety and better developer experience
  • Great fit for TypeScript + Prisma stacks
  • Cleaner, more maintainable, and easier to scale

🧠 Conclusion

Nexus is more than a schema builder—it's a way to write GraphQL APIs that are safe, predictable, and easy to maintain.

By defining everything in TypeScript, you eliminate duplication, reduce bugs, and keep your codebase consistent.

If you’re building a GraphQL backend in Node.js, especially with Prisma, Nexus is definitely worth adding to your toolbox.