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

Upgrade to @graphql-ts/schema@1 #9535

Merged
merged 4 commits into from
Mar 12, 2025
Merged

Upgrade to @graphql-ts/schema@1 #9535

merged 4 commits into from
Mar 12, 2025

Conversation

emmatown
Copy link
Member

@emmatown emmatown commented Mar 10, 2025

This updates Keystone to @graphql-ts/schema@1.0.0 which makes a few changes, the most notable thing for users is that they should use gWithContext to bind g(named graphql in the current stable version of keystone, renamed to g in #9460) to their own Context type from .keystone/types instead of using the g exported by @keystone-6/core that is bound to the generic KeystoneContext.

import { gWithContext } from '@keystone-6/core'
import type { Context } from '.keystone/types'

const g = gWithContext<Context>()
type g<T> = gWithContext.infer<T>

This means that e.g. writing resolvers will have the correct context type.

The g type alias is used to help declaring types, particular for circular types, like this:

type PersonSource = {
  id: string;
  name: string;
};

const Person: g<typeof g.object<PersonSource>> = g.object<PersonSource>()({
  name: "Person",
  fields: () => ({
    id: g.field({ type: g.nonNull(g.ID) }),
    name: g.field({ type: g.nonNull(g.String) }),
    friends: g.field({
      type: g.list(g.nonNull(Person)),
      resolve(source, _, context) {
        return []
      },
    }),
  }),
});

Without the g<typeof g.object<PersonSource>>, TypeScript would error about the circularity. Previously this could be written with g.ObjectType<PersonSource>, the types for this no longer exist, you should now use the g<typeof g.something<...>> or imports from @keystone-6/core/graphql-ts which re-exports types from @graphql-ts/schema.

Another notable change is that all the various types returned by e.g. g.object/etc. are now directly compatible with GraphQLObjectType/etc. from GraphQL.js instead of being accessible at .graphQLType on the returned object.

Also, the minimum TypeScript version is now 5.7.

Copy link

socket-security bot commented Mar 10, 2025

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher

🚮 Removed packages: npm/@graphql-ts/extend@1.0.3, npm/@graphql-ts/schema@0.6.4

View full report↗︎

@emmatown emmatown force-pushed the graphql-ts-major branch 2 times, most recently from 99a471d to a2948cb Compare March 11, 2025 23:02
@emmatown emmatown force-pushed the graphql-ts-major branch 3 times, most recently from f0b5a71 to ad17018 Compare March 12, 2025 04:41
@emmatown emmatown changed the title graphql-ts updates testing Upgrade to @graphql-ts/schema@1 Mar 12, 2025
@emmatown emmatown marked this pull request as ready for review March 12, 2025 06:04
Copy link
Member

@dcousens dcousens left a comment

Choose a reason for hiding this comment

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

Amazing

@dcousens dcousens merged commit 810e77d into main Mar 12, 2025
48 checks passed
@dcousens dcousens deleted the graphql-ts-major branch March 12, 2025 06:15
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.

None yet

2 participants