【问题标题】:Apollo Explorer not reflecting changes in source codeApollo Explorer 未反映源代码的更改
【发布时间】:2021-12-31 11:16:42
【问题描述】:

我一直在对源代码进行一些更改,但无法让它们显示在 Apollo Explorer Sandbox 中。例如,我在源代码中的一个解析器中添加了一些突变和一个额外的查询,但它们没有出现在 Apollo Sandbox 中。有什么想法吗?

import { Arg, Ctx, Int, Mutation, Query, Resolver } from "type-graphql";
import { Post } from "src/entities/Post";
import { MyContext } from "src/types";
import { idText } from "typescript";

@Resolver()
export class PostResolver {
    @Query(() => [Post])
    posts(@Ctx() { em }: MyContext): Promise<Post[]> {
        return em.find(Post, {});
    }

    @Query(() => Post, { nullable: true })
    post(@Arg("id", () => Int) id: number, @Ctx() { em }: MyContext): Promise<Post | null> {
        return em.findOne(Post, { id  });
    }

    @Mutation(() => Post)
    async createPost(
        @Arg("title") title: string,
        @Ctx() { em }: MyContext
    ): Promise<Post> {
        const post = em.create(Post, {title});
        await em.persistAndFlush(post);
        return post;
    }

    @Mutation(() => Post, {nullable: true})
    async updatePost(
        @Arg("id") id: number,
        @Arg("title", () => String, { nullable: true }) title: string,
        @Ctx() { em }: MyContext
    ): Promise<Post | null> {
        const post = await em.findOne(Post, { id });
        if (!post) {
            return null;
        }
        if (typeof title !== 'undefined') {
            post.title = title;
            await em.persistAndFlush(post);
        }
        return post;
    }
}

【问题讨论】:

    标签: node.js typescript graphql apollo-server


    【解决方案1】:

    我想通了。这只是 dist 文件夹中的 javascript 代码没有用打字稿代码更新的问题。使用 yarn watch 更新并修复了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      • 2018-01-31
      • 2014-06-16
      相关资源
      最近更新 更多