SilverStripe GraphQL - error when querying types with descendants











up vote
1
down vote

favorite












I'm getting this error when trying to query a type and a descendant:



"Fragment cannot be spread here as objects of type "AppTestObject" can never be of type "AppTestChild"."



I set up a test install using recipe-core, admin, graphql, and graphql-devtools (all latest) to test this out in a basic setting. I've created 2 objects:



class TestObject extends DataObject {

private static $singular_name = "Test Object";
private static $plural_name = "Test Objects";
private static $table_name = "TestObject";

private static $db = [
'Title' => 'Varchar(255)'
];

}

class TestChild extends DataObject {

private static $singular_name = "Test Child";
private static $plural_name = "Test Children";
private static $table_name = "TestChild";

private static $db = [
'Title' => 'Varchar(255)'
];

}


And set up simple scaffolding through configuration:



SilverStripeGraphQLController:
schema:
scaffolding:
types:

AppTestObject:
fields: [ID]
operations:
read: true

AppTestChild:
fields: [ID, Title]
operations:
read: true


I'm able to query each of these types individually without any problems. But when I try to get TestChild as a descendant of TestObject I get the error above. Here's an example of my query:



query {
readAppTestObjects {
edges {
node {
...on AppTestChild {
Title
}
}
}
}
}


Checking the documentation for the schema in graphiql, there is nothing under readAppTestObjects referencing descendants, although in the documentation for silverstripe/graphql it says:



When reading types that have exposed descendants (e.g. reading Page, when RedirectorPage is also exposed), the return type is a union of the base type and all exposed descendants. This union type takes on the name {BaseType}WithDescendants.









share|improve this question




























    up vote
    1
    down vote

    favorite












    I'm getting this error when trying to query a type and a descendant:



    "Fragment cannot be spread here as objects of type "AppTestObject" can never be of type "AppTestChild"."



    I set up a test install using recipe-core, admin, graphql, and graphql-devtools (all latest) to test this out in a basic setting. I've created 2 objects:



    class TestObject extends DataObject {

    private static $singular_name = "Test Object";
    private static $plural_name = "Test Objects";
    private static $table_name = "TestObject";

    private static $db = [
    'Title' => 'Varchar(255)'
    ];

    }

    class TestChild extends DataObject {

    private static $singular_name = "Test Child";
    private static $plural_name = "Test Children";
    private static $table_name = "TestChild";

    private static $db = [
    'Title' => 'Varchar(255)'
    ];

    }


    And set up simple scaffolding through configuration:



    SilverStripeGraphQLController:
    schema:
    scaffolding:
    types:

    AppTestObject:
    fields: [ID]
    operations:
    read: true

    AppTestChild:
    fields: [ID, Title]
    operations:
    read: true


    I'm able to query each of these types individually without any problems. But when I try to get TestChild as a descendant of TestObject I get the error above. Here's an example of my query:



    query {
    readAppTestObjects {
    edges {
    node {
    ...on AppTestChild {
    Title
    }
    }
    }
    }
    }


    Checking the documentation for the schema in graphiql, there is nothing under readAppTestObjects referencing descendants, although in the documentation for silverstripe/graphql it says:



    When reading types that have exposed descendants (e.g. reading Page, when RedirectorPage is also exposed), the return type is a union of the base type and all exposed descendants. This union type takes on the name {BaseType}WithDescendants.









    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I'm getting this error when trying to query a type and a descendant:



      "Fragment cannot be spread here as objects of type "AppTestObject" can never be of type "AppTestChild"."



      I set up a test install using recipe-core, admin, graphql, and graphql-devtools (all latest) to test this out in a basic setting. I've created 2 objects:



      class TestObject extends DataObject {

      private static $singular_name = "Test Object";
      private static $plural_name = "Test Objects";
      private static $table_name = "TestObject";

      private static $db = [
      'Title' => 'Varchar(255)'
      ];

      }

      class TestChild extends DataObject {

      private static $singular_name = "Test Child";
      private static $plural_name = "Test Children";
      private static $table_name = "TestChild";

      private static $db = [
      'Title' => 'Varchar(255)'
      ];

      }


      And set up simple scaffolding through configuration:



      SilverStripeGraphQLController:
      schema:
      scaffolding:
      types:

      AppTestObject:
      fields: [ID]
      operations:
      read: true

      AppTestChild:
      fields: [ID, Title]
      operations:
      read: true


      I'm able to query each of these types individually without any problems. But when I try to get TestChild as a descendant of TestObject I get the error above. Here's an example of my query:



      query {
      readAppTestObjects {
      edges {
      node {
      ...on AppTestChild {
      Title
      }
      }
      }
      }
      }


      Checking the documentation for the schema in graphiql, there is nothing under readAppTestObjects referencing descendants, although in the documentation for silverstripe/graphql it says:



      When reading types that have exposed descendants (e.g. reading Page, when RedirectorPage is also exposed), the return type is a union of the base type and all exposed descendants. This union type takes on the name {BaseType}WithDescendants.









      share|improve this question















      I'm getting this error when trying to query a type and a descendant:



      "Fragment cannot be spread here as objects of type "AppTestObject" can never be of type "AppTestChild"."



      I set up a test install using recipe-core, admin, graphql, and graphql-devtools (all latest) to test this out in a basic setting. I've created 2 objects:



      class TestObject extends DataObject {

      private static $singular_name = "Test Object";
      private static $plural_name = "Test Objects";
      private static $table_name = "TestObject";

      private static $db = [
      'Title' => 'Varchar(255)'
      ];

      }

      class TestChild extends DataObject {

      private static $singular_name = "Test Child";
      private static $plural_name = "Test Children";
      private static $table_name = "TestChild";

      private static $db = [
      'Title' => 'Varchar(255)'
      ];

      }


      And set up simple scaffolding through configuration:



      SilverStripeGraphQLController:
      schema:
      scaffolding:
      types:

      AppTestObject:
      fields: [ID]
      operations:
      read: true

      AppTestChild:
      fields: [ID, Title]
      operations:
      read: true


      I'm able to query each of these types individually without any problems. But when I try to get TestChild as a descendant of TestObject I get the error above. Here's an example of my query:



      query {
      readAppTestObjects {
      edges {
      node {
      ...on AppTestChild {
      Title
      }
      }
      }
      }
      }


      Checking the documentation for the schema in graphiql, there is nothing under readAppTestObjects referencing descendants, although in the documentation for silverstripe/graphql it says:



      When reading types that have exposed descendants (e.g. reading Page, when RedirectorPage is also exposed), the return type is a union of the base type and all exposed descendants. This union type takes on the name {BaseType}WithDescendants.






      php graphql silverstripe silverstripe-4






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 10:25









      Robbie Averill

      20.4k73976




      20.4k73976










      asked Nov 7 at 5:47









      Chris

      1589




      1589
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Yeah this is a bug in the SilverStripe graphql module. What you're doing should work.



          I believe the fix is in flight at https://github.com/silverstripe/silverstripe-graphql/pull/176, you can follow the progress there. Maybe try the patch out and leave some comments.






          share|improve this answer





















          • Robbie, you're a gem. This fixed the issue.
            – Chris
            Nov 8 at 20:16










          • Please direct credit at the pull request author on GitHub ;)
            – Robbie Averill
            Nov 8 at 20:27











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184168%2fsilverstripe-graphql-error-when-querying-types-with-descendants%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Yeah this is a bug in the SilverStripe graphql module. What you're doing should work.



          I believe the fix is in flight at https://github.com/silverstripe/silverstripe-graphql/pull/176, you can follow the progress there. Maybe try the patch out and leave some comments.






          share|improve this answer





















          • Robbie, you're a gem. This fixed the issue.
            – Chris
            Nov 8 at 20:16










          • Please direct credit at the pull request author on GitHub ;)
            – Robbie Averill
            Nov 8 at 20:27















          up vote
          1
          down vote



          accepted










          Yeah this is a bug in the SilverStripe graphql module. What you're doing should work.



          I believe the fix is in flight at https://github.com/silverstripe/silverstripe-graphql/pull/176, you can follow the progress there. Maybe try the patch out and leave some comments.






          share|improve this answer





















          • Robbie, you're a gem. This fixed the issue.
            – Chris
            Nov 8 at 20:16










          • Please direct credit at the pull request author on GitHub ;)
            – Robbie Averill
            Nov 8 at 20:27













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Yeah this is a bug in the SilverStripe graphql module. What you're doing should work.



          I believe the fix is in flight at https://github.com/silverstripe/silverstripe-graphql/pull/176, you can follow the progress there. Maybe try the patch out and leave some comments.






          share|improve this answer












          Yeah this is a bug in the SilverStripe graphql module. What you're doing should work.



          I believe the fix is in flight at https://github.com/silverstripe/silverstripe-graphql/pull/176, you can follow the progress there. Maybe try the patch out and leave some comments.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 10:27









          Robbie Averill

          20.4k73976




          20.4k73976












          • Robbie, you're a gem. This fixed the issue.
            – Chris
            Nov 8 at 20:16










          • Please direct credit at the pull request author on GitHub ;)
            – Robbie Averill
            Nov 8 at 20:27


















          • Robbie, you're a gem. This fixed the issue.
            – Chris
            Nov 8 at 20:16










          • Please direct credit at the pull request author on GitHub ;)
            – Robbie Averill
            Nov 8 at 20:27
















          Robbie, you're a gem. This fixed the issue.
          – Chris
          Nov 8 at 20:16




          Robbie, you're a gem. This fixed the issue.
          – Chris
          Nov 8 at 20:16












          Please direct credit at the pull request author on GitHub ;)
          – Robbie Averill
          Nov 8 at 20:27




          Please direct credit at the pull request author on GitHub ;)
          – Robbie Averill
          Nov 8 at 20:27


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184168%2fsilverstripe-graphql-error-when-querying-types-with-descendants%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini