Skip to content

Commit

Permalink
Merge branch 'master' into remove-custom-access-control
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Mar 17, 2021
2 parents 0a31792 + db94f9c commit a0fcdc3
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
const { multiAdapterRunners, setupFromConfig } = require('@keystone-next/test-utils-legacy');
import {
AdapterName,
multiAdapterRunners,
setupFromConfig,
testConfig,
} from '@keystone-next/test-utils-legacy';
import { createSchema, list, graphQLSchemaExtension, gql } from '@keystone-next/keystone/schema';
import { text } from '@keystone-next/fields';

const falseFn = () => false;
const falseFn: (...args: any) => boolean = () => false;

const withAccessCheck = (access, resolver) => {
return (...args) => {
const withAccessCheck = <T, Args extends unknown[]>(
access: boolean | ((...args: Args) => boolean),
resolver: (...args: Args) => T
): ((...args: Args) => T) => {
return (...args: Args) => {
if (typeof access === 'function') {
if (!access(...args)) {
throw new Error('Access denied');
Expand All @@ -17,15 +25,15 @@ const withAccessCheck = (access, resolver) => {
};
};

function setupKeystone(adapterName) {
function setupKeystone(adapterName: AdapterName) {
return setupFromConfig({
adapterName,
config: createSchema({
lists: {
config: testConfig({
lists: createSchema({
User: list({
fields: { name: text() },
}),
},
}),
extendGraphqlSchema: graphQLSchemaExtension({
typeDefs: gql`
type Query {
Expand All @@ -52,7 +60,7 @@ function setupKeystone(adapterName) {

multiAdapterRunners().map(({ runner, adapterName }) =>
describe(`Adapter: ${adapterName}`, () => {
describe('keystone.extendGraphQLSchema()', () => {
describe('extendGraphqlSchema', () => {
it(
'Executes custom queries correctly',
runner(setupKeystone, async ({ context }) => {
Expand Down

0 comments on commit a0fcdc3

Please sign in to comment.