自定义 Keystonejs 服务器端函数:“没有名为‘public’的可执行模式";错误 [英] Custom Keystonejs server-side functions: "No executable schema named 'public'" error
问题描述
我需要向 KeystoneJS 实例添加一些自定义服务器端函数.下面是一个简单的例子;函数 userCount
已添加到初始化 Keystone 的文件的导出中,该文件应返回用户数.
module.exports = {基石,应用: [新的 GraphQLApp(),新的 AdminUIApp({名称:PROJECT_NAME,enableDefaultRoute: 真,身份验证策略,}),],userCount: async() =>{尝试 {const context = keystone.createContext({ skipAccessControl: true });控制台日志(上下文);//下面输出const userCount = await keystone.executeGraphQL({语境,查询:`查询{_allUsersMeta {数数}}`,});返回用户数;} 捕捉(错误){返回错误;}}};
Context
似乎是使用架构名称 public
正确创建的(请参阅下面的控制台日志),但无论我尝试什么,我都会收到以下错误:><块引用>
没有名为public"的可执行架构可用.你设置了'@keystonejs/app-graphql'吗?
这似乎与下面的日志矛盾.我做错了什么?
console.log(context)
输出:
<代码>{架构名称:'公共',已认证项目:未定义,authedListKey:未定义,getCustomAccessControlForUser: [功能: getCustomAccessControlForUser],getListAccessControlForUser: [功能: getListAccessControlForUser],getFieldAccessControlForUser: [功能: getFieldAccessControlForUser],getAuthAccessControlForUser:[功能:getAuthAccessControlForUser],总结果: 0,maxTotalResults: 1000,创建上下文:[功能],executeGraphQL: [功能],gqlNames: [功能]}
问题的原因似乎是我使用单独的 Express 实例处理 GET 请求,除了基石.
解决方案是将我所有的 Express 逻辑(例如自定义端点)添加到 Keystone index.js
文件中的 configureExpress
导出,按照这些说明.
自定义服务器 可以设置为更复杂的实现.
I need to add some custom server-side functions to my KeystoneJS instance. Below is a simple example; the function userCount
has been added to the exports of the file that initialises Keystone, which should return a count of the number of users.
module.exports = {
keystone,
apps: [
new GraphQLApp(),
new AdminUIApp({
name: PROJECT_NAME,
enableDefaultRoute: true,
authStrategy,
}),
],
userCount: async () => {
try {
const context = keystone.createContext({ skipAccessControl: true });
console.log(context); // Output below
const userCount = await keystone.executeGraphQL({
context,
query: `query {
_allUsersMeta {
count
}
}`,
});
return userCount;
} catch (error) {
return error;
}
}
};
Context
seems to be correctly created with the schema name public
(see console log below), but no matter what I try, I get the following error:
No executable schema named 'public' is available. Have you setup '@keystonejs/app-graphql'?
This seems to contradict the log below. What am I doing wrong?
console.log(context)
output:
{
schemaName: 'public',
authedItem: undefined,
authedListKey: undefined,
getCustomAccessControlForUser: [Function: getCustomAccessControlForUser],
getListAccessControlForUser: [Function: getListAccessControlForUser],
getFieldAccessControlForUser: [Function: getFieldAccessControlForUser],
getAuthAccessControlForUser: [Function: getAuthAccessControlForUser],
totalResults: 0,
maxTotalResults: 1000,
createContext: [Function],
executeGraphQL: [Function],
gqlNames: [Function]
}
The cause of the problem seems to be that I was handling GET requests with a separate Express instance, which I'd set up in addition to the instance used by Keystone.
The solution was to add all my Express logic (e.g. custom endpoints) to the configureExpress
export in the Keystone index.js
file, as per these instructions.
A custom server can be setup for more complicated implementations.
这篇关于自定义 Keystonejs 服务器端函数:“没有名为‘public’的可执行模式";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!