Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions docs/content/docs/guides/schema-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,24 @@ import { Context } from '.keystone/types';

export default config({
{/* ... */},
extendGraphqlSchema: graphql.extend(base => {
return {
mutation: {
publishPost: graphql.field({
type: base.object('Post'),
args: { id: graphql.arg({ type: graphql.nonNull(graphql.ID) }) },
resolve(source, { id }, context:Context) {
return context.db.Post.updateOne({
where: { id },
data: { status: 'published', publishDate: new Date().toISOString() },
});
},
}),
},
};
}),
graphql: {
extendGraphqlSchema: graphql.extend(base => {
return {
mutation: {
publishPost: graphql.field({
type: base.object('Post'),
args: { id: graphql.arg({ type: graphql.nonNull(graphql.ID) }) },
resolve(source, { id }, context:Context) {
return context.db.Post.updateOne({
where: { id },
data: { status: 'published', publishDate: new Date().toISOString() },
});
},
}),
},
};
}),
}
});
```

Expand Down Expand Up @@ -80,24 +82,26 @@ which performs the same function as above.
```ts
export default config({
{/* ... */},
extendGraphqlSchema: schema =>
mergeSchemas({
schemas: [schema],
typeDefs: `
type Mutation {
publishPost(id: ID!): Post
`,
resolvers: {
Mutation: {
publishPost: (root, { id }, context) => {
return context.db.Post.updateOne({
where: { id },
data: { status: 'published', publishDate: new Date().toUTCString() },
});
graphql: {
extendGraphqlSchema: schema =>
mergeSchemas({
schemas: [schema],
typeDefs: `
type Mutation {
publishPost(id: ID!): Post
`,
resolvers: {
Mutation: {
publishPost: (root, { id }, context) => {
return context.db.Post.updateOne({
where: { id },
data: { status: 'published', publishDate: new Date().toUTCString() },
});
},
},
},
},
}),
}),
}
});
```

Expand Down