Tomek Poniatowicz
1/4/2021
GraphQL Nexus is a library to build code-first GraphQL APIs that relies on Node.js and TypeScript. The code-first approach prioritizes the process of developing schema resolvers over the process of designing the schema. This approach puts resolvers in a leading position of a GraphQL project and making a schema shape dependent on resolvers (schema is implemented programmatically).
The key features provided by Nexus are:
Having figured out all the types you need for your schema all you need to do is simply use makeSchema
function to create the schema instance that would be used as the foundation for your GraphQL server.
Besides the fresh package name nexus
which implicates the new way of importing things (use nexus
instead of @nexus/schema
)
import { makeSchema } from 'nexus'
GraphQL Nexus 1.0 provides some important improvements and changes to the project among which we can find:
Abstract Types - version 1.0 offers API for implementing three approaches to abstract types (unions & interfaces) known from the official graphql-js
package:
resolveType
) - discriminating union member types in a centralized way,__typename
) - discriminating union member types in a modular way.isTypeOf
) - discriminating union member types in a modular way.
All along with the type safety.Changes to Backing Types - in version 1.0 backing
and root
types are globally referred to as Source Types
.
Along with this spotlight changes version 1.0 introduced some smaller ones, not directly connected to the project codebase, but not less important i.e. upgraded documentation, guides and new codesandbox examples (intro, subscriptions, next.js).