silverstripe / silverstripe-graphql

Serves Silverstripe data as GraphQL representations
BSD 3-Clause "New" or "Revised" License
52 stars 61 forks source link

Fix WithDescendants union type regression in scaffolding #215

Open chillu opened 5 years ago

chillu commented 5 years ago

The docs say that you get <type>WithDescendants, but you don't. It's unclear when that happend, but it's a regression which versioned-admin and elemental now rely on. They can't just change their query to use descendant based logic, because that would force them to dynamically create those queries (based on the available types in a particular SilverStripe project).

We could fix this through https://github.com/silverstripe/silverstripe-graphql/issues/209 (RFC: Replace "descendant unions" with fields to simplify querying), but that seems like a long time to leave this regression in the module.

This has also come up with devs on the #graphql channel just now

chillu commented 5 years ago

@unclecheese Just to minimise confusion here, could you validate my assumptions here?

chillu commented 5 years ago

Workaround for this in https://github.com/open-sausages/silverstripe-graphql/commit/6dcc005b0178ae689967198dcf27cb5bbbae7d7c

chillu commented 5 years ago

Demo of the current issue in 3.0.1:

graphql.yml

SilverStripe\Control\Director:
  rules:
    'graphql': '%$SilverStripe\GraphQL\Controller.default'
SilverStripe\GraphQL\Manager:
  schemas:
    default:
      scaffolding:
        types:
          Page:
            fields: '*'
            operations:
                read: true
           SilverStripe\ErrorPage\ErrorPage:
             fields: [ErrorCode]
query readPages {
  readPages {
    edges {
      node {
        Title
        ErrorCode
      }
    }
  }
}

Response

{
  "data": null,
  "errors": [
    {
      "message": "Cannot query field \"ErrorCode\" on type \"Page\".",
      "locations": [
        {
          "line": 6,
          "column": 9
        }
      ]
    }
  ]
}
chillu commented 5 years ago

This doesn't work either

graphql.yml

SilverStripe\Control\Director:
  rules:
    'graphql': '%$SilverStripe\GraphQL\Controller.default'
SilverStripe\GraphQL\Manager:
  schemas:
    default:
      scaffolding:
        types:
          Page:
            fields: [Title,ErrorCode]
            operations:
              read: true
          SilverStripe\ErrorPage\ErrorPage:
            fields: [ErrorCode]

Response

{
  "errors": [
    {
      "message": "Invalid field \"ErrorCode\" on Page",
      "code": 0,
      "file": 
TheBnl commented 4 years ago

I was questioning wat the current way of working with descendants is, or if there is an alternative to <type>WithDescendants for version 3.2.3? Those types don't show up in my introspection.

Using the union method as described in the readme section results in the following error: Fragment cannot be spread here as objects of type \"Block\" can never be of type \"VideoBlock\".

I'm asking here because i'm not quite sure what to do, and if this is still a work in progress should the readme be updated stating that it is a WIP feature?