Skip to content

Commit

Permalink
Merge branch 'main' into renovate/lock-file-maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens authored Oct 26, 2021
2 parents f167fa6 + c723eb8 commit 22662f4
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-beds-yawn.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions .changeset/sour-snails-flash.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion packages/keystone/package.json
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions packages/keystone/src/lib/server/createApolloServer.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1498,10 +1498,10 @@
dependencies:
tslib "~2.3.0"

"@graphql-ts/schema@0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@graphql-ts/schema/-/schema-0.3.1.tgz#d98eefce24212c20808a43338ce014ebae1ca6d7"
integrity sha512-sPK1dXo0HEk4+DkMm9eE1MeylcDxtjK/sAKJJ4FJbYKK5F0gew7ohszVfgidVwk1nrjcT2/SWncdwM3plBX28g==
"@graphql-ts/schema@0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@graphql-ts/schema/-/schema-0.5.0.tgz#cc9cbf614ed931aff4c9987e88094a4030ad9e32"
integrity sha512-uljlEm6hRk92MG3XMXpKfSWzJ+03MXRLbsmGj5alZ/gbfS+CJkeh+hsvQOjwPD1EL5RhCE7L3E/zDWjH6W+V6g==
dependencies:
"@babel/runtime" "^7.9.2"

Expand Down

0 comments on commit 22662f4

Please sign in to comment.