问题标签 [express-graphql]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
675 浏览

node.js - Node.js + express-graphql + passport 中的 JWT 身份验证

我正在使用 MERN 编写一个全栈应用程序,我需要使用 JWT 令牌提供身份验证。我的代码如下所示:

我想通过 GraphQL 提供新一代令牌。为此,我需要检查用户是否使用了正确的身份验证方法。例如,要获取新的访问令牌,您需要刷新令牌,您需要使用刷新令牌的密码和电子邮件登录。但是使用护照意味着在身份验证后我将只拥有一个用户。

我应该如何进行?

0 投票
0 回答
632 浏览

react-native - GraphQL Subscription Authentication Using AsyncStorage

Am trying to use subscription on my client app to send JWT Token and refreshToken to the server using WebSocketLink connectionParams. But the problem is that my token and refreshToken are saved inside AsynStorage that require me to use async await to get the value out. When i tried to use await, it send undefined to the server.

Here is the code below:

If i set a plan key, it will work. But i need to get the tokens form Async storage using await. How can i go about it?

0 投票
2 回答
676 浏览

graphql-js - GraphQL [graphql js] 循环依赖: * 的类型必须是 Output Type 但得到: [object Object]

编辑

添加了我的解决方案作为答案


原始问题

我相信这个问题与循环依赖有关。我昨晚度过了大部分时间,今天尝试了我能在网上找到的所有东西,但似乎没有任何效果。

我试过的:

  • fieldsprop 转换为返回字段对象的函数
  • 将相关字段(在 fields 属性内)转换为返回类型的函数
  • 结合上述两种方法
  • 最后以 require 语句代替使用引用类型的字段结束(似乎不正确,linter 对此有中风)

这是文件结构:

文件结构

这是代码:

userType.js

connectionType.js

0 投票
2 回答
2774 浏览

express-graphql - 无法读取 Object.renderGraphiQL 中未定义的属性“startsWith”

我正在阅读 udemy 的 GraphQL 教程,

https://www.udemy.com/introduction-to-graphql-and-apollo-building-modern-apis

我正在阅读操作 graphql 和 graphiql -> apollo -express - 服务器的指南。并得到了这个。视频中未定义此特定错误。这是一个免费的教程,第 9 课有这个。怎么办。我找不到解决办法。请帮忙。

renderGraphiQLString.js

这是它说有错误的行-->

解决GraphiQLString.js

服务器.js

0 投票
1 回答
3894 浏览

mongoose - 如何在 GraphQLObjectType 中定义对象字段?

所以我试图在 MongoDB 中创建一个 User 集合,并使用 GraphQL 和 mongoose 对其进行查询。

我在路径“pathToServer\server\models\user.js”中创建了我的用户模式,它看起来像这样:

我创建了一个 GraphQL 类型,目前我在路径 'pathToServer\server\schema\types\user.js' 中有它,它看起来像这样:

最后,我在路径 'pathToServer\server\schema\schema.js' 中有带有查询和突变的 GraphQL 模式:

问题是每当我启动服务器时它都会抛出一个错误:

也许我没有正确定义名称字段?我认为它可能会被区别对待,因为我的模型中的 name 字段是一个包含字段 firstName 和 lastName 的对象。

请你看一下好吗?

提前致谢!

编辑 我已经编辑了用户类型

现在服务器启动了,但它在 graphiql 中给了我这个错误:

0 投票
1 回答
808 浏览

express - express-graphql:如何删除外部“数据”对象层。

我正在用 GraphQL 替换现有的 REST 端点。

在我们现有的 REST 端点中,我们返回一个 JSON 数组。

GraphQL 似乎将数组包装在两个额外的对象层中。有没有办法删除“数据”和“客户端”层?

响应数据:

我的查询:

0 投票
1 回答
186 浏览

node.js - graphql:休息 API 连接

我想知道是否有办法使用graphql在name属性上加入两个 rest API 。这些是我的回应

我想用graphql来组合它们,这样

graphql 是正确的工具吗?

0 投票
1 回答
856 浏览

express - 从 graphql yoga 返回状态码

在我的解析器内部,我在解析器调用之前检查这个解析器是否受到保护。

如果解析器受到保护,并且用户未登录,我可能会抛出如下错误: return new Error('Token is missing');

这将停止执行请求并返回正确的消息形状,并带有错误字段。

但是响应的状态为 200,这是不正确的。我希望能够选择自己的状态,例如 403。

这是我当前的解析器实现:

我会在 express 中添加一个 before request 中间件,但是没有办法知道正在调用哪个查询,因为所有调用都是针对同一个端点完成的。

任何输入将不胜感激!

0 投票
3 回答
10362 浏览

angular - 拦截 Apollo/graphql 请求

我们在我们的应用程序中使用 Apollo/Graphql,但我们正面临一个问题。

该应用程序是在 Angular 5 中开发的,NodeJS 作为后端,带有将响应前端的 graphql 服务器。为了以角度拦截 Http 请求,我们实现了“HttpInterceptor”,以便我们可以以自定义方式处理错误。但是,Apollo 请求不会通过这个拦截器。

为了正确处理错误,我们使用了“apollo-link-error”。

但是我们想知道是否可以像 HttpInterceptor 一样拦截 apollo 请求。

0 投票
2 回答
403 浏览

javascript - GraphQL Connections

I have this relationship btw a user and its memberships. The memberships field is a connection between a user and multiple memberships.

The issue here is that I have this error where user field in MembershipType causes an error

Blockquote /Users/nizarayari/Arise/arise-auth/node_modules/graphql/jsutils/invariant.js:19 throw new Error(message); ^ Error: Expected undefined to be a GraphQL nullable type. at invariant (/Users/nizarayari/Arise/arise-auth/node_modules/graphql/jsutils/invariant.js:19:11) at assertNullableType (/Users/nizarayari/Arise/arise-auth/node_modules/graphql/type/definition.js:261:51) at new GraphQLNonNull (/Users/nizarayari/Arise/arise-auth/node_modules/graphql/type/wrappers.js:79:54) at Object. (/Users/nizarayari/Arise/arise-auth/src/schema/membership/MembershipType.js:25:13) at Module._compile (module.js:624:30) at Object.Module._extensions..js (module.js:635:10) at Module.load (module.js:545:32) at tryModuleLoad (module.js:508:12) at Function.Module._load (module.js:500:3) at Module.require (module.js:568:17) at require (internal/module.js:11:18) at Object. (/Users/nizarayari/Arise/arise-auth/src/schema/user/UserType.js:19:1) at Module._compile (module.js:624:30) at Object.Module._extensions..js (module.js:635:10) at Module.load (module.js:545:32) at tryModuleLoad (module.js:508:12)

Here is my query for user

No queries for memberships just mutation