2
votes

I'm attempted to scaffold a basic DataObject into the schema, but my queries are throwing the following errors:

http://localhost:8080/graphql:

{
  "data": null,
  "errors": [
    {
      "message": "Syntax Error GraphQL request (1:1) Unexpected <EOF>\n\n1: \n   ^\n",
      "locations": [
        {
          "line": 1,
          "column": 1
        }
      ]
    }
  ]
}

And, http://localhost:8080/graphql/?query={readQuickPossessions{ID+Title+Address+SquareFeet}}:

{
  "data": null,
  "errors": [
    {
      "message": "Syntax Error GraphQL request (1:25) Cannot parse the unexpected character \"+\".\n\n1: {readQuickPossessions{ID+Title+Address+SquareFeet}}\n                           ^\n",
      "locations": [
        {
          "line": 1,
          "column": 25
        }
      ]
    }
  ]
}

Here is the DataObject:

<?php
namespace Trigger\HomeBuilderSite\DataObjects;

use SilverStripe\ORM\DataObject;
use SilverStripe\GraphQL\Scaffolding\Interfaces\ScaffoldingProvider;
use SilverStripe\GraphQL\Scaffolding\Scaffolders\SchemaScaffolder;

class QuickPossession extends DataObject implements ScaffoldingProvider {
  private static $table_name = 'QuickPossession';

  private static $db = [
    'Title' => 'Varchar(255)',
    'Address' => 'Varchar(255)',
    'SquareFeet' => 'Int',
  ];

  private static $has_one = [];

  public function provideGraphQLScaffolding(SchemaScaffolder $scaffolder) {
    $scaffolder
      ->type(QuickPossession::class)
        ->addFields([
          'ID', 
          'Title',
          'Address', 
          'SquareFeet'
        ])
        ->operation(SchemaScaffolder::READ)
          ->end()
        ->operation(SchemaScaffolder::UPDATE)
          ->end()
        ->end();
    return $scaffolder;
  }
}

And in mysite.yml:

SilverStripe\GraphQL\Controller:
  schema:
    scaffolding_providers:
      - Trigger\HomeBuilderSite\DataObjects\QuickPossession

Any insights into what I'm missing?

2

2 Answers

3
votes

I've responded to the ticket. Issue appears to be an invalid query. By default, the read operations have pagination.

query {
  readQuickPosessions {
    edges {
       node {
         ID
         Title
       }
    }
    pageInfo {
       hasNextPage
    }
}

Alternatively, you can turn off pagination with ->setUsePagination(false) on the operation node.

You can use silverstripe graphql devtools to debug this as well.

1
votes

It looks like the query that silverstripe-graphql is producing is incorrect:

{readQuickPossessions{ID+Title+Address+SquareFeet}}

There is no + syntax in GraphQL queries

I would recommend trying the YAML method to scaffold an object and seeing if there's a difference, and potentially there's an update that fixes this.

If that doesn't work, and you've checked all the syntax, you should definitely report an issue.