我想为 GraphQL Playground 定义一些 http 标头,默认启用和/或始终启用。本质上,我想补充:
"apollographql-client-name": "playground"
"apollographql-client-version": "yada-yada"
能够将来自操场的请求与 Apollo Studio 上的任何其他请求区分开来。最好的方法是什么?
通过 GraphQL Playground,我指的是 Apollo 运行的那个,这里记录的那个:https ://www.apollographql.com/docs/apollo-server/testing/graphql-playground/
我当前的 ApolloServer 配置如下所示:
let apolloServerExpressConfig: ApolloServerExpressConfig = {
schema: schema,
playground: {
settings: {
"request.credentials": "include",
},
},
}
如果我添加标签以尝试定义标题,如下所示:
let apolloServerExpressConfig: ApolloServerExpressConfig = {
schema: schema,
playground: {
settings: {
"request.credentials": "include",
},
tabs: [{
headers: {
"apollographql-client-name": "playground",
"apollographql-client-version": "yada-yada",
},
}],
},
}
重新加载页面时,GraphQL 游乐场不再恢复所有选项卡及其查询,这非常有用。我认为一旦您定义了选项卡,就会删除一些自动选项卡管理。我很高兴为新选项卡创建定义了默认标题,如果这些标题暴露给客户端就可以了。
我的应用程序已经定义了标题,因此,我可以区分应用程序和查询它的任何其他内容,但我想区分我的应用程序、游乐场和其他任何内容(后一组应该为空)。