Graphl query problem

System Information
  • Strapi Version: 4
  • Operating System: Windows pro
  • Database: SQLite
  • Node Version: 14.16.1
  • NPM Version: /
  • Yarn Version: 1.22.10

Hi,

I don’t know if one topic already talk about it, but I have a problem and solution I haven’t found it yet. :sweat_smile:

The problem is with Graphql, on my windows (I just want test Strapi v4 with Graphql and Next js before use Docker or Linux). May be the solution is to don’t use Windows :cold_face:, but I’m not sure if Windows is the source of my problem.

What I expected:

query allPosts{
  posts {
   	title 
  }
}

The error :

{
  "error": {
    "errors": [
      {
        "message": "Cannot query field \"title\" on type \"PostEntityResponseCollection\".",
        "locations": [
          {
            "line": 3,
            "column": 5
          }
        ],
        "extensions": {
          "code": "GRAPHQL_VALIDATION_FAILED",
          "exception": {
            "stacktrace": [
              "GraphQLError: Cannot query field \"title\" on type \"PostEntityResponseCollection\".",
....

I need to do this query :

query allPosts{
  posts {
   	data {
      attributes {
        title
      }
    } 
  }
}

I just want to know if this is normal or not? If not, why do I have this problem? I’m waiting for this query because all documentations use this kind of query (first query “What I expected”).

In doubt, sorry for the duplicate topic and my english.

Ty in advance :wink:

I am having the exact same issue… any advances in knowing what is wrong?

Ok @logical-potato it’s not an issue. It’s new “system” with GraphQL APIs.

I found that :

Now with v4 we need to use GraphQL with this query system.

I hope it will help you and happy new year ! :slight_smile:

3 Likes

The problem is that your GraphQL query is not valid (see the error “GRAPHQL_VALIDATION_FAILED”, and also the error message)

As you just said, instead of

posts {
    title
}

you need to do

posts {
    data {
        attributes {
            title
        }
    }
}

This is because the data is structured this way in Strapi, and yes, it’s normal. :slightly_smiling_face:

(Tip: press Ctrl + Space in the graphql playground to see suggestions when writing your query)

3 Likes