简体   繁体   English

无法在类型“QueryRoot”上查询字段“XXX”。”(GraphQL 的 Lacinia Clojure 库)

[英]Cannot query field `XXX' on type `QueryRoot'." (Lacinia Clojure library for GraphQL)

I'm just trying to figure out GraphQL in Clojure using Lacinia with a simple "wiki" app.我只是想在 Clojure 中使用 Lacinia 和一个简单的“wiki”应用程序找出 GraphQL。

The app.应用程序。 has Pages which are sequences of Cards.具有作为卡片序列的页面。 And the API can return either a raw text version of the page, or a sequence of Card objects. API 可以返回页面的原始文本版本,或者一系列 Card 对象。

Here's my schema defined in EDN这是我在 EDN 中定义的架构


{:enums
 {:cardtype
  {:description "A type that is attached to each card"
   :values [:RAW :MARKDOWN :CALCULATED]}}

 :objects
 {:Card
  {:description "A card within the system"
   :fields
   {}}
  :RawPage
  {:description "A page always has a representation whose body is nothing but a string of plaintext"
   :fields
   {:page_name {:type String}
    :body {:type String}}}
  :Page
  {:description "A Page is a named page within the wiki. It is made of a series of cards"
   :fields
   {:page_name {:type String}
    :cards {:type (list :Card)}} }}


 :queries
 {:raw_page
  {:type :RawPage
   :description "Retrieve the raw version of a single page by its name"
   :args {:page_name {:type (non-null String)}}
   :resolve :resolve-raw-page}

  :cooked_page
  {:type :Page
   :description "Retrieve the cooked version of a single page by its name"
   :args {:page_name {:type (non-null String)}}
   :resolve :resolve-cooked-page}
  }
 }

And I'm trying to test it by firing this query up from GraphiQL我试图通过从 GraphiQL 启动这个查询来测试它

  {
    raw_page(page_name: "HelloWorld")
    page_name
    body
  }

The handler is处理程序是


(defn graphql-handler [request]
  {:status 200
   :headers {"Content-Type" "application/json"}
   :body (let [query (extract-query request)
               result (execute pagestore/pagestore-schema query nil nil)]
           (json/write-str result))})

And the resolver for the raw_page query I'm asking is :我要问的 raw_page 查询的解析器是:

(defn resolve-raw-page [context arguments value]
  (let [{:keys [page_name]} arguments]
    {:page_name page_name
     :body (get-page-from-file page_name)}))

And I'm getting this error message :我收到此错误消息:

{
  "errors": [
    {
      "message": "Cannot query field `page_name' on type `QueryRoot'.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "extensions": {
        "type": "QueryRoot",
        "field": "page_name"
      }
    }
  ]
}

This is probably a really simple n00b mistake.这可能是一个非常简单的 n00b 错误。 Either with the schema or my query.使用架构或我的查询。 But I can't see what's wrong.但我看不出有什么问题。

I take it QueryRoot is the root of the query.我认为 QueryRoot 是查询的根。 But is this something I have to explicitly navigate down from somewhere?但这是我必须从某个地方明确导航的东西吗?

OK.好的。

After banging my head for a few hours, I finally figured it out.折腾了几个小时后,我终于想通了。

It was a missing pair of curly-brackets after the query argument and around the fields.在查询参数之后和字段周围缺少一对大括号。

Query should have been :查询应该是:

  {
    raw_page(page_name: "HelloWorld") {
      page_name
      body
    }
  }

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

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