Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphql - second level nested relationships always return empty array #4288

Closed
dankostov opened this issue Oct 18, 2019 · 5 comments · Fixed by #4296
Closed

Graphql - second level nested relationships always return empty array #4288

dankostov opened this issue Oct 18, 2019 · 5 comments · Fixed by #4296
Labels
issue: bug Issue reporting a bug severity: high If it breaks the basic use of the product status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@dankostov
Copy link

dankostov commented Oct 18, 2019

Describe the bug
I saw that similar bug have existed before, this one is related to many-to-many (bi-directional) relationship only.

Objects located deeper than 2 levels with many-to-many relationship always return empty array when querying using GraphQL.

Steps to reproduce the behavior
Example of graphql:

query {
 building(id:1) {
 	apartments {
     name
      rooms {
      name
     }
   }      
 }   
}

Actual Result:

{
 "data": {
   "building": {
     "apartments": [
       {
         "name": "Apartment 1",
         "rooms": []
       }
     ]
   }
 }
}

JSON models:

{
  "connection": "default",
  "collectionName": "buildings",
  "info": {
    "name": "building",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": [
      "created_at",
      "updated_at"
    ],
    "comment": ""
  },
  "attributes": {
    "name": {
      "type": "string"
    },
    "rooms": {
      "collection": "room",
      "via": "buildings",
      "dominant": true
    },
    "apartments": {
      "collection": "apartment",
      "dominant": true,
      "via": "buildings"
    }
  }
}
{
  "connection": "default",
  "collectionName": "apartments",
  "info": {
    "name": "apartment",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": [
      "created_at",
      "updated_at"
    ],
    "comment": ""
  },
  "attributes": {
    "name": {
      "type": "string"
    },
    "rooms": {
      "columnName": "rooms",
      "collection": "room",
      "via": "apartments",
      "dominant": true
    },
    "buildings": {
      "collection": "building",
      "via": "apartments"
    }
  }
}
{
  "connection": "default",
  "collectionName": "rooms",
  "info": {
    "name": "room",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": [
      "created_at",
      "updated_at"
    ],
    "comment": ""
  },
  "attributes": {
    "name": {
      "type": "string"
    },
    "buildings": {
      "collection": "building",
      "via": "rooms"
    },
    "apartments": {
      "collection": "apartment",
      "via": "rooms",
      "columnName": "apartments"
    }
  }
}

Expected behavior
It should return the rooms as well.

System

  • Node.js version: v12.12.0
  • NPM version: 6.11.3
  • Strapi version: 3.0.0-alpha.26 / 3.0.0-beta.17.1
  • Database: sqlite
  • Operating system: Ubuntu
@derrickmehaffy
Copy link
Member

@dankostov due note that Alpha is no longer supported: 3.0.0-alpha.26

@dankostov
Copy link
Author

It's happening on 3.0.0-beta.17.1 as well.

@alexandrebodin
Copy link
Member

@dankostov Can you share your three models as json plz

@dankostov
Copy link
Author

@alexandrebodin I have updated the description, including the models as you requested.
Is it possible this to be graphql client issue, am i querying it in the right way?

@alexandrebodin alexandrebodin added status: confirmed Confirmed by a Strapi Team member or multiple community members severity: high If it breaks the basic use of the product labels Oct 21, 2019
@dankostov
Copy link
Author

@alexandrebodin The issue is also happening for the "has many" relationship (the last one).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: high If it breaks the basic use of the product status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants