Skip to content
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

Add an example using Nexus to extend the Keystone schema #6792

Merged
merged 22 commits into from
Nov 11, 2021
Merged

Conversation

JedWatson
Copy link
Member

@JedWatson JedWatson commented Oct 14, 2021

This came up on Slack, and I was interested in testing out how to use Nexus to extend Keystone's GraphQL API. So I wrote up this example.

Turns out it's pretty neat, although there are a couple of limitations that we could improve in the future:

  • Nexus really wants you to run a watch process while you're coding, to regenerate types as you work. Since Keystone doesn't do hot reloading at the moment, I've added a dev-nexus script which is completely hacky but gets the job done. not a problem anymore with the live reloading in Keystone now
  • You can't use Keystone's GraphQL types in Nexus, it should be totally possible but I haven't worked out how to make Nexus aware of the GraphQL schema Keystone generates yet
  • Nexus also has a Prisma plugin, which simplifies type definition. We should be able to get Nexus in this example hooked up to the Prisma schema that Keystone generates

@changeset-bot

This comment was marked as resolved.

@vercel
Copy link

vercel bot commented Oct 14, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/HgHafYnCh7Zw73zHRKpGSCRTLTdN
✅ Preview: https://keystone-next-docs-git-nexus-example-keystonejs.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 14, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@JedWatson
Copy link
Member Author

Note on the status of the Prisma plugin:

I just read through graphql-nexus/nexus-plugin-prisma#1039 and it's being rewritten, the one you can use today only works with an older version of Prisma than the one that Keystone uses so we should definitely wait for the new one (here) is ready for use.

@vercel vercel bot temporarily deployed to Preview October 19, 2021 10:47 Inactive
@vercel vercel bot temporarily deployed to Preview October 19, 2021 10:56 Inactive
@vercel vercel bot temporarily deployed to Preview October 19, 2021 10:59 Inactive
@vercel vercel bot temporarily deployed to Preview October 19, 2021 11:06 Inactive
@vercel vercel bot temporarily deployed to Preview October 19, 2021 11:22 Inactive
@vercel vercel bot temporarily deployed to Preview October 19, 2021 11:56 Inactive
Copy link
Contributor

@bladey bladey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice example.

Getting the following when running yarn dev and/or yarn dev-nexus (doesn't matter the combination), regardless it all seems to work still:

Screen Shot 2021-10-20 at 12 30 43 pm

When attempting to request nexusPosts:

Pasted Graphic 2

Aren't dates supposed to be ISO Strings?

async resolve(root, ( authorid, days ), context)

Works if changed to toISOString() and having a post with a publish date being in the future:

Pasted Graphic

For the things example, I can't pull out:

  things {
    id
    title
  }

Based on what the data looks like:

image

As there is a mismatch here:

Pasted Graphic 3 copy

Changing this on the fly it gets detected as a change:

image

But still fails to resolve until I restart Keystone itself:

image

After a restart:

image

@vercel vercel bot temporarily deployed to Preview November 8, 2021 11:57 Inactive
@vercel vercel bot temporarily deployed to Preview November 8, 2021 11:59 Inactive
@vercel vercel bot temporarily deployed to Preview November 8, 2021 12:27 Inactive
@vercel vercel bot temporarily deployed to Preview November 11, 2021 03:54 Inactive
@vercel vercel bot temporarily deployed to Preview November 11, 2021 04:29 Inactive
@vercel vercel bot temporarily deployed to Preview November 11, 2021 04:55 Inactive
@vercel vercel bot temporarily deployed to Preview November 11, 2021 04:58 Inactive
@vercel vercel bot temporarily deployed to Preview November 11, 2021 05:01 Inactive
@vercel vercel bot temporarily deployed to Preview November 11, 2021 05:09 Inactive
@bladey bladey self-requested a review November 11, 2021 05:21
Copy link
Contributor

@bladey bladey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well.

@vercel vercel bot temporarily deployed to Preview November 11, 2021 05:36 Inactive
@JedWatson JedWatson enabled auto-merge (squash) November 11, 2021 05:36
@vercel vercel bot temporarily deployed to Preview November 11, 2021 05:49 Inactive
@vercel vercel bot temporarily deployed to Preview November 11, 2021 06:34 Inactive
@JedWatson JedWatson merged commit 787de6f into main Nov 11, 2021
@JedWatson JedWatson deleted the nexus-example branch November 11, 2021 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants