【发布时间】:2020-02-11 07:15:40
【问题描述】:
我正在使用 neo4j-graphql-js 库将 graphql 查询转换为密码,我需要实现一个拦截器来验证返回的内容是否属于请求它的用户。为此,我需要实现拦截器,但我遇到的问题是我没有解析器,因为它会生成利比里亚。我怎样才能让它通过拦截器?如果无法使用拦截器,有没有办法在响应中实现一个中间件?
我正在使用nestjs 框架。我使用neo4j 数据库。
谢谢。
模块:
@Module({
imports: [
GraphQLModule.forRootAsync({
useClass: GraphqlConfigService,
}),
],
providers: [neo4jProvider],
})
export class GraphqlModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(GraphQLAuthMiddleware,GraphQLRoleMiddleware)
.forRoutes('graphql');
}
}
@Injectable()
export class GraphqlConfigService implements GqlOptionsFactory {
async createGqlOptions(): Promise<GqlModuleOptions> {
const schema = buildSchema();
return {
playground: true,
schema: schema,
path: '/graphql/queries',
context: {
driver: neo4j.driver(
'bolt://neo4j_db:7687',
neo4j.auth.basic('neo4j', 'root')
)
}
};
}
}
function buildSchema(): GraphQLSchema {
return makeAugmentedSchema({
typeDefs,
config: {
query: true,
mutation: true
}
});
}
【问题讨论】:
标签: javascript neo4j graphql interceptor nestjs