umbraco-community / umbraco-graphql

An implementation of GraphQL for Umbraco 8 using GraphQL for .NET.
MIT License
64 stars 32 forks source link

When trying to convert an item in a collection to a Type should it exclude results that don't match the Type? #7

Closed PeteDuncanson closed 5 years ago

PeteDuncanson commented 6 years ago

Trying to get all the ancestors of a content item will return me an array of items:

{
  content(id:1115) {
    name,
    ancestors {
      items {
          name
        }
      }
    }
  }
}

Returns:

{
  "data": {
    "content": {
      "name": "Matt Brailsford",
      "ancestors": {
        "items": [
          {
            "name": "People"
          }
        ]
      }
    }
  }
}

If I want to try to convert that to a Type some odd things happen.

1) If I have multiple items of different Types it will return the non-matching items in the array as empty objects rather than strip them out as I would expect. This might be correct as the conversion happens within the loop over the items? Sadly I can't repeat this in the demo as everything is in the root.

2) If I try to convert to a Type that matched none of the content then I still get an empty item back, it doesn't return an empty array. This is actually the same issue as above but just fudged a bit (should it tell me in an error that it can't convert or find anything for that Type for instance? This is repeatable in the demo like so:

{
  content(id:1115) {
    name,
    ancestors {
      items {
        ... on Blogpost {   # Matt isn't nested under a Blogpost
          name
        }
      }
    }
  }
}

returns:


{
  "data": {
    "content": {
      "name": "Matt Brailsford",
      "ancestors": {
        "items": [
          {}    # should this even be returned?
        ]
      }
    }
  }
}
rasmusjp commented 6 years ago

Yeah, the problem exists because ancestors, children, siblings and content pickers returns an array of PublishedContent which all types implement.

I'm not sure if we can do anything about this since all we do is return the items and then GraphQL for .NET handles the rest.

EnterpriseWide commented 5 years ago

Is a children filter by content type possible? Here is a query where I filter children by name but I would like to filter by contentType instead. query { content { byType { Homepage(id: 1156) { ...MyPage _children(filter: {_name_not: "Page Components"}) { items { ...MyPage } } } } } } fragment MyPage on umb_PublishedContent { _id _name _url _contentType { alias } }

rasmusjp commented 5 years ago

As mentioned in the PR I don't think it's a good idea to filter out items as it's incosistent with how GraphQL works in general and there's a lot of places it needs to be handlen and it would be something you need to handle with your custom types too