Ruby on rails 使用graphql gem的Rails api使用哪个gatsby源插件
我正在使用Ruby on rails 使用graphql gem的Rails api使用哪个gatsby源插件,ruby-on-rails,postgresql,heroku,graphql,gatsby,Ruby On Rails,Postgresql,Heroku,Graphql,Gatsby,我正在使用gem'graphql'构建一个Rails API,并希望使用Gatsby.js前端访问这个graphql API。我尝试使用插件和,但它们似乎都不起作用。(当我在本地机器上使用GraphiQL应用程序进行查询时,API工作正常。) 有更好的Gatsby.js源插件吗?它可以与使用gem'graphql'的Rails API配合使用,它提供了一个端点http://localhost:3000/graphql?如果是这样,我应该如何在gatsby config.js等中配置该插件?(顺便
gem'graphql'
构建一个Rails API,并希望使用Gatsby.js
前端访问这个graphql API。我尝试使用插件和,但它们似乎都不起作用。(当我在本地机器上使用GraphiQL
应用程序进行查询时,API工作正常。)
有更好的Gatsby.js
源插件吗?它可以与使用gem'graphql'
的Rails API配合使用,它提供了一个端点http://localhost:3000/graphql
?如果是这样,我应该如何在gatsby config.js
等中配置该插件?(顺便说一句,我正在使用一个Postgres数据库,我打算将其部署到Heroku——我曾想过继续使用,但我不确定这是否是最好的选择。)
在routes.rb
中的Rails API中,我将post”/graphql设置为:“graphql#execute”
以路由到GraphqlController
。以下是控制器中的execute
方法
def execute
variables = ensure_hash(params[:variables])
query = params[:query]
operation_name = params[:operationName]
context = {
# Query context goes here, for example:
# current_user: current_user,
}
result = GraphqlRailsSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
render json: result
rescue => e
raise e unless Rails.env.development?
handle_error_in_development e
end
当我尝试呈现json:result
时,result
是:[{“message”=>“没有查询字符串存在”}]>
,用于我下面引用的任何前端设置
在我的Gatsby.js前端中,当我使用时,在Gatsby config.js
中,我有
{
resolve: 'gatsby-source-apiserver',
options: {
typePrefix: 'internal__',
url: `http://localhost:3000/graphql`,
method: 'post',
headers: {
'Content-Type': 'application/json'
},
data: {
},
name: `posts`,
entityLevel: `data.posts`,
payloadKey: `body`,
}
},
…当我运行gatsby develope
时,我的控制台中出现了他的错误
{
resolve: "gatsby-source-graphql",
options: {
// This type will contain remote schema Query type
typeName: "Authors",
// This is field under which it's accessible
fieldName: "authors",
// Url to query from
url: "http://localhost:3000/graphql",
},
},
TypeError:无法读取未定义的属性“数据”
而且,当我使用时,我在gatsby config.js
中有这个
{
resolve: "gatsby-source-graphql",
options: {
// This type will contain remote schema Query type
typeName: "Authors",
// This is field under which it's accessible
fieldName: "authors",
// Url to query from
url: "http://localhost:3000/graphql",
},
},
…当我运行gatsby develope
时,我的控制台中出现了他的错误
{
resolve: "gatsby-source-graphql",
options: {
// This type will contain remote schema Query type
typeName: "Authors",
// This is field under which it's accessible
fieldName: "authors",
// Url to query from
url: "http://localhost:3000/graphql",
},
},
错误:找不到模块“gatsby/graphql”
如您所见,我对如何在前端和后端之间连接
模式感到困惑。在此方面的任何帮助都将不胜感激 有没有找到解决方案?也在寻找解决方案