API

extendType

extendType

Defines a way to incrementally build types, by "extending" a type from multiple locations in a project. Useful in situations where you have types split across multiple domains, each of which should add fields to a single type (like the "Query" root).

1export const AddUserById = extendType({
2 type: 'Query',
3 definition: t => {
4 t.field('userById', {
5 type: 'User',
6 args: { id: intArg('id of the user') },
7 resolve: (root, args, ctx) => ctx.user.getById(args.id),
8 })
9 },
10})
11
12// elsewhere...
13
14export const AddPostById = extendType({
15 type: 'Query',
16 definition: t => {
17 t.field('postById', {
18 type: 'Post',
19 args: { id: intArg('id of the post') },
20 resolve: (root, args, ctx) => ctx.post.getById(args.id),
21 })
22 },
23})

A similar extendInputType is available for extending input types.

Edit this page on Github
Content