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 Context types for graphql-ts export #7877

Merged
merged 3 commits into from
Sep 6, 2022
Merged

Add Context types for graphql-ts export #7877

merged 3 commits into from
Sep 6, 2022

Conversation

dcousens
Copy link
Member

@dcousens dcousens commented Sep 1, 2022

This pull request adds support for the capability to add : Context as a type refinement when doing GraphQL extensions.
Fundamentally this is still no different to a cast of as Context.

For the future, we will look at things like #7733, but for now this will be an improvement for many using these types.

export const extendGraphqlSchema = graphql.extend(base => {
  ... = graphql.object<{ authorId: string }>()({
    name: 'Statistics',
    fields: {
      authorPosts: graphql.field({
        type: graphql.Int,
        resolve({ authorId }, args, context: Context) { // <-- adding `: Context` now contextualizes the types
          return context.db.Post.count({
            where: { 
              author: {
                id: {
                  equals: authorId
                }
              }
          });
        },
      }),
    },
  })
})

@vercel
Copy link

vercel bot commented Sep 1, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
keystone-next-docs ✅ Ready (Inspect) Visit Preview Sep 1, 2022 at 7:12AM (UTC)

@changeset-bot
Copy link

changeset-bot bot commented Sep 1, 2022

🦋 Changeset detected

Latest commit: 01cfbc0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@keystone-6/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 1, 2022

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.

Latest deployment of this branch, based on commit 01cfbc0:

Sandbox Source
@keystone-6/sandbox Configuration

@dcousens dcousens marked this pull request as draft September 1, 2022 02:53
@vercel vercel bot temporarily deployed to Preview September 1, 2022 02:59 Inactive
@vercel vercel bot temporarily deployed to Preview September 1, 2022 03:05 Inactive
@dcousens dcousens marked this pull request as ready for review September 1, 2022 03:13
@vercel vercel bot temporarily deployed to Preview September 1, 2022 03:29 Inactive
@vercel vercel bot temporarily deployed to Preview September 1, 2022 04:36 Inactive
@vercel vercel bot temporarily deployed to Preview September 1, 2022 07:12 Inactive
@dcousens dcousens merged commit ad54ef3 into main Sep 6, 2022
@dcousens dcousens deleted the graphql-context branch September 6, 2022 03:35
dcousens added a commit that referenced this pull request Sep 14, 2022
* merge graphql schemas with list schemas

* add contextualised type capability for graphql-ts extensions

* add changeset

Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>
dcousens added a commit that referenced this pull request Sep 15, 2022
* merge graphql schemas with list schemas

* add contextualised type capability for graphql-ts extensions

* add changeset

Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>
dcousens added a commit that referenced this pull request Sep 15, 2022
* merge graphql schemas with list schemas

* add contextualised type capability for graphql-ts extensions

* add changeset

Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>
dcousens added a commit that referenced this pull request Sep 15, 2022
* merge graphql schemas with list schemas

* add contextualised type capability for graphql-ts extensions

* add changeset

Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>
@dcousens dcousens self-assigned this Oct 3, 2022
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.

2 participants