使用 graphlient 的 Graphql 查询问题

Issue with Graphql query using graphlient

我正在使用 graphlient gem 进行 graphql 查询调用 我必须在控制器中进行此调用,这就是我使用 graphlient ta make call

的原因
client = Graphlient::Client.new("http://localhost:3000/graphql", headers: {
            'Authorization': "API #{api_key}"
          })

response = client.query do
      query{
           search(id: 1){
            
                edges{
                    node{
                         id
                         name
                         timing{
                            start
                            end
                          }
                         }
                      }   
                  }
       end

我的计时字段有两个属性 startend 但是 Rails 给我语法错误 as

end is a keyword in Rails

我如何 运行 这个查询没有语法错误?有什么方法可以将字符串格式的查询发送到 运行 this?

我假设您正在使用 ashkan18/graphlient,因为这是搜索 graphlient 时的第一个结果。

并且根据其文档,您可以使用字符串进行查询。因此,您可以代替在您的示例中使用块,而是这样做:

response = client.query <<~GRAPHQL
  query {
    search(id: 1) {
      edges {
        node {
          id
          name
          timing {
            start
            end
          }
        }
      }
    }
  }
GRAPHQL