normal graphql queries causing errors

最后都变了- 提交于 2019-12-25 01:17:04

问题


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?


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/55930539/normal-graphql-queries-causing-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!