SilverStripe GraphQL - 语法错误

时间:2018-02-12 16:48:15

标签: php graphql silverstripe-4

我试图将基本DataObject绑定到模式中,但是我的查询引发了以下错误:

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
        }
      ]
    }
  ]
}

并且,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
        }
      ]
    }
  ]
}

这是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;
  }
}

在mysite.yml:

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

对我缺少什么的任何见解?

2 个答案:

答案 0 :(得分:3)

我对门票做出了回应。问题似乎是无效的查询。默认情况下,读取操作具有分页。

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

或者,您可以在操作节点上关闭->setUsePagination(false)的分页。

您也可以使用silverstripe graphql devtools进行调试。

答案 1 :(得分:1)

看起来silverstripe-graphql正在生成的查询不正确:

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

没有+ syntax in GraphQL queries

我建议您尝试the YAML method to scaffold an object并查看是否存在差异,并且可能会有更新解决此问题。

如果这不起作用,并且您已经检查了所有语法,那么您绝对应该report an issue