Skip to content

Commit

Permalink
Move getSchemaExtension code into own file (#4964)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Mar 1, 2021
1 parent 1f315bb commit 10852a1
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-clocks-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/auth': patch
---

Moved the `getSchemaExtension` code into its own file for easier documentation.
69 changes: 3 additions & 66 deletions packages-next/auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,16 @@
import url from 'url';
import { mergeSchemas } from '@graphql-tools/merge';
import {
AdminFileToWrite,
BaseGeneratedListTypes,
KeystoneConfig,
ExtendGraphqlSchema,
KeystoneContext,
} from '@keystone-next/types';
import { password, timestamp } from '@keystone-next/fields';

import { AuthConfig, Auth, AuthGqlNames, AuthTokenTypeConfig } from './types';

import { getBaseAuthSchema } from './gql/getBaseAuthSchema';
import { getInitFirstItemSchema } from './gql/getInitFirstItemSchema';
import { getPasswordResetSchema } from './gql/getPasswordResetSchema';
import { getMagicAuthLinkSchema } from './gql/getMagicAuthLinkSchema';

import { AuthConfig, Auth, AuthGqlNames } from './types';
import { getSchemaExtension } from './schema';
import { signinTemplate } from './templates/signin';
import { initTemplate } from './templates/init';
import { KeystoneContext } from '@keystone-next/types';

const getSchemaExtension = ({
identityField,
listKey,
protectIdentities,
secretField,
gqlNames,
initFirstItem,
passwordResetLink,
magicAuthLink,
}: {
identityField: string;
listKey: string;
protectIdentities: boolean;
secretField: string;
gqlNames: AuthGqlNames;
initFirstItem?: any;
passwordResetLink?: any;
magicAuthLink?: AuthTokenTypeConfig;
}): ExtendGraphqlSchema => (schema, keystone) =>
[
getBaseAuthSchema({
identityField,
listKey,
protectIdentities,
secretField,
gqlNames,
}),
initFirstItem &&
getInitFirstItemSchema({
listKey,
fields: initFirstItem.fields,
itemData: initFirstItem.itemData,
gqlNames,
keystone,
}),
passwordResetLink &&
getPasswordResetSchema({
identityField,
listKey,
protectIdentities,
secretField,
passwordResetLink,
gqlNames,
}),
magicAuthLink &&
getMagicAuthLinkSchema({
identityField,
listKey,
protectIdentities,
magicAuthLink,
gqlNames,
}),
]
.filter(x => x)
.reduce((s, extension) => mergeSchemas({ schemas: [s], ...extension }), schema);

/**
* createAuth function
Expand Down
64 changes: 64 additions & 0 deletions packages-next/auth/src/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { mergeSchemas } from '@graphql-tools/merge';
import { ExtendGraphqlSchema } from '@keystone-next/types';

import { AuthGqlNames, AuthTokenTypeConfig } from './types';
import { getBaseAuthSchema } from './gql/getBaseAuthSchema';
import { getInitFirstItemSchema } from './gql/getInitFirstItemSchema';
import { getPasswordResetSchema } from './gql/getPasswordResetSchema';
import { getMagicAuthLinkSchema } from './gql/getMagicAuthLinkSchema';

export const getSchemaExtension = ({
identityField,
listKey,
protectIdentities,
secretField,
gqlNames,
initFirstItem,
passwordResetLink,
magicAuthLink,
}: {
identityField: string;
listKey: string;
protectIdentities: boolean;
secretField: string;
gqlNames: AuthGqlNames;
initFirstItem?: any;
passwordResetLink?: any;
magicAuthLink?: AuthTokenTypeConfig;
}): ExtendGraphqlSchema => (schema, keystone) =>
[
getBaseAuthSchema({
identityField,
listKey,
protectIdentities,
secretField,
gqlNames,
}),
initFirstItem &&
getInitFirstItemSchema({
listKey,
fields: initFirstItem.fields,
itemData: initFirstItem.itemData,
gqlNames,
keystone,
}),
passwordResetLink &&
getPasswordResetSchema({
identityField,
listKey,
protectIdentities,
secretField,
passwordResetLink,
gqlNames,
}),
magicAuthLink &&
getMagicAuthLinkSchema({
identityField,
listKey,
protectIdentities,
magicAuthLink,
gqlNames,
}),
]
.filter(x => x)
.reduce((s, extension) => mergeSchemas({ schemas: [s], ...extension }), schema);

1 comment on commit 10852a1

@vercel
Copy link

@vercel vercel bot commented on 10852a1 Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.