最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why graphQl returns "Unknown argument 'first' on field..." error when trying to s

programmeradmin4浏览0评论

I am trying to fetch first five items of a set. My query is following:

query sequence($id: String) {
  sequence(id: $id) {
    items(first:1) {
            content
    }
  }
}

How ever, I get response

"Unknown argument \"first\" on field \"items\" of type \"Sequence\"."

As far as I understood from the docs this is how I am supposed to make query if I want to get a limited amount of items back.

Do I need to define the argument somewhere in the schema? How do I limit the amount of returned items properly?

I am trying to fetch first five items of a set. My query is following:

query sequence($id: String) {
  sequence(id: $id) {
    items(first:1) {
            content
    }
  }
}

How ever, I get response

"Unknown argument \"first\" on field \"items\" of type \"Sequence\"."

As far as I understood from the docs this is how I am supposed to make query if I want to get a limited amount of items back.

Do I need to define the argument somewhere in the schema? How do I limit the amount of returned items properly?

Share Improve this question asked Apr 19, 2018 at 9:33 Jaakko KarhuJaakko Karhu 2,3864 gold badges29 silver badges42 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

All field arguments need to be defined in the schema, the default behaviour is for a field to accept no arguments.

You can define a first argument in your items field in your schema using syntax like this:

  type Sequence {
    items(first: Int): [Item]
  }

(See: Example No. 120 in the spec.)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论