简体   繁体   English

如果用户未登录,如何处理中继和graphql身份验证?

[英]how do I handle relay and graphql authentication if user is not logged in?

I have schema that is configured to query for users' data when logged in but I don't know what to do with it when a user is not logged in, this is the root query: 我有配置为在登录时查询用户数据的架构,但是当用户未登录时我不知道该如何处理,这是根查询:

const Query = new GraphQLObjectType({
  name: 'Query',
  fields: {
    viewer: {
      type: GraphQLUser,
      resolve: (root, args, { user }) => getViewer(), // I have a user data configured on requests if it's logged in
    },
    node: nodeField,
  },
});

I also have this error because I think there's no user data on rootValue yet so my query is returning undefined: 我也有这个错误,因为我认为rootValue上还没有用户数据,所以我的查询返回的是未定义的:

Error: User.todoLists field type must be Output Type but got: undefined. 错误:User.todoLists字段类型必须为Output Type,但得到:未定义。

If I return on the viewer the 'guest' text it wouldn't be a GraphQLUser type, help? 如果我在查看器上返回的“来宾”文本不是GraphQLUser类型,可以帮助吗?

You can return null . 您可以返回null

If in the future you want to enforce non-null values, then you will have to use GraphQLNonNull in your type definition, like this: 如果将来要强制使用非null值,则必须在类型定义中使用GraphQLNonNull ,如下所示:

...
type: new GraphQLNonNull(GraphQLUser),
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM