在此处输入图像描述
我试图使用Graphql在Laravel中创建一个Api,但我得到了这个错误";意外的标记<在位置0"的JSON中;请帮我处理这个
如果您通过会话(Laravel-santum(和CSRF使用GraphQL,请在已发布的视图中添加以下内容:
<meta name="csrf-token" content="{{ csrf_token() }}">
修改游乐场配置:
GraphQLPlayground.init(root, {
endpoint: "{{url(config('graphql-playground.endpoint'))}}",
settings: {
'request.credentials': 'same-origin',
},
headers: {
'X-CSRF-TOKEN': document.querySelector('meta[name="csrftoken"]').content
}
})
并确保在config/graphql-playground.php
:中取消注释该行
'middleware' => ['web']