API

queryField

queryField

Often times you want to split up query fields into different domains of your application, and like mutationField are another one of the most common use-cases for extendType. queryField exists as a shorthand for this common case:

1import { stringArg } from 'nexus'
2
3export const usersQueryField = queryField('user', {
4 type: SomeType,
5 args: {
6 id: nonNull(stringArg()),
7 },
8 resolve() {
9 // ...
10 },
11})

as shorthand for:

1export const usersQueryField = extendType({
2 type: 'Query',
3 definition(t) {
4 t.field('user', {
5 type: SomeType,
6 args: {
7 id: nonNull(stringArg()),
8 },
9 resolve() {
10 // ...
11 },
12 })
13 },
14})

You can also use it with a function as the first argument, which will pass the t provided to the definition block, especially useful when using with the connection plugin:

1export const usersQueryField = queryField(t => {
2 t.connectionField('users', {
3 type: SomeType,
4 resolve() {
5 // ...
6 },
7 })
8})
Edit this page on Github
Content