Tag: graphql js

GraphiQL返回nil变异

我使用Seqelize GraphQL,我有一个返回null的变异。 我试过用不同的几种方法来改变这个变种的parsing器,但是当我用GraphiQL来testing的时候它总是返回null。 下面是用几种不同的方式写的parsing器: 1 – 最初,我有想法添加包装function的承诺。 resolve(root, args) { return new Promise((resolve, reject) => { db.record.findOne({ where: { UID: args.UID } }) .then(record => { let newArr = undefined if (record.watched == null) { newArr = [args.value] } else { let old = record.watched newArr = old.concat([args.value]) } db.record.update({ watched: newArr }, { where: […]

如何编写graphql的中间件,这将在每个parsing器之前调用

在每一个请求我发送令牌,并检查它在快递中间件 app.use(async (req, res, next) => { const authorization = req.headers.authorization; let token = null; let user; if (authorization) { try { token = jwt.verify(authorization, config.secret); } catch (e) { // dont work throw new GraphQLError({ message: 'token damaged' }); } if (token) { const { _id } = token; user = await User.findOne({ _id […]

GraphQL jsfile upload

我看到一些Relay的例子,但我使用Apollo的graphQL,找不到任何例子或文件如何通过变异处理file upload在GraphQL中?

在Google Cloud App Engine上运行GraphQL服务器

在node.js本地运行端点,我在我的app.js中使用下面的代码片段 app.use('/graphql', (0, _expressGraphql2.default)(function (req) { return { schema: _schema2.default, pretty: true, context: _extends({ db: _models2.default }, (0, _isUser2.default)(req.headers['authorization'].split(' ')[1])) }; })); app.listen(8080, function () { 但是,我的应用程序没有收到来自端点的任何响应,试图访问主机名:8080 / graphql。 这在我的本地机器上工作。

GraphQL:从兄弟parsing器访问另一个parsing器/字段输出

需要一些帮助。 假设我要求以下数据: { parent { obj1 { value1 } obj2 { value2 } } } 我需要在value1parsing器中计算value2的结果。 在价值2中回复承诺的想法,并以某种方式将其置于价值1解决scheme,但如果价值2parsing器没有运行呢? 有什么办法可以做?

架构没有configuration为突变

我有以下架构: import { GraphQLSchema, GraphQLObjectType, GraphQLInt, GraphQLString } from 'graphql'; let counter = 100; const schema = new GraphQLSchema({ // Browse: http://localhost:3000/graphql?query={counter,message} query: new GraphQLObjectType({ name: 'Query', fields: () => ({ counter: { type: GraphQLInt, resolve: () => counter }, message: { type: GraphQLString, resolve: () => 'Salem' } }) }), mutiation: new GraphQLObjectType({ name: […]

如何从需要返回语句的GraphQLparsing器中调用asynchronousnode.js函数?

graphql.org/graphql-js提供的用于创build简单GraphQL实现的Hello World示例如下: var { graphql, buildSchema } = require('graphql'); // Construct a schema, using GraphQL schema language var schema = buildSchema(` type Query { hello: String } `); // The root provides a resolver function for each API endpoint var root = { hello: () => { return 'Hello World!'; } }; // Run the […]

GraphQL – 传递非特定对象的对象作为参数

我对GraphQL很新颖。 我试图传递一个这样的对象作为参数: { filters: { status: 'approved', id: { LESS_THAN: 200 } } } 或者这个对象也可以是这样的; { filters: { status: ['approved', 'pending'], id: 200 } } 我知道可以在此对象中的所有属性,但所有这些属性可以是string/ int或对象。 我试图这样定义它,但它显然不工作: args: { filters: { type: new GraphQLNonNull(new GraphQLNonNull(GraphQLString)) }, }, 我想用GraphQLtypesGraphQLInputObjectType来定义参数。 const OffersFiltersType = new GraphQLInputObjectType({ name: 'Filters', description: '…', fields: () => ({}) id: { type: […]

订阅GraphQL Server时出错

我对GraphQl相当陌生,我在这里遵循GraphQL NodeJS后端教程: GraphQL实时订阅 。 一切运作良好,我完成了教程。 接下来我跟着阿波罗前端教程在这里VueJS: Vue&Apollo订阅 。 我从第一个教程中select使用自己创build的GraphQL服务器,而不是使用前端教程中使用的GraphCool。 这是我卡住的部分。 如果我打电话 subscription { Link(filter: { mutation_in: [CREATED] }) { node { id url description } } } 在GraphiQL客户端中,当我使用数据data: Link: node: {id: "59ef0bbeef32bb05692ee4b4", url: "http://new-test-url2.com", description: "Test description2"}在不同的浏览器选项卡中创build一个新的链接时,我获得了id , url和description data: Link: node: {id: "59ef0bbeef32bb05692ee4b4", url: "http://new-test-url2.com", description: "Test description2"} (此订阅调用也在后端教程中进行)。 但是当我打电话 subscription { Link(filter: { […]

NodeJs GraphQLdynamic查询variables

https://launchpad.graphql.com/9qvqz3v5r 这是我的graphQL例子 如果我通过userId:2作为静态 { user(userId:2){ firstName lastName } } 我会得到如下输出 { "data": { "user": { "firstName": "Joe", "lastName": "spin" } } } 我需要使用dynamic查询variables相同的输出 query getUserNameData($userId: User){ user(userId:$userId){ firstName lastName } } query variables { "userId" : 2 } 但我getter错误为:variables\“$ userId \”不能是非inputtypes\“用户http://prntscr.com/h2ojor 谁能帮我?