-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce Nexus example to define extension inline #8375
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d75a708
use ^1.3.0 nexus
dcousens b330c9f
use seconds as a smaller example
dcousens ee829f8
reduce nexus example down, use existing schema merged
dcousens 123037d
add missing nexus argument types, tidy up
dcousens a211c87
add shouldGenerateArtifacts
dcousens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nexus/nexus-typegen.ts | ||
nexus-types.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import path from 'path'; | ||
import type { GraphQLSchema } from 'graphql'; | ||
import { list } from '@keystone-6/core'; | ||
import { allowAll } from '@keystone-6/core/access'; | ||
import { select, relationship, text, timestamp } from '@keystone-6/core/fields'; | ||
import { mergeSchemas } from '@graphql-tools/schema'; | ||
import * as nexus from 'nexus'; | ||
import type { Context, Lists } from '.keystone/types'; | ||
import type { Lists } from '.keystone/types'; | ||
|
||
export const lists: Lists = { | ||
Post: list({ | ||
|
@@ -40,18 +40,20 @@ export function extendGraphqlSchema(baseSchema: GraphQLSchema) { | |
t.field('nexusPosts', { | ||
type: nexus.nonNull(nexus.list('Post')), | ||
args: { | ||
authorId: nexus.stringArg(), | ||
id: nexus.nonNull(nexus.stringArg()), | ||
seconds: nexus.nonNull(nexus.intArg({ default: 600 })), | ||
}, | ||
async resolve(root, { authorId, seconds }, context: Context) { | ||
|
||
async resolve(root, { id, seconds }, context) { | ||
const cutoff = new Date(Date.now() - seconds * 1000); | ||
|
||
return await context.db.Post.findMany({ | ||
where: { | ||
...(authorId ? { author: { id: authorId } } : null), | ||
publishDate: { gt: cutoff }, | ||
}, | ||
}); | ||
// Note we use `context.db.Post` here as we have a return type | ||
// of [Post], and this API provides results in the correct format. | ||
// If you accidentally use `context.query.Post` here you can expect problems | ||
// when accessing the fields in your GraphQL client. | ||
return context.db.Post.findMany({ | ||
where: { author: { id: { equals: id } }, publishDate: { gt: cutoff } }, | ||
}) as Promise<Lists.Post.Item[]>; // TODO: nexus doesn't like <readonly Post[]> | ||
}, | ||
}); | ||
}, | ||
|
@@ -85,6 +87,13 @@ export function extendGraphqlSchema(baseSchema: GraphQLSchema) { | |
mergeSchema: { | ||
schema: baseSchema, | ||
}, | ||
outputs: { | ||
typegen: path.join(process.cwd(), 'nexus-types.ts'), | ||
}, | ||
contextType: { | ||
module: path.join(process.cwd(), 'node_modules', '.keystone', 'types.d.ts'), | ||
export: 'Context', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if I prefer this to |
||
}, | ||
types: { | ||
NexusThing, | ||
NexusPostQuery, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inline with our other examples