Skip to content

✨ 15th November 2021

Compare
Choose a tag to compare
@bladey bladey released this 17 Nov 00:27
· 1146 commits to main since this release
aecbe67

Expanded unique filters, customisable table and column names support and a new example featuring Nexus as we continue to finalise our GA release. 🪢

"@keystone-next/auth": "36.0.0",
"@keystone-next/cloudinary": "11.0.0",
"@keystone-next/fields-document": "13.0.0",
"@keystone-next/keystone": "28.0.0",
"@keystone-next/session-store-redis": "8.0.0",

Like this release? Give us a star on GitHub!

Expanded Unique Filters 🔎

select, timestamp, float and decimal fields with isIndexed: 'unique' now have unique filters via ListWhereUniqueInput which text, integer and the id field already support.

For example, if you added isIndexed: 'unique' to a select field in a theoretical Settings list, you can now run the following query:

query {
  setting ( where: { provider: "github" } ) {
    id
    token
  }
}

This is instead of running a settings query where you would have received a list back, and have had to check for results and get the first element:

query {
  settings ( where: { provider: { equals: "github" } } ) {
    id
    token
  }
}

Customisable Table and Column Names 📇

You may now use different table and column names to those automatically chosen by Keystone for your list and field keys. This is powered by Prisma's @map and @@map attributes. You can read more about this concept in Prisma's documentation.

This is useful if you do not want to modify your existing database (such as a read-only database) and use it with Keystone.

For example if you wanted to refer to a table named stories but you refer to it in Keystone as Posts provide config.db.map to a list or field key such as:

Post: list({
  db: {
    map: 'stories',
  },
  fields: {
    ...
  }
})

Nexus Example 🪢

We've got a new example using Nexus, a declarative, code-first and strongly typed GraphQL schema construction for TypeScript & JavaScript.

Using Nexus you can extend the GraphQL API provided by Keystone with custom queries and mutations.

In the example below we expose a mutation called nexusPosts which pulls out items from our Posts list that have been published within the past 7 days (by default), with an optional author filter.

export const PostQuery = extendType({
  type: "Query",
  definition(t) {
    t.field("nexusPosts", {
      type: nonNull(list("NexusPost")),
      args: {
        authorId: stringArg(),
        days: nonNull(intArg({ default: 7 })),
      },
      async resolve(root, { authorId, days }, context) {
        const cutoff = new Date(
          new Date().setUTCDate(new Date().getUTCDate() - days)
        ).toISOString();

        return await context.prisma.post.findMany({
          where: {
            ...(authorId ? { author: { id: authorId } } : null),
            publishDate: { gt: cutoff },
          },
        });
      },
    });
  },
});

Check out the example in Keystone's examples directory.

Miscellaneous Fixes ⚙️

  • The format of the date shown in the DatePicker now uses the user's locale.
  • When the sessionData option is invalid, the error will now be thrown on startup instead of silently ignored.

Changelog

You can also the verbose changelog in the related PR (#6914) for this release.