运行项目时,出现这样的错误:初始化Keystone时出现错误
错误:适配器类型“mongoose”不支持字段类型“CloudinaryImage”。我该如何解决?
答案 0 :(得分:0)
import { createAuth } from '@keystone-next/auth';
import { config, createSchema } from '@keystone-next/keystone/schema';
import {
withItemData,
statelessSessions,
} from '@keystone-next/keystone/session';
import { KeystoneContext } from '@keystone-next/types';
import { permissionsList } from './schemas/fields';
import { Role } from './schemas/Role';
import { Listing } from './schemas/Listing';
import { ListingImage } from './schemas/ListingImage';
import { Profile } from './schemas/Profile';
import { User } from './schemas/User';
import { PersonalInfo } from './schemas/PersonalInfo';
import { TaskerProfile } from './schemas/TaskerProfile';
import { WorkPlace } from './schemas/WorkPlace';
import { Calendar } from './schemas/Calendar';
import { ClosingMessage } from './schemas/ClosingMessages';
import { OngoingClosingMessage } from './schemas/OngoingClosingMessages';
import { PromoteYourself } from './schemas/PromoteYourself';
import { Payment } from './schemas/Payments';
import { Support } from './schemas/Support';
import 'dotenv/config';
import { extendGraphqlSchema } from './mutations';
const databaseURL = process.env.DATABASE_URL;
const sessionConfig = {
maxAge: 60 * 60 * 24 * 360,
secret: process.env.COOKIE_SECRET,
};
const { withAuth } = createAuth({
listKey: 'User',
identityField: 'email',
secretField: 'password',
initFirstItem: {
fields: ['name', 'email', 'password'],
// TODO: Add in inital roles here
},
// passwordResetLink: {
// async sendToken(args) {
// // send the email
// await sendPasswordResetEmail(args.token, args.identity);
// },
// },
});
export default withAuth(
config({
server: {
cors: {
origin: true, // TODO: add only allowed URLs -> [process.env.CUSTOMER_PORTAL,...]
credentials: true,
},
port: process.env.SERVER_PORT,
},
db: {
adapter: 'mongoose',
url: databaseURL,
// eslint-disable-next-line @typescript-eslint/require-await
async onConnect(keystone) {
console.log('Connected to the database!');
// if (process.argv.includes('--seed-data')) {
// await insertSeedData(keystone);
// }
},
},
lists: createSchema({
// Schema items go in here
User,
Role,
Listing,
ListingImage,
Profile,
PersonalInfo,
Calendar,
ClosingMessage,
OngoingClosingMessage,
PromoteYourself,
Payment,
Support,
WorkPlace,
TaskerProfile
}),
extendGraphqlSchema,
ui: {
// Show the UI only for people who pass this test
isAccessAllowed: ({ session }) =>
// console.log(session);
!!session?.data,
},
session: withItemData(statelessSessions(sessionConfig), {
// GraphQL Query
User: `id name email role { ${permissionsList.join(' ')} }`,
}),
images: {
upload: 'local',
local: {
storagePath: 'public/images',
baseUrl: '/images',
},
},
})
);
答案 1 :(得分:0)
import 'dotenv/config';
import { relationship, text } from '@keystone-next/fields';
import { list } from '@keystone-next/keystone/schema';
import { cloudinaryImage } from '@keystone-next/cloudinary';
import { isSignedIn, permissions } from '../access';
export const cloudinary = {
cloudName: process.env.CLOUDINARY_CLOUD_NAME,
apiKey: process.env.CLOUDINARY_KEY,
apiSecret: process.env.CLOUDINARY_SECRET,
folder: 'abdul',
};
export const ListingImage = list({
access: {
create: () => true,
read: () => true, // this is required to make the entity public
update: () => true,
delete: () => true,
},
fields: {
image: cloudinaryImage({
cloudinary,
label: 'Source',
}),
altText: text(),
listing: relationship({
ref: 'Listing.photo',
ui: {
displayMode: 'select'
}
}),
},
ui: {
listView: {
initialColumns: ['image', 'altText', 'listing'],
},
},
});