如何获取上下文中的操作名称?在解析器中我可以通过参数得到它info。
import { ApolloServer } from 'apollo-server'
const server = new ApolloServer({
context: ({ req }) => {
// Get query/mutation operation name like getAllUsers
}
})
server.listen()
Run Code Online (Sandbox Code Playgroud) 我无法使用 apollo Studio。迁移到 Graphql 游乐场后。当我尝试在本地主机中运行并将我重定向到 apollo studio sanbox https://studio.apollographql.com/sandbox?endpoint=http%3A%2F%2Flocalhost%3A5018%2Fgraphql时:无法连接到本地主机。
请帮忙解决这个问题
我正在尝试设置我的服务器端后端,但遇到了此错误:
node_modules/apollo-cache-control/dist/index.d.ts:24:9 - error TS2717: Subsequent property declarations must have the same type. Property 'cacheControl' must be of type 'ResolveInfoCacheControl', but here has type '{ setCacheHint: (hint: CacheHint) => void; cacheHint: CacheHint; }'.
24 cacheControl: {
~~~~~~~~~~~~
node_modules/@nestjs/graphql/node_modules/apollo-server-types/dist/index.d.ts:140:9
140 cacheControl: ResolveInfoCacheControl;
~~~~~~~~~~~~
'cacheControl' was also declared here.
Run Code Online (Sandbox Code Playgroud) 上下文: 我正在尝试通过 Netlify 使用 Apollo Server Lambda 部署 GraphQL。我的处理程序如下:
代码:
exports.handler = server.createHandler({
cors: {
origin: '*'
}
});
Run Code Online (Sandbox Code Playgroud)
我能够在 Netlify 上成功构建和部署 - 但是服务器在启动时抛出错误。Netlify 正在寻找要触发的事件,但我使用的 Apollo Server 处理程序没有提供。我们如何将此处理程序连接到使用事件的处理程序?
错误信息:
{"errorType":"Error","errorMessage":"Unable to determine event source based on event.","trace":["Error: Unable to determine event source based on event."," at getEventSourceNameBasedOnEvent (/var/task/node_modules/@vendia/serverless-express/src/event-sources/utils.js:88:9)"," at proxy (/var/task/node_modules/@vendia/serverless-express/src/configure.js:38:51)"," at handler (/var/task/node_modules/@vendia/serverless-express/src/configure.js:99:12)"," at Runtime.handler (/var/task/node_modules/apollo-server-lambda/dist/ApolloServer.js:51:27)"]}
Run Code Online (Sandbox Code Playgroud) 我没有为此应用程序使用 AWS AppSync。我已经创建了 Graphql 模式,我已经制作了自己的解析器。对于每个创建、查询,我都创建了每个 Lambda 函数。我使用了 DynamoDB 单表概念及其全局二级索引。
创建一个 Book 项目对我来说没问题。在 DynamoDB 中,该表如下所示:
。
我在返回 Graphql 查询时遇到问题。从 DynamoDB 表获取后Items,我必须使用 Map 函数,然后返回Items基于 Graphql 的表type。我觉得这不是有效的方法。我不知道查询数据的最佳方式。另外,我的作者和作者查询都为空。
这是我的gitlab 分支。
这是我的 Graphql 架构
import { gql } from 'apollo-server-lambda';
const typeDefs = gql`
enum Genre {
adventure
drama
scifi
}
enum Authors {
AUTHOR
}
# Root Query - all the queries supported by the schema
type Query {
"""
All Authors query
"""
authors(author: …Run Code Online (Sandbox Code Playgroud)我想向 apollo 服务器添加一个验证层。它应该在每个 graphql 查询/突变之后但在解析器函数之前运行。验证层需要知道被调用的 graphql 查询/变异以及传递的参数。如果无效,它将抛出错误并阻止解析器功能运行。
我不清楚在哪里注入它而不手动将它放在每个解析器函数中。
首先,我实际上是在Stack Overflow上发帖的新手,但我当然会尽我所能在此处提供所有相关信息并分享找到的解决方案,因为我可以想象会有更多的人对此感到麻烦。
因此,我们从一个以多个小型微服务为后端的系统开始,我们发现了Apollo服务器,它能够从graphql端点检索模式并将它们缝合在一起,因此我们可以有一个不错的切入点。我们已经可以工作了,但是apollo服务器并没有真正帮助总体架构的工具。那就是我们找到NestJS的原因,因为我们在前端使用了angular,并且NestJS非常相似,因此看起来很合适。
但是,我们遇到的问题是我们似乎无法使以下功能正常工作:-我希望有一个模块,其中包含可以被赋予多个端点(从uri到微服务)的服务-具有这些功能给定的服务应从这些端点检索graphQL模式,并将其制成RemoteExecutableSchemas,然后将它们合并。-合并它们并使用(远程)链接信息制作1个大架构,以便graphQL知道从何处获取数据。-发生这种情况后,我们想添加一些针脚以使所有关系都存在(但这不是我的问题所在)
我一直在浏览官方文档(https://docs.nestjs.com/graphql/quick-start)的示例(https://github.com/nestjs/nest/tree/master/sample/ 12-graphql-apollo),当然也签出了github项目(https://github.com/nestjs/graphql),并在此仓库中整理了一下代码,以查看代码在后台执行的操作。
我们已经尝试了几种方法来即时获取它们,但是无法在实例化之前将模式放入GraphQLModule中。然后,我们认为让服务从端点检索graphqlSchema并使用实际起作用的printSchema(schema)将其写入文件中是可以接受的,但是随后我丢失了链接信息,从而使该信息成为本地模式而不是远程模式。现在,我们提出了以下建议,但再次陷入困境。
让我们从我的package.json中的一个小片段开始,以便人们知道版本:)
"dependencies": {
"@nestjs/common": "^5.4.0",
"@nestjs/core": "^5.4.0",
"@nestjs/graphql": "^5.5.1",
"apollo-link-http": "^1.5.9",
"apollo-server-express": "^2.3.2",
"graphql": "^14.1.1",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^6.2.2",
"typescript": "^3.0.1"
},
"devDependencies": {
"@nestjs/testing": "^5.1.0",
"@types/express": "^4.16.0",
"@types/jest": "^23.3.1",
"@types/node": "^10.7.1",
"@types/supertest": "^2.0.5",
"jest": "^23.5.0",
"nodemon": "^1.18.3",
"prettier": "^1.14.2",
"supertest": "^3.1.0",
"ts-jest": "^23.1.3",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.5.0",
"tslint": "5.11.0"
},
Run Code Online (Sandbox Code Playgroud)
因此,目前我有一个架构处理程序模块,如下所示:
@Module({
imports: [GraphQLModule.forRootAsync({
useClass: GqlConfigService
})],
controllers: [SchemaHandlerController],
providers: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Angular Apollo 作为客户端和 Apollo 2.0 作为服务器上传文件。
相信我,我尝试了所有教程,例如我可以在互联网上找到但没有帮助的示例。有一个名为 apollo-upload-file 的库,他们给出了如何实现它的示例,但在客户端他们使用了 React。虽然我尝试实施他的例子,但没有任何效果。
请帮忙。
所以可能这是一个非常基本的问题,所以请耐心等待。让我解释一下我在做什么以及我真正需要什么。
解释
我使用ApolloGraphql(apollo-server-express npm 模块)创建了一个 graphql 服务器。
这是给你一个想法的代码片段。
api.js
import express from 'express'
import rootSchema from './root-schema'
.... // some extra code
app = express.router()
app.use(jwtaAuthenticator) // --> this code authenticates Authorization header
.... // some more middleware's added
const graphQLServer = new ApolloServer({
schema: rootSchema, // --> this is root schema object
context: context => context,
introspection: true,
})
graphQLServer.applyMiddleware({ app, path: '/graphql' })
Run Code Online (Sandbox Code Playgroud)
服务器.js
import http from 'http'
import express from 'express'
import apiRouter from './api' …Run Code Online (Sandbox Code Playgroud) 在遇到问题后,我自己尝试了一些东西,我尝试了文档中的示例,但遇到了类似的问题,文档是错误的,还是我在做一些愚蠢的事情?
我尝试执行的示例是此页面中的示例:https : //www.apollographql.com/docs/apollo-server/federation/introduction/
相关的一段代码是:
const server = new ApolloServer({
schema: buildFederatedSchema([{
typeDefs: gql`
extend type Query {
me: User
}
type User @key(fields: "id") {
id: ID!
username: String!
}
`,
resolvers: [],
}, {
typeDefs: gql`
extend type Query {
topProducts(first: Int = 5): [Product]
}
type Product @key(fields: "upc") {
upc: String!
name: String!
price: Int
}
`,
resolvers: [],
}, {
typeDefs: gql`
type Review {
body: String
author: User @provides(fields: "username")
product: Product
} …Run Code Online (Sandbox Code Playgroud) apollo-server ×10
graphql ×7
apollo ×4
angular ×1
aws-lambda ×1
graphql-js ×1
javascript ×1
nestjs ×1
netlify ×1
node.js ×1
prisma ×1
prisma2 ×1
serverless ×1
typescript ×1