Laravel lighthouse 4.16 在不使用 @middleware 的情况下获取当前用户,@middleware 已弃用
Laravel lighthouse 4.16 get current user without using @middleware which is deprecated
我有以下突变
type Mutation {
# ...
createArticle(title: String!, content: String!): Article
@field(resolver: "ArticleMutator@create")
@middleware(checks: ["auth:api"]) // here is the problem related to relation of a user and an article
}
在 Laravel Lighthouse 4.16
中不能再使用 @middleware 指令
所以我想知道我可以使用哪种方法来检索当前经过身份验证的用户并同时创建与文章的关系?
在此处更新完整项目https://github.com/wolfiton/laravel-graphql
我也不知道为什么我无法从上下文中获取 user.id。我在文档中找不到与此问题相关的任何内容。
这是与我的问题相关的 2 个文件
https://github.com/wolfiton/laravel-graphql/blob/master/graphql/schema.graphql
https://github.com/wolfiton/laravel-graphql/blob/master/app/GraphQL/Mutations/ArticleMutator.php
使用 Matt Davenport 建议@guard 时出错
type Mutation @guard(with: ["api"]) {
createArticle(title: String!, content: String!): Article
@field(resolver: "ArticleMutator")
}
{
"errors": [
{
"debugMessage": "Call to a member function articles() on null",
"message": "Internal server error",
"extensions": {
"category": "internal"
},
"locations": [
{
"line": 6,
"column": 3
}
],
"path": [
"createArticle"
],
提前致谢
@middleware
指令已被弃用,取而代之的是 @guard
,所以我会这样做:
type Mutation @guard(with: ["api"]) {
createArticle(title: String!, content: String!): Article @field(resolver: "ArticleMutator@create")
}
我有以下突变
type Mutation {
# ...
createArticle(title: String!, content: String!): Article
@field(resolver: "ArticleMutator@create")
@middleware(checks: ["auth:api"]) // here is the problem related to relation of a user and an article
}
在 Laravel Lighthouse 4.16
中不能再使用 @middleware 指令所以我想知道我可以使用哪种方法来检索当前经过身份验证的用户并同时创建与文章的关系?
在此处更新完整项目https://github.com/wolfiton/laravel-graphql
我也不知道为什么我无法从上下文中获取 user.id。我在文档中找不到与此问题相关的任何内容。
这是与我的问题相关的 2 个文件
https://github.com/wolfiton/laravel-graphql/blob/master/graphql/schema.graphql
https://github.com/wolfiton/laravel-graphql/blob/master/app/GraphQL/Mutations/ArticleMutator.php
使用 Matt Davenport 建议@guard 时出错
type Mutation @guard(with: ["api"]) {
createArticle(title: String!, content: String!): Article
@field(resolver: "ArticleMutator")
}
{
"errors": [
{
"debugMessage": "Call to a member function articles() on null",
"message": "Internal server error",
"extensions": {
"category": "internal"
},
"locations": [
{
"line": 6,
"column": 3
}
],
"path": [
"createArticle"
],
提前致谢
@middleware
指令已被弃用,取而代之的是 @guard
,所以我会这样做:
type Mutation @guard(with: ["api"]) {
createArticle(title: String!, content: String!): Article @field(resolver: "ArticleMutator@create")
}