Plugins
Declarative Wrapping (null/list)
Declarative Wrapping
The declarative wrapping plugin adds the pre-0.19 APIs of list: true | boolean[]
, nullable: boolean
, and required: boolean
on field & argument definitions.
To install, add the declarativeWrapping
to the makeSchema.plugins
array, along with any other plugins you'd like to include:
1import { makeSchema, declarativeWrappingPlugin } from 'nexus'23const schema = makeSchema({4 // ... types, etc,5 plugins: [6 // ... other plugins7 declarativeWrappingPlugin(),8 ],9})
You can now use the object style APIs on any args & field definitions.
1export const User = objectType({2 name: 'User',3 definition(t) {4 t.string('someNullField', {5 nullable: true,6 })7 t.string('someRequiredField', {8 nullable: false,9 resolve: () => 'Some Field',10 })11 t.string('someList', {12 list: true,13 resolve: () => [],14 })15 t.string('someListOfLists', {16 list: [true, true],17 args: {18 int: intArg({ required: true }),19 },20 resolve: () => [],21 })22 },23})
If you have migrated to the new chaining / wrapping APIs and would like to disable the typings and make usage a a runtime error, add declarativeWrappingPlugin({ disable: true })
.