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 config.experimental.contextInitialisedLists #6403

Merged
merged 5 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-ladybugs-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': minor
---

Added the experimental config option `config.experimental.contextInitialisedLists`, which adds the internal data structure `experimental.initialisedLists` to the `context` object. This is a temporary addition to the API which will be removed in a future release once a more controlled API is available. It should be used with caution, as it will contain breaking change in `patch` level releases.
7 changes: 7 additions & 0 deletions packages/keystone/src/lib/context/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../../types';

import { PrismaClient } from '../core/utils';
import { InitialisedList } from '../core/types-for-lists';
import { getDbAPIFactory, itemAPIForList } from './itemAPI';
import { createImagesContext } from './createImagesContext';
import { createFilesContext } from './createFilesContext';
Expand All @@ -19,12 +20,14 @@ export function makeCreateContext({
prismaClient,
gqlNamesByList,
config,
lists,
}: {
graphQLSchema: GraphQLSchema;
internalSchema: GraphQLSchema;
config: KeystoneConfig;
prismaClient: PrismaClient;
gqlNamesByList: Record<string, GqlNames>;
lists: Record<string, InitialisedList>;
}) {
const images = createImagesContext(config);
const files = createFilesContext(config);
Expand Down Expand Up @@ -99,6 +102,10 @@ export function makeCreateContext({
images,
files,
};
if (config.experimental?.contextInitialisedLists) {
contextToReturn.experimental = { initialisedLists: lists };
}

const dbAPIFactories = schemaName === 'public' ? publicDbApiFactories : internalDbApiFactories;
for (const listKey of Object.keys(gqlNamesByList)) {
dbAPI[listKey] = dbAPIFactories[listKey](contextToReturn);
Expand Down
1 change: 1 addition & 0 deletions packages/keystone/src/lib/createSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function createSystem(config: KeystoneConfig) {
gqlNamesByList: Object.fromEntries(
Object.entries(lists).map(([listKey, list]) => [listKey, getGqlNames(list)])
),
lists,
});

return {
Expand Down
4 changes: 4 additions & 0 deletions packages/keystone/src/types/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export type KeystoneConfig = {
generateNextGraphqlAPI?: boolean;
/** Config options for Keystone Cloud */
keystoneCloud?: KeystoneCloudConfig;
/** Adds the internal data structure `experimental.initialisedLists` to the context object.
* This is not a stable API and may contain breaking changes in `patch` level releases.
*/
contextInitialisedLists?: boolean;
};
};

Expand Down
7 changes: 7 additions & 0 deletions packages/keystone/src/types/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IncomingMessage } from 'http';
import { Readable } from 'stream';
import { GraphQLSchema, ExecutionResult, DocumentNode } from 'graphql';
import { InitialisedList } from '../lib/core/types-for-lists';
import type { BaseGeneratedListTypes, GqlNames } from './utils';

export type KeystoneContext = {
Expand All @@ -20,6 +21,12 @@ export type KeystoneContext = {
schemaName: 'public' | 'internal';
/** @deprecated */
gqlNames: (listKey: string) => GqlNames;
experimental?: {
/** @deprecated This value is only available if you have config.experimental.contextInitialisedLists = true.
* This is not a stable API and may contain breaking changes in `patch` level releases.
*/
initialisedLists: Record<string, InitialisedList>;
};
} & Partial<SessionContext<any>>;

// List item API
Expand Down
1 change: 1 addition & 0 deletions tests/test-projects/crud-notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# @keystone-next/test-projects-crud-notifications

## 0.0.3

### Patch Changes

- Updated dependencies [[`e9f3c42d5`](https://github.com/keystonejs/keystone/commit/e9f3c42d5b9d42872cecbd18fbe9bf9d7d53ed82), [`5cd8ffd6c`](https://github.com/keystonejs/keystone/commit/5cd8ffd6cb822dbee8555b47846a5019c4d2b1c3), [`1cbcf54cb`](https://github.com/keystonejs/keystone/commit/1cbcf54cb1206461866b582865e3b1a8fc728f18), [`a92169d04`](https://github.com/keystonejs/keystone/commit/a92169d04e5a1a98deb8e757b8eae3b06fc66450), [`5cd8ffd6c`](https://github.com/keystonejs/keystone/commit/5cd8ffd6cb822dbee8555b47846a5019c4d2b1c3), [`b696a9579`](https://github.com/keystonejs/keystone/commit/b696a9579b503db86f42776381e247c4e1a7409f), [`f3014a627`](https://github.com/keystonejs/keystone/commit/f3014a627060c7cd86440a6937da5caecfd023a0), [`092df6678`](https://github.com/keystonejs/keystone/commit/092df6678cea18d639be16ad250ec4ecc9250f5a), [`5cd8ffd6c`](https://github.com/keystonejs/keystone/commit/5cd8ffd6cb822dbee8555b47846a5019c4d2b1c3), [`6da56b80e`](https://github.com/keystonejs/keystone/commit/6da56b80e03c748a621afcca6c1ec2887fef7271), [`4f4f0351a`](https://github.com/keystonejs/keystone/commit/4f4f0351a056dea9d1614aa2a3a4789d66bb402d), [`697efa354`](https://github.com/keystonejs/keystone/commit/697efa354b1066b3d4b6eb757ca704b458f45e93), [`c7e331d90`](https://github.com/keystonejs/keystone/commit/c7e331d90a28b2ed8236100097cb8d34a11fabe2), [`3a7a06b2c`](https://github.com/keystonejs/keystone/commit/3a7a06b2cc6b5ea157d34d925b15494b471899eb), [`272b97b3a`](https://github.com/keystonejs/keystone/commit/272b97b3a10c0dfada782171d55ef7ac6f47c98f), [`78dac764e`](https://github.com/keystonejs/keystone/commit/78dac764e1860b33f9e2bd8cee6015abeaaa5ec4), [`399561b27`](https://github.com/keystonejs/keystone/commit/399561b2769ddd8f3d3fdf29838f5784404bb053), [`9d361c1c8`](https://github.com/keystonejs/keystone/commit/9d361c1c8625e1390f837b7318b63547d686a63b), [`0dcb1c95b`](https://github.com/keystonejs/keystone/commit/0dcb1c95b5200750cc8649485425f2ae40d023a3), [`94435ffee`](https://github.com/keystonejs/keystone/commit/94435ffee765824091899242e4a2f73c7356b524), [`5cd8ffd6c`](https://github.com/keystonejs/keystone/commit/5cd8ffd6cb822dbee8555b47846a5019c4d2b1c3), [`56044e2a4`](https://github.com/keystonejs/keystone/commit/56044e2a425f4256b66475fd3b1a6342cd6c3bf9), [`f46fd32b7`](https://github.com/keystonejs/keystone/commit/f46fd32b7047dbb5ea2566859f7ecee8db5b0b15), [`874f2c405`](https://github.com/keystonejs/keystone/commit/874f2c4058c9cf006213e84b9ffcf39c5bf144e8), [`8ea4eed55`](https://github.com/keystonejs/keystone/commit/8ea4eed55367aaa213f6b4ffb7473087498e39ae), [`e3fe6498d`](https://github.com/keystonejs/keystone/commit/e3fe6498dc36203d8080dff3c2e0c25f6c98733e), [`1030296d1`](https://github.com/keystonejs/keystone/commit/1030296d1f304dc44246e895089ac1f992e80590), [`3564b342d`](https://github.com/keystonejs/keystone/commit/3564b342d6dc2127ae591d7ac055af9eae90543c), [`8b2d179b2`](https://github.com/keystonejs/keystone/commit/8b2d179b2463d78b082182ca9afa8233109e0ba3), [`e3fefafcc`](https://github.com/keystonejs/keystone/commit/e3fefafcce6f8bf836c9bf0f4d931b8200ba41c7), [`4d9f89f88`](https://github.com/keystonejs/keystone/commit/4d9f89f884e2bf984fdd74ca2cbb7874b25b9cda), [`686c0f1c4`](https://github.com/keystonejs/keystone/commit/686c0f1c4a1feb609e1584aa71738709bbbf984e), [`d214e2f72`](https://github.com/keystonejs/keystone/commit/d214e2f72bae1c798e2415a38410d6063c333e2e), [`f5e64af37`](https://github.com/keystonejs/keystone/commit/f5e64af37df2eb460c89d89fa3c8924fb34970ed)]:
Expand Down