Skip to content

Commit

Permalink
updates examples and internal usages to use new module resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown authored and dcousens committed Aug 25, 2022
1 parent 90241ea commit 86460ce
Show file tree
Hide file tree
Showing 28 changed files with 33 additions and 67 deletions.
10 changes: 5 additions & 5 deletions docs/pages/docs/apis/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Options:
See the [Hooks API](./hooks) for full details on the available hook options.
- `label`: The label displayed for this field in the Admin UI. Defaults to a human readable version of the field name.
- `ui`: Controls how the field is displayed in the Admin UI.
- `views`: A [resolved](https://nodejs.org/api/modules.html#modules_require_resolve_request_options) path to a module containing code to replace or extend the default Admin UI components for this field. See the [Custom Field Views](../guides/custom-field-views) guide for details on how to use this option.
- `views`: A module specifier that will be resolved from the Keystone project's directory to a module containing code to replace or extend the default Admin UI components for this field. See the [Custom Field Views](../guides/custom-field-views) guide for details on how to use this option.
- `createView.fieldMode` (default: `'edit'`): Controls the create view page of the Admin UI.
Can be one of `['edit', 'hidden']`, or an async function with an argument `{ session, context }` that returns one of `['edit', 'hidden']`.
Defaults to the list's `ui.createView.defaultFieldMode` config if defined.
Expand Down Expand Up @@ -109,7 +109,7 @@ export default config({
hooks: { /* ... */ },
label: '...',
ui: {
views: require.resolve('path/to/viewsModule.tsx'),
views: './path/to/viewsModule',
createView: {
fieldMode: ({ session, context }) => 'edit',
},
Expand Down Expand Up @@ -1025,12 +1025,12 @@ export default config({
## Related resources

{% related-content %}
{% well
{% well
heading="Schema API Reference"
href="/docs/apis/schema" %}
The API to configure your options used with the `list()` function.
The API to configure your options used with the `list()` function.
{% /well %}
{% well
{% well
heading="GraphQL API Reference"
href="/docs/apis/graphql" %}
A complete CRUD (create, read, update, delete) GraphQL API derived from the list and field names you configure in your system.
Expand Down
8 changes: 5 additions & 3 deletions docs/pages/docs/guides/custom-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const myInt =
orderBy: { arg: graphql.arg({ type: orderDirectionEnum }) },
},
output: graphql.field({ type: graphql.Int }),
views: require.resolve('./view.tsx'),
views: './view',
});
```

Expand Down Expand Up @@ -115,8 +115,10 @@ output: graphql.field({

The frontend portion of a field must be in a seperate file that the backend implementation points to with the `views` option.

The `views` option is resolved as though it is an import from some file in the project directory.

```
views: require.resolve('./view.tsx'),
views: './view',
```

#### Controller
Expand Down Expand Up @@ -217,7 +219,7 @@ export const CardValue: CardValueComponent = ({ item, field }) => {
## Related resources

{% related-content %}
{% well
{% well
heading="Example Project: Custom Fields"
href="https://github.com/keystonejs/keystone/tree/main/examples/custom-field"
target="_blank" %}
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/guides/document-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export default config({
fields: {
fieldName: document({
ui: {
views: require.resolve('./component-blocks')
views: './component-blocks'
},
componentBlocks,
}),
Expand Down
3 changes: 0 additions & 3 deletions examples/basic/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ export const lists: Lists = {
Post: list({
fields: {
title: text({ access: {} }),
// TODO: expand this out into a proper example project
// Enable this line to test custom field views
// test: text({ ui: { views: require.resolve('./admin/fieldViews/Test.tsx') } }),
status: select({
options: [
{ label: 'Published', value: 'published' },
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-field-view/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ In this project we add a new JSON field to the `Task` list:
```typescript
relatedLinks: json({
ui: {
views: require.resolve('./fields/related-links/components.tsx'),
views: './fields/related-links/components',
createView: { fieldMode: 'edit' },
listView: { fieldMode: 'hidden' },
itemView: { fieldMode: 'edit' },
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-field-view/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const lists = {
// We've added a json field which implements custom views in the Admin UI
relatedLinks: json({
ui: {
views: require.resolve('./fields/related-links/components.tsx'),
views: './fields/related-links/components',
createView: { fieldMode: 'edit' },
listView: { fieldMode: 'hidden' },
itemView: { fieldMode: 'edit' },
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-field/2-stars-field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const stars =
return value;
},
}),
views: require.resolve('./views.tsx'),
views: './2-stars-field/views',
getAdminMeta() {
return { maxStars };
},
Expand Down
3 changes: 1 addition & 2 deletions packages/cloudinary/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from 'path';
import {
CommonFieldConfig,
BaseListTypeInfo,
Expand Down Expand Up @@ -172,7 +171,7 @@ export const cloudinaryImage =
};
},
}),
views: path.join(path.dirname(__dirname), 'views'),
views: '@keystone-6/cloudinary/views',
},
{
map: config.db?.map,
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/fields/resolve-view.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/core/src/fields/types/bigInt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
assertReadIsNonNullAllowed,
getResolvedIsNullable,
} from '../../non-null-graphql';
import { resolveView } from '../../resolve-view';

export type BigIntFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down Expand Up @@ -173,7 +172,7 @@ export const bigInt =
output: graphql.field({
type: config.graphql?.read?.isNonNull ? graphql.nonNull(graphql.BigInt) : graphql.BigInt,
}),
views: resolveView('bigInt/views'),
views: '@keystone-6/core/fields/types/bigInt/views',
getAdminMeta() {
return {
validation: {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/calendarDay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
assertReadIsNonNullAllowed,
getResolvedIsNullable,
} from '../../non-null-graphql';
import { resolveView } from '../../resolve-view';
import { CalendarDayFieldMeta } from './views';

export type CalendarDayFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
Expand Down Expand Up @@ -143,7 +142,7 @@ export const calendarDay =
return value;
},
}),
views: resolveView('calendarDay/views'),
views: '@keystone-6/core/fields/types/calendarDay/views',
getAdminMeta(): CalendarDayFieldMeta {
return {
defaultValue: defaultValue ?? null,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/checkbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '../../../types';
import { graphql } from '../../..';
import { assertCreateIsNonNullAllowed, assertReadIsNonNullAllowed } from '../../non-null-graphql';
import { resolveView } from '../../resolve-view';

export type CheckboxFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down Expand Up @@ -72,7 +71,7 @@ export const checkbox =
output: graphql.field({
type: config.graphql?.read?.isNonNull ? graphql.nonNull(graphql.Boolean) : graphql.Boolean,
}),
views: resolveView('checkbox/views'),
views: '@keystone-6/core/fields/types/checkbox/views',
getAdminMeta: () => ({ defaultValue }),
});
};
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/decimal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
FieldData,
} from '../../../types';
import { graphql } from '../../..';
import { resolveView } from '../../resolve-view';
import {
assertCreateIsNonNullAllowed,
assertReadIsNonNullAllowed,
Expand Down Expand Up @@ -183,7 +182,7 @@ export const decimal =
return val;
},
}),
views: resolveView('decimal/views'),
views: '@keystone-6/core/fields/types/decimal/views',
getAdminMeta: (): import('./views').DecimalFieldMeta => ({
defaultValue: defaultValue ?? null,
precision,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
FileMetadata,
} from '../../../types';
import { graphql } from '../../..';
import { resolveView } from '../../resolve-view';

export type FileFieldConfig<ListTypeInfo extends BaseListTypeInfo> = {
storage: string;
Expand Down Expand Up @@ -115,6 +114,6 @@ export const file =
return { filename, filesize, storage: config.storage };
},
}),
views: resolveView('file/views'),
views: '@keystone-6/core/fields/types/file/views',
});
};
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/float/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
assertReadIsNonNullAllowed,
getResolvedIsNullable,
} from '../../non-null-graphql';
import { resolveView } from '../../resolve-view';

export type FloatFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down Expand Up @@ -160,7 +159,7 @@ export const float =
output: graphql.field({
type: config.graphql?.read?.isNonNull ? graphql.nonNull(graphql.Float) : graphql.Float,
}),
views: resolveView('float/views'),
views: '@keystone-6/core/fields/types/float/views',
getAdminMeta() {
return {
validation: {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
KeystoneContext,
} from '../../../types';
import { graphql } from '../../..';
import { resolveView } from '../../resolve-view';
import { SUPPORTED_IMAGE_EXTENSIONS } from './utils';

export type ImageFieldConfig<ListTypeInfo extends BaseListTypeInfo> = {
Expand Down Expand Up @@ -152,6 +151,6 @@ export const image =
};
},
}),
views: resolveView('image/views'),
views: '@keystone-6/core/fields/types/image/views',
});
};
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/integer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
assertReadIsNonNullAllowed,
getResolvedIsNullable,
} from '../../non-null-graphql';
import { resolveView } from '../../resolve-view';

export type IntegerFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down Expand Up @@ -185,7 +184,7 @@ export const integer =
output: graphql.field({
type: config.graphql?.read?.isNonNull ? graphql.nonNull(graphql.Int) : graphql.Int,
}),
views: resolveView('integer/views'),
views: '@keystone-6/core/fields/types/integer/views',
getAdminMeta() {
return {
validation: {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/json/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
jsonFieldTypePolyfilledForSQLite,
} from '../../../types';
import { graphql } from '../../..';
import { resolveView } from '../../resolve-view';

export type JsonFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down Expand Up @@ -38,7 +37,7 @@ export const json =
update: { arg: graphql.arg({ type: graphql.JSON }) },
},
output: graphql.field({ type: graphql.JSON }),
views: resolveView('json/views'),
views: '@keystone-6/core/fields/types/json/views',
getAdminMeta: () => ({ defaultValue }),
},
{
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/multiselect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '../../../types';
import { graphql } from '../../..';
import { assertCreateIsNonNullAllowed, assertReadIsNonNullAllowed } from '../../non-null-graphql';
import { resolveView } from '../../resolve-view';
import { userInputError } from '../../../lib/core/graphql-errors';

export type MultiselectFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
Expand Down Expand Up @@ -128,7 +127,7 @@ export const multiselect =
await config.hooks?.validateInput?.(args);
},
},
views: resolveView('multiselect/views'),
views: '@keystone-6/core/fields/types/multiselect/views',
getAdminMeta: () => ({
options: transformedConfig.options,
type: config.type ?? 'string',
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/password/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { userInputError } from '../../../lib/core/graphql-errors';
import { humanize } from '../../../lib/utils';
import { BaseListTypeInfo, fieldType, FieldTypeFunc, CommonFieldConfig } from '../../../types';
import { graphql } from '../../..';
import { resolveView } from '../../resolve-view';
import { getResolvedIsNullable } from '../../non-null-graphql';
import { PasswordFieldMeta } from './views';

Expand Down Expand Up @@ -184,7 +183,7 @@ export const password =
resolve: inputResolver,
},
},
views: resolveView('password/views'),
views: '@keystone-6/core/fields/types/password/views',
getAdminMeta: (): PasswordFieldMeta => ({
isNullable,
validation: {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/relationship/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
AdminMetaRootVal,
} from '../../../types';
import { graphql } from '../../..';
import { resolveView } from '../../resolve-view';

// This is the default display mode for Relationships
type SelectDisplayConfig = {
Expand Down Expand Up @@ -86,7 +85,7 @@ export const relationship =
const [foreignListKey, foreignFieldKey] = ref.split('.');
const commonConfig = {
...config,
views: resolveView('relationship/views'),
views: '@keystone-6/core/fields/types/relationship/views',
getAdminMeta: (
adminMetaRoot: AdminMetaRootVal
): Parameters<typeof import('./views').controller>[0]['fieldMeta'] => {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
assertReadIsNonNullAllowed,
getResolvedIsNullable,
} from '../../non-null-graphql';
import { resolveView } from '../../resolve-view';

export type SelectFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> &
Expand Down Expand Up @@ -111,7 +110,7 @@ export const select =
await config.hooks?.validateInput?.(args);
},
},
views: resolveView('select/views'),
views: '@keystone-6/core/fields/types/select/views',
getAdminMeta: () => ({
options,
type: config.type ?? 'string',
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '../../../types';
import { graphql } from '../../..';
import { assertCreateIsNonNullAllowed, assertReadIsNonNullAllowed } from '../../non-null-graphql';
import { resolveView } from '../../resolve-view';

export type TextFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down Expand Up @@ -178,7 +177,7 @@ export const text =
output: graphql.field({
type: config.graphql?.read?.isNonNull ? graphql.nonNull(graphql.String) : graphql.String,
}),
views: resolveView('text/views'),
views: '@keystone-6/core/fields/types/text/views',
getAdminMeta(): TextFieldMeta {
return {
displayMode: config.ui?.displayMode ?? 'input',
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/timestamp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
assertReadIsNonNullAllowed,
getResolvedIsNullable,
} from '../../non-null-graphql';
import { resolveView } from '../../resolve-view';
import { TimestampFieldMeta } from './views';

export type TimestampFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
Expand Down Expand Up @@ -136,7 +135,7 @@ export const timestamp =
? graphql.nonNull(graphql.DateTime)
: graphql.DateTime,
}),
views: resolveView('timestamp/views'),
views: '@keystone-6/core/fields/types/timestamp/views',
getAdminMeta(): TimestampFieldMeta {
return {
defaultValue: defaultValue ?? null,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/fields/types/virtual/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
getGqlNames,
} from '../../../types';
import { graphql } from '../../..';
import { resolveView } from '../../resolve-view';

type VirtualFieldGraphQLField<Item extends BaseItem> = graphql.Field<
Item,
Expand Down Expand Up @@ -85,7 +84,7 @@ export const virtual =
return usableField.resolve!(item as any, ...args);
},
}),
views: resolveView('virtual/views'),
views: '@keystone-6/core/fields/types/virtual/views',
getAdminMeta: () => ({ query: config.ui?.query || '' }),
});
};
Loading

0 comments on commit 86460ce

Please sign in to comment.