Comments (1)
Here is a fully working example that can not reproduce your issue. In particular see the $schema->assertValid()
. I suggest you integrate that method call in your automated test suites.
Also notice that SchemaValidator
will load all PHP files recursively, starting from the folder where the example file lives. So you should probably isolate it in its own folder to avoid scanning your entire project (and vendor) for nothing.
Let me know here if you are able to modify this working example and break it according to your real use-case.
<?php
require '../vendor/autoload.php';
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Tools\SchemaValidator;
use Doctrine\ORM\Tools\Setup;
use GraphQL\Doctrine\Types;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
/**
* @ORM\Entity
*/
class User
{
/**
* @var null|int
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}
/**
* @ORM\Entity
*/
class RankMonitor
{
/**
* @var int
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var User
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="userId", referencedColumnName="id", nullable=false)
*/
private $user;
/**
* @return User
*/
public function getUser(): User
{
return $this->user;
}
/**
* @param User $user
*
* @return RankMonitor
*/
public function setUser(User $user): RankMonitor
{
$this->user = $user;
return $this;
}
}
// Create the entity manager
$config = Setup::createAnnotationMetadataConfiguration([__DIR__], true, null, null, false);
$connection = ['url' => 'sqlite:///:memory:'];
$entityManager = EntityManager::create($connection, $config);
// Configure the type registry
$types = new Types($entityManager);
// Build your Schema
$schema = new Schema([
'query' => new ObjectType([
'name' => 'query',
'fields' => [
'test' => [
'type' => Type::int(),
'resolve' => function ($root, $args) use ($types): int {
return 1;
},
],
],
]),
'mutation' => new ObjectType([
'name' => 'mutation',
'fields' => [
'createRankMonitor' => [
'type' => Type::nonNull($types->getOutput(RankMonitor::class)),
'args' => [
'input' => Type::nonNull($types->getInput(RankMonitor::class)),
],
'resolve' => function ($root, $args, $context) {
return new RankMonitor();
},
],
],
]),
]);
// check everything is OK in Doctrine
$validator = new SchemaValidator($entityManager);
$errors = $validator->validateMapping();
var_dump($errors);
// check everything is OK in GraphQL
$schema->assertValid();
echo 'OK' . PHP_EOL;
from graphql-doctrine.
Related Issues (20)
- Support collection in setter HOT 4
- Event driven programming HOT 2
- phpstan HOT 1
- Documentation generation error HOT 3
- Some usage issues HOT 3
- Custom Trait in Model throws Exception HOT 5
- Entity without relations must not have an empty FilterGroupJoin HOT 6
- Cannot return null for non-nullable field HOT 5
- More sorting orders HOT 3
- Groups with OR logic and Joins HOT 2
- Support Embeddable classes HOT 2
- Hello, could you give me a demo? HOT 1
- No type registered with key `date`. Either correct the usage, or register it in your custom types container when instantiating `GraphQL\Doctrine\Types` HOT 13
- Getting entity fields with magic methods HOT 3
- Support webonyx/graphql-php 14 HOT 1
- Properties starting with is/has IE: isActive instead of getActive HOT 1
- Detached Entity HOT 2
- Problem when using with "doctrine/doctrine-bundle" HOT 7
- Slim Framework Example HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-doctrine.