Skip to content

Commit

Permalink
Merge branch 'main' into renovate/eslint-8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Oct 26, 2021
2 parents ea58138 + c723eb8 commit b988935
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 123 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-beds-yawn.md
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': major
---

Keystone will now default to using GraphQL Playground instead of Apollo Sandbox as it did prior to updating to Apollo Server 3. If you want to use Apollo Sandbox, you can set `graphql.playground: 'apollo'` to use Apollo. `graphql.playground` defaults to `process.env.NODE_ENV !== 'production'`, which will serve GraphQL Playground in development and serve nothing in production, if you'd like to set it to one of those always, you can set `graphql.playground` to a boolean explicitly.
5 changes: 5 additions & 0 deletions .changeset/lazy-parrots-do.md
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': minor
---

Add short plain-text display to document fields for Cell (list view; resolves #6522) and a rendered document view in CardValue
5 changes: 5 additions & 0 deletions .changeset/mighty-donuts-report.md
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': major
---

Updated `@graphql-ts/schema` to `0.5.0`. The `__rootVal` properties on `ObjectType`, `InterfaceType` and `UnionType` have been renamed to `__source`, this is intended to be internal but it could be depended on so if you did, you will need to change to `__source`. The `fields` property on `InterfaceType` has been renamed to `__fields` and it will no longer exist at runtime like the other types.
7 changes: 7 additions & 0 deletions .changeset/popular-zoos-run.md
@@ -0,0 +1,7 @@
---
"@keystone-next/keystone": patch
"@keystone-next/api-tests-legacy": patch
"@keystone-next/prisma-utils": patch
---

Update prisma monorepo to [v3.3.0 (minor)](https://github.com/prisma/prisma/releases/tag/3.3.0)
5 changes: 5 additions & 0 deletions .changeset/sour-snails-flash.md
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': major
---

Removed `graphql.cors` option. You should exclusively configure `cors` with the `server.cors` option.
5 changes: 4 additions & 1 deletion docs/pages/docs/apis/config.mdx
Expand Up @@ -345,7 +345,10 @@ Options:
- `queryLimits` (default: `undefined`): Allows you to limit the total number of results returned from a query to your GraphQL API.
See also the per-list `graphql.queryLimits` option in the [Schema API](./schema).
- `path` (default: `'/api/graphql'`): The path of the GraphQL API endpoint.
- `cors` (default: `rocess.env.NODE_ENV !== 'production' ? { origin: 'https://studio.apollographql.com', credentials: true } : undefined`): The CORS configuration to use on the GraphQL API endpoint. The default is setup to allow access access to API from the Apollo Sandbox during development
- `playground` (default: `process.env.NODE_ENV !== 'production'`)
- `true` - Add `ApolloServerPluginLandingPageGraphQLPlayground` to the Apollo Server plugins
- `false` - Add `ApolloServerPluginLandingPageDisabled` to the Apollo Server plugins
- `'apollo'` - Do not add any plugins to the Apollo config, this will use [Apollo Sandbox](https://www.apollographql.com/docs/apollo-server/testing/build-run-queries/#apollo-sandbox)
- `apolloConfig` (default: `undefined`): Allows you to pass [extra options](https://www.apollographql.com/docs/apollo-server/api/apollo-server/#constructor) into the `ApolloServer` constructor.

```typescript
Expand Down
1 change: 1 addition & 0 deletions packages/fields-document/package.json
Expand Up @@ -25,6 +25,7 @@
"@babel/runtime": "^7.15.4",
"@braintree/sanitize-url": "^5.0.2",
"@emotion/weak-memoize": "^0.2.5",
"@keystone-next/document-renderer": "^4.0.1",
"@keystone-ui/button": "^5.0.2",
"@keystone-ui/core": "^3.2.1",
"@keystone-ui/fields": "^5.0.1",
Expand Down
21 changes: 18 additions & 3 deletions packages/fields-document/src/views.tsx
Expand Up @@ -4,6 +4,7 @@
import { jsx } from '@keystone-ui/core';
import { FieldContainer, FieldLabel } from '@keystone-ui/fields';
import { Descendant, Node, Text } from 'slate';
import { DocumentRenderer } from '@keystone-next/document-renderer';

import {
CardValueComponent,
Expand All @@ -13,6 +14,7 @@ import {
FieldProps,
} from '@keystone-next/keystone/types';
import weakMemoize from '@emotion/weak-memoize';
import { CellContainer, CellLink } from '@keystone-next/keystone/admin-ui/components';
import { DocumentEditor } from './DocumentEditor';
import { ComponentBlock } from './component-blocks';
import { Relationships } from './DocumentEditor/relationship';
Expand Down Expand Up @@ -42,15 +44,28 @@ export const Field = ({
</FieldContainer>
);

export const Cell: CellComponent = () => {
return null;
const serialize = (nodes: Node[]) => {
return nodes.map((n: Node) => Node.string(n)).join('\n');
};

export const Cell: CellComponent = ({ item, field, linkTo }) => {
const value = item[field.path]?.document;
if (!value) return null;
const plainText = serialize(value);
const cutText = plainText.length > 100 ? plainText.slice(0, 100) + '...' : plainText;
return linkTo ? (
<CellLink {...linkTo}>{cutText}</CellLink>
) : (
<CellContainer>{cutText}</CellContainer>
);
};
Cell.supportsLinkTo = true;

export const CardValue: CardValueComponent = ({ item, field }) => {
return (
<FieldContainer>
<FieldLabel>{field.label}</FieldLabel>
<pre>{JSON.stringify(item[field.path], null, 2)}</pre>
<DocumentRenderer document={item[field.path]?.document || []} />
</FieldContainer>
);
};
Expand Down
11 changes: 6 additions & 5 deletions packages/keystone/package.json
Expand Up @@ -32,7 +32,7 @@
"@emotion/hash": "^0.8.0",
"@emotion/weak-memoize": "^0.2.5",
"@graphql-tools/schema": "^8.2.0",
"@graphql-ts/schema": "0.3.1",
"@graphql-ts/schema": "0.5.0",
"@hapi/iron": "^6.0.0",
"@keystone-ui/button": "^5.0.2",
"@keystone-ui/core": "^3.2.1",
Expand All @@ -48,9 +48,9 @@
"@keystone-ui/toast": "^4.0.4",
"@keystone-ui/tooltip": "^4.0.3",
"@preconstruct/next": "^3.0.0",
"@prisma/client": "3.2.1",
"@prisma/migrate": "3.2.1",
"@prisma/sdk": "3.2.1",
"@prisma/client": "3.3.0",
"@prisma/migrate": "3.3.0",
"@prisma/sdk": "3.3.0",
"@sindresorhus/slugify": "^1.1.2",
"@types/apollo-upload-client": "14.1.0",
"@types/bcryptjs": "^2.4.2",
Expand All @@ -69,6 +69,7 @@
"@types/supertest": "^2.0.11",
"@types/uid-safe": "^2.1.2",
"@types/uuid": "^8.3.1",
"apollo-server-core": "^3.4.0",
"apollo-server-errors": "^3.2.0",
"apollo-server-express": "^3.4.0",
"apollo-server-micro": "^3.4.0",
Expand Down Expand Up @@ -109,7 +110,7 @@
"pirates": "^4.0.1",
"pluralize": "^8.0.0",
"prettier": "^2.4.1",
"prisma": "3.2.1",
"prisma": "3.3.0",
"prompts": "^2.4.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
16 changes: 16 additions & 0 deletions packages/keystone/src/lib/server/createApolloServer.ts
Expand Up @@ -2,6 +2,10 @@ import type { IncomingMessage, ServerResponse } from 'http';
import { GraphQLError, GraphQLSchema } from 'graphql';
import { ApolloServer as ApolloServerMicro } from 'apollo-server-micro';
import { ApolloServer as ApolloServerExpress } from 'apollo-server-express';
import {
ApolloServerPluginLandingPageDisabled,
ApolloServerPluginLandingPageGraphQLPlayground,
} from 'apollo-server-core';
import type { CreateContext, GraphQLConfig, SessionStrategy } from '../../types';
import { createSessionContext } from '../../session';

Expand Down Expand Up @@ -61,11 +65,23 @@ const _createApolloServerConfig = ({
graphqlConfig?: GraphQLConfig;
}) => {
const apolloConfig = graphqlConfig?.apolloConfig;
const playgroundOption = graphqlConfig?.playground ?? process.env.NODE_ENV !== 'production';

return {
schema: graphQLSchema,
debug: graphqlConfig?.debug, // If undefined, use Apollo default of NODE_ENV !== 'production'
...apolloConfig,
plugins:
playgroundOption === 'apollo'
? apolloConfig?.plugins
: [
playgroundOption
? ApolloServerPluginLandingPageGraphQLPlayground({
settings: { 'request.credentials': 'same-origin' },
})
: ApolloServerPluginLandingPageDisabled(),
...(apolloConfig?.plugins || []),
],
formatError: formatError(graphqlConfig),
};
};
Expand Down
6 changes: 1 addition & 5 deletions packages/keystone/src/lib/server/createExpressServer.ts
Expand Up @@ -46,11 +46,7 @@ const addApolloServer = async ({
apolloServer.applyMiddleware({
app: server,
path: config.graphql?.path || '/api/graphql',
cors:
config.graphql?.cors ||
(process.env.NODE_ENV !== 'production'
? { origin: 'https://studio.apollographql.com', credentials: true }
: undefined),
cors: false,
});
};

Expand Down
15 changes: 11 additions & 4 deletions packages/keystone/src/types/config/index.ts
Expand Up @@ -119,12 +119,19 @@ export type GraphQLConfig = {
queryLimits?: {
maxTotalResults?: number;
};
/**
* - `true` - Add `ApolloServerPluginLandingPageGraphQLPlayground` to the Apollo Server plugins
* - `false` - Add `ApolloServerPluginLandingPageDisabled` to the Apollo Server plugins
* - `'apollo'` - Do not add any plugins to the Apollo config, this will use [Apollo Sandbox](https://www.apollographql.com/docs/apollo-server/testing/build-run-queries/#apollo-sandbox)
* @default process.env.NODE_ENV !== 'production'
*/
playground?: boolean | 'apollo';
/**
* Additional options to pass into the ApolloServer constructor.
* @see https://www.apollographql.com/docs/apollo-server/api/apollo-server/#constructor
*/
apolloConfig?: Config;
/*
/**
* When an error is returned from the GraphQL API, Apollo can include a stacktrace
* indicating where the error occurred. When Keystone is processing mutations, it
* will sometimes captures more than one error at a time, and then group these into
Expand All @@ -140,7 +147,7 @@ export type GraphQLConfig = {
* `apolloConfig.formatError` to log the stacktraces and then strip them out before
* returning the error.
*
* ```
* ```ts
* graphql: {
* debug: true,
* apolloConfig: {
Expand All @@ -154,8 +161,8 @@ export type GraphQLConfig = {
* },
* }
* ```
* *
* Default: process.env.NODE_ENV !== 'production'
*
* @default process.env.NODE_ENV !== 'production'
*/
debug?: boolean;
};
Expand Down
12 changes: 6 additions & 6 deletions packages/keystone/src/types/schema/graphql-ts-schema.ts
Expand Up @@ -143,22 +143,22 @@ export type Type = graphqlTsSchema.Type<Context>;
export type NullableOutputType = graphqlTsSchema.NullableOutputType<Context>;
export type OutputType = graphqlTsSchema.OutputType<Context>;
export type Field<
RootVal,
Source,
Args extends Record<string, graphqlTsSchema.Arg<any>>,
TType extends OutputType,
Key extends string
> = graphqlTsSchema.Field<RootVal, Args, TType, Key, Context>;
> = graphqlTsSchema.Field<Source, Args, TType, Key, Context>;
export type FieldResolver<
RootVal,
Source,
Args extends Record<string, graphqlTsSchema.Arg<any>>,
TType extends OutputType
> = graphqlTsSchema.FieldResolver<RootVal, Args, TType, Context>;
> = graphqlTsSchema.FieldResolver<Source, Args, TType, Context>;
export type ObjectType<RootVal> = graphqlTsSchema.ObjectType<RootVal, Context>;
export type UnionType<RootVal> = graphqlTsSchema.UnionType<RootVal, Context>;
export type InterfaceType<
RootVal,
Source,
Fields extends Record<string, graphqlTsSchema.InterfaceField<any, OutputType, Context>>
> = graphqlTsSchema.InterfaceType<RootVal, Fields, Context>;
> = graphqlTsSchema.InterfaceType<Source, Fields, Context>;
export type InterfaceField<
Args extends Record<string, graphqlTsSchema.Arg<any>>,
TType extends OutputType
Expand Down
4 changes: 2 additions & 2 deletions prisma-utils/package.json
Expand Up @@ -4,8 +4,8 @@
"private": true,
"main": "dist/keystone-next-prisma-utils.cjs.js",
"dependencies": {
"@prisma/generator-helper": "3.2.1",
"@prisma/sdk": "3.2.1",
"@prisma/generator-helper": "3.3.0",
"@prisma/sdk": "3.3.0",
"fs-extra": "^10.0.0",
"prettier": "^2.4.1"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/api-tests/utils.ts
Expand Up @@ -132,7 +132,7 @@ export const expectPrismaError = (
args.map(({ path, message, code, target }) => ({
extensions: {
code: 'KS_PRISMA_ERROR',
prisma: { clientVersion: '3.2.1', code, meta: { target } },
prisma: { clientVersion: '3.3.0', code, meta: { target } },
},
path,
message,
Expand Down

0 comments on commit b988935

Please sign in to comment.