API

queryField


CONTENT

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/schema'
2
3export const usersQueryField = queryField('user', {
4 type: SomeType,
5 args: { id: stringArg({ required: true }) },
6 resolve() {
7 // ...
8 },
9})

as shorthand for:

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

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