type;缺少类型' graphqlschema&#x27的属性。

发布于 2025-01-20 23:01:26 字数 496 浏览 2 评论 0原文

我正在尝试将Apollo服务器作为打字条中的云函数启动,并希望在我的TypeDefs中使用@Cypher和@relationship Directives。

要使用这些指令,我正在使用“@neo4j/graphQl”:“^3.0.0”。

在为阿波罗服务器提供架构时,我会遇到错误。 GetSchema()返回承诺,但ApollServer期望类型GraphQl模式的模式。

const neoSchema = new Neo4jGraphQL({ typeDefs });

const server = new ApolloServer({
  schema: neoSchema.getSchema(),
  context: ({ req }) => ({
    headers: req.headers,
    req,
  }),
});

exports.handler = server.createHandler();

如果有人可以在这里帮助我,真的会很感激。

I am trying to launch an Apollo Server as a cloud function in typescript and want to use @cypher and @relationship directives in my typeDefs.

To use these directives I am using "@neo4j/graphql": "^3.0.0".

I am getting errors while providing schema to the apollo server. getSchema() returns a Promise but ApollServer expects a schema of type GraphQL Schema.

const neoSchema = new Neo4jGraphQL({ typeDefs });

const server = new ApolloServer({
  schema: neoSchema.getSchema(),
  context: ({ req }) => ({
    headers: req.headers,
    req,
  }),
});

exports.handler = server.createHandler();

Would really appreciate it if someone can help me out here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赏烟花じ飞满天 2025-01-27 23:01:26

Apollo服务器在此步骤中无法履行承诺,并且您无法进行顶级等待(除非您在Typescript.next上),因此您必须将其包装在另一个功能中。

危险:

如果您不记忆一下,请不要跳过这一点,您将在每个调用中创建一个新的处理程序,这会使您对文件描述符泄漏打开。这样做的症状是,您将开始获得所有内容(包括DNS查找)的超时,因此您将开始在代码中获得Enotfound错误。我已经为您的后代添加了评论:


const neoSchema = new Neo4jGraphQL({ typeDefs });
let _cachedHandler: ReturnType<ApolloServer['createHandler']>;

/**
 * We have to be careful here that we're not creating a new server on EVERY invocation
 * because that will create a file descriptor leak. Make sure you're using a memoized cache
 */
const memoizedHandler = async (event, context) => {
  if (!_cachedHandler) {
    const server = new ApolloServer({
      schema: await neoSchema.getSchema(),
      context: ({ req }) => ({
        headers: req.headers,
        req,
      }),
    });
    // this is the actual handler
    _cachedHandler = server.createHandler();
  }
  // now we can just call the handler
  return _cachedHandler(event, context);
}

exports.handler = memoizedHandler;

Apollo Server can't handle a promise at this step, and you can't do top-level awaits (unless you're on typescript.next), so you have to wrap this in another function.

DANGER: DON'T SKIP THIS BIT

If you don't memoize this, you'll create a new handler on every invocation, which opens you up to a file descriptor leak. The symptom of this is that you'll start getting timeouts for EVERYTHING (including DNS lookups), so you'll start getting ENOTFOUND errors in your code. I've added a comment for your future generations:


const neoSchema = new Neo4jGraphQL({ typeDefs });
let _cachedHandler: ReturnType<ApolloServer['createHandler']>;

/**
 * We have to be careful here that we're not creating a new server on EVERY invocation
 * because that will create a file descriptor leak. Make sure you're using a memoized cache
 */
const memoizedHandler = async (event, context) => {
  if (!_cachedHandler) {
    const server = new ApolloServer({
      schema: await neoSchema.getSchema(),
      context: ({ req }) => ({
        headers: req.headers,
        req,
      }),
    });
    // this is the actual handler
    _cachedHandler = server.createHandler();
  }
  // now we can just call the handler
  return _cachedHandler(event, context);
}

exports.handler = memoizedHandler;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文