【问题标题】:How can i set my ApolloServer to open a graphql playground instead of the apollographql sandbox by default?我如何设置我的 ApolloServer 默认打开一个 graphql 游乐场而不是 apollographql 沙箱?
【发布时间】:2021-10-18 20:48:19
【问题描述】:

我的问题是,当我访问 http://hocalhost/port/graphql 时,如何将 this graphql playground extension 设置为我的默认游乐场,而不是使用默认的 sandbox。在创建ApolloServer 实例的过程中,我是否可以设置任何选项来配置它?

...
const apolloServer = new ApolloServer({
    schema: await buildSchema({
      validate: false,
      resolvers: [HelloResolver, UserResolver],
    }),
    context: ({ req, res }) => ({ em: orm.em, req, res }),
  });
  await apolloServer.start();
  apolloServer.applyMiddleware({ app });

....

【问题讨论】:

    标签: graphql apollo-server


    【解决方案1】:

    使用 GraphQL Playground 插件并将其提供给您的 Apollo Server 构造函数。 For more info checkout Apollo Docs.

    import {
      ApolloServerPluginLandingPageGraphQLPlayground
    } from "apollo-server-core";
    
    const apolloServer = new ApolloServer({
      ...
      plugins: [
        ApolloServerPluginLandingPageGraphQLPlayground(),
      ],
    });

    【讨论】:

      猜你喜欢
      • 2019-07-14
      • 2021-10-22
      • 2021-04-03
      • 2020-06-03
      • 2017-07-25
      • 2021-11-16
      • 1970-01-01
      • 2021-03-28
      • 2022-07-24
      相关资源
      最近更新 更多