0

我只是想在 Clojure 中使用 Lacinia 和一个简单的“wiki”应用程序来计算 GraphQL。

该应用程序。有作为卡片序列的页面。API 可以返回页面的原始文本版本,或一系列 Card 对象。

这是我在 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}
  }
 }

我正在尝试通过从 GraphiQL 启动这个查询来测试它

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

处理程序是


(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))})

我要问的 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)}))

我收到此错误消息:

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

这可能是一个非常简单的 n00b 错误。使用架构或我的查询。但我看不出有什么问题。

我认为 QueryRoot 是查询的根。但这是我必须从某个地方明确向下导航的东西吗?

4

1 回答 1

1

好的。

在敲了几个小时的头之后,我终于弄明白了。

在查询参数和字段周围缺少一对花括号。

查询应该是:

  {
    raw_page(page_name: "HelloWorld") {
      page_name
      body
    }
  }
于 2020-02-29T03:10:43.637 回答