使用Symfony 4(Flex)后端和超博客包,我试图运行查询。我已按照说明进行了所有操作,但不幸的是,我仍然收到来自编译器的以下消息。 我将在这里从php附加所有配置。
GraphQL配置
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.