normal graphql queries causing errors

2019-08-27 21:52发布

I have been searching around for a while and been getting a lot of help from the SO community. But, it seems that the setup of my project isn't allowing normal queries such as sort, limit, filter, or others.

I am querying a custom middleware/drupal site.

Examples that throw errors:

{
  umdHub(limit: 5) {
    articles {
      data {
        id
        title
        subtitle
        body
        summary
      }
    }
  }
}

or

{
  umdHub(
    sort: {
      fields: [authorship_date___time]
      order: ASC
    }
  ) {
    articles {
      data {
        id
        title
        subtitle
        body
        summary
        authorship_date {
          formatted_short
          unix
          unix_int
          formatted_long
          formatted_short
          time
        }
      }
    }
  }
}

All return errors in http://localhost:8000/___graphql like:

{
  "errors": [
    {
      "message": "Unknown argument \"limit\" on field \"umdHub\" of type \"Query\".",
      "locations": [
        {
          "line": 2,
          "column": 10
        }
      ]
    }
  ]
}

How can I resolve these issues?

2条回答
姐就是有狂的资本
2楼-- · 2019-08-27 22:41

Turns out this was the way to do it:

{
  umdHub {
    articles (page: { limit: 5 }) {
      data {
        id
        title
        subtitle
        body
        summary
        hero_image {
          url_1200_630
        }
        authorship_date {
          formatted_short
          unix
          unix_int
          formatted_long
          formatted_short
          time
        }
        slug
      }
    }
  }
}
查看更多
乱世女痞
3楼-- · 2019-08-27 22:47

That because you don't have argument limit in on field umdHub. To resolve, let's check your schema, on the umdHub field of type Query, and add limit arguments, then restart your server.

Exemple:

type Query {
  umdHub(limit: Int, sort: SortInput) { // <-- Add this
   articles
  }
}
查看更多
登录 后发表回答