我只是想通过一个简单的“维基”应用程序使用Lacinia来理解Clojure中的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是查询的根。但是这是我必须从某个地方显式导航到下面的东西吗?
发布于 2020-02-29 11:10:44
好的。
经过几个小时的努力,我终于弄明白了。
在查询参数后面和字段周围缺少一对大括号。
查询应该是:
{
raw_page(page_name: "HelloWorld") {
page_name
body
}
}https://stackoverflow.com/questions/60460892
复制相似问题