API

nexus

import ... from 'nexus'

This section is about the main module of the nexus pacakge. Of all Nexus' modules this is the one you'll find yourself using the most in a Nexus projet. The main nexus module exports an application singleton. It is available as the default module export. The primary components of the application are exposed via properties on the application object. For convenience these components are also exposed as named exports. If you do not like long property chains you might prefer imported the named exports (see examples of either style later in this page). Each named export is documented on its own page. Each named export has a corollary guide page as well. Guides take time to explain concepts and motivations. The API docs focus only on dry technical details of the API.

A Word About Autocomplete

Whichever import style you go with know that you can benefit from TypeScript's auto-import feature. To import the defualt export by name automatically you need to use the same identifier that we use internally. That identifier is app. Type that anywhere and you should see the option to auto-import the default export from nexus.

Example of importing default export

1import app from 'nexus'
2
3app.on.start(() => {
4 app.log.info('Hello World!')
5})
6
7app.settings.change({
8 server: {
9 port: 5689,
10 },
11})
12
13app.schema.queryType({
14 definition(t) {
15 t.string('foo', () => 'bar')
16 },
17})

Example of importing named exports

1import { schema, settings, log, on } from 'nexus'
2
3on.start(() => {
4 log.info('Hello World!')
5})
6
7settings.change({
8 server: {
9 port: 5689,
10 },
11})
12
13schema.queryType({
14 definition(t) {
15 t.string('foo', () => 'bar')
16 },
17})

In this section

Edit this page on Github