React Relay - должен быть указан корневой тип запроса - PullRequest
0 голосов
/ 15 февраля 2019

Использование бэкэнда Symfony 4 (Flex) и пакета оверблогов. Я пытаюсь выполнить запрос.Я сделал все по инструкции и, к сожалению, все еще получаю следующее сообщение от компилятора.Я прикреплю сюда все конфиги со стороны php.

GraphQL Config

config / graphql / types / Query.yaml

Query:
  type: object
  config:
    description: "Facility ORM repository"
    fields:
      facility:
        type: "Facility"
        args:
          id:
            description: "Resolves using the facility id."
            type: "Int"
        resolve: "@=resolver('Facility', [args])"

config / graphql / types /Facility.types.yaml

Facility:
  type: object
  config:
    description: "An facility object with main data"
    fields:
      id:
        type: "Int!"
        description: "The unique ID of the facility."
      name:
        type: "String"
        description: "Name of the facility"
      description:
        type: "String"
        description: "Description of the facility (free form field)"
      content:
        type: "String"
        description: "Content - Default content which should appear on the page"
      custom_content:
        type: "String"
        description: "Custom Content - Content which should appear on the page, overriding the default `content` field"
      score:
        type: "String"
        description: "Ordering score - This is configured by the admin/moderator or application user"
      address_line_first:
        type: "String"
        description: "Address - 1st Line"
      address_line_second:
        type: "String"
        description: "Address - 2nd Line"
      postal_code:
        type: "Int"
        description: "Address - 2nd Line"
      latitude:
        type: "Float"
        description: "Geolocation Latitude"
      longitude:
        type: "Float"
        description: "Geolocation Longitude"

src / GraphQL / Resolver / FacilityResolver.php

<?php

namespace App\GraphQL\Resolver;

use App\Repository\FacilityRepository;
use Overblog\GraphQLBundle\Definition\Argument;
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface;

class FacilityResolver implements ResolverInterface, AliasedInterface
{
    /**
     * @var FacilityRepository
     */
    private $facilityRepository;

    /**
     * FacilityResolver constructor.
     *
     * @param FacilityRepository $facilityRepository
     */
    public function __construct(FacilityRepository $facilityRepository)
    {
        $this->facilityRepository = $facilityRepository;
    }

    /**
     * @param Argument $args
     *
     * @return \App\Entity\Facility|null
     */
    public function resolve(Argument $args)
    {
        return $this->facilityRepository->find((int) $args['id']);
    }

    /**
     * @return array
     */
    public static function getAliases()
    {
        return [
            'resolve' => 'Facility',
        ];
    }
}

Это было в бэкэнде.А теперь давайте обсудим на стороне реле

src / Facility / Facility.js

/**
 * @flow strict
 * @format
 */

import * as React from 'react';
import FacilityForm from './FacilityForm';

import { graphql, QueryRenderer } from 'relay-runtime';
import environment from '../environment';

type Props = {||};
type State = {||};

const query = graphql`
    query FacilityQuery($id: Int!) {
        facility(id: $id) {
            id
            name
        }
    }
`;

class Facility extends React.Component<Props, State> {
  render() {
    return (
      <QueryRenderer
        environment={environment}
        query={query}
        variables={{
          id: 1,
        }}
        render={({ error, props }) => {
          console.log(error);
          console.log(props);
        }}
      />
    );
  }
}

export default Facility;

Схема реагирования:

# An facility object with main data
type Facility {
  # The unique ID of the facility.
  id: Int!

  # Name of the facility
  name: String

  # Description of the facility (free form field)
  description: String

  # Content - Default content which should appear on the page
  content: String

  # Custom Content - Content which should appear on the page, overriding the default `content` field
  custom_content: String

  # Ordering score - This is configured by the admin/moderator or application user
  score: String

  # Address - 1st Line
  address_line_first: String

  # Address - 2nd Line
  address_line_second: String

  # Address - 2nd Line
  postal_code: Int

  # Geolocation Latitude
  latitude: Float

  # Geolocation Longitude
  longitude: Float
}

# Facility ORM repository
type Query {
  facility(
    # Resolves using the facility id.
    id: Int
  ): Facility
}

Генерация с помощью самоанализа

Когда я запускаю компилятор

я получаю ошибку:

Writing js
ERROR:
Query root type must be provided.
error Command failed with exit code 100.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
...