diff --git a/.travis.yml b/.travis.yml index 70f1f27..a92655d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: php php: - 7.1 - 7.2 +- 7.3 cache: directories: - $HOME/.composer/cache diff --git a/src/Annotations/SourceField.php b/src/Annotations/SourceField.php index 940c02a..dc44dfe 100644 --- a/src/Annotations/SourceField.php +++ b/src/Annotations/SourceField.php @@ -105,7 +105,7 @@ public function isLogged(): bool /** * Returns the GraphQL return type of the request (as a string). - * The string can represent the FQCN of the type or an entry in the container resolving to the GraphQL type. + * The string is the GraphQL output type name. * * @return string|null */ diff --git a/src/Annotations/SourceFieldInterface.php b/src/Annotations/SourceFieldInterface.php index e1a04a7..f3ee6ba 100644 --- a/src/Annotations/SourceFieldInterface.php +++ b/src/Annotations/SourceFieldInterface.php @@ -30,7 +30,7 @@ public function isLogged(): bool; /** * Returns the GraphQL return type of the request (as a string). - * The string can represent the FQCN of the type or an entry in the container resolving to the GraphQL type. + * The string is the GraphQL output type name. * * @return string|null */ diff --git a/src/FieldsBuilder.php b/src/FieldsBuilder.php index 876af6a..d066a9e 100644 --- a/src/FieldsBuilder.php +++ b/src/FieldsBuilder.php @@ -496,7 +496,6 @@ private function mapType(Type $type, ?Type $docBlockType, bool $isNullable, bool } } - return $graphQlType; } diff --git a/src/Schema.php b/src/Schema.php index 15265ac..ddc0c08 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -4,6 +4,7 @@ namespace TheCodingMachine\GraphQL\Controllers; use GraphQL\Type\Definition\ObjectType; +use GraphQL\Type\Definition\Type; use GraphQL\Type\SchemaConfig; use TheCodingMachine\GraphQL\Controllers\Containers\BasicAutoWiringContainer; use TheCodingMachine\GraphQL\Controllers\Mappers\RecursiveTypeMapperInterface; @@ -26,13 +27,37 @@ public function __construct(QueryProviderInterface $queryProvider, RecursiveType $query = new ObjectType([ 'name' => 'Query', 'fields' => function() use ($queryProvider) { + $queries = $queryProvider->getQueries(); + if (empty($queries)) { + return [ + 'dummyQuery' => [ + 'type' => Type::string(), + 'description' => 'A placeholder query used by thecodingmachine/graphql-controllers when there are no declared queries.', + 'resolve' => function () { + return 'This is a placeholder query. Please create a query using the @Query annotation.'; + } + ] + ]; + } return $queryProvider->getQueries(); } ]); $mutation = new ObjectType([ 'name' => 'Mutation', 'fields' => function() use ($queryProvider) { - return $queryProvider->getMutations(); + $mutations = $queryProvider->getMutations(); + if (empty($mutations)) { + return [ + 'dummyMutation' => [ + 'type' => Type::string(), + 'description' => 'A placeholder query used by thecodingmachine/graphql-controllers when there are no declared mutations.', + 'resolve' => function () { + return 'This is a placeholder mutation. Please create a mutation using the @Mutation annotation.'; + } + ] + ]; + } + return $mutations; } ]); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php new file mode 100644 index 0000000..e3453ea --- /dev/null +++ b/tests/SchemaTest.php @@ -0,0 +1,36 @@ +getTypeMapper(), $this->getTypeResolver()); + + $fields = $schema->getQueryType()->getFields(); + $this->assertArrayHasKey('dummyQuery', $fields); + $resolve = $fields['dummyQuery']->resolveFn; + $this->assertSame('This is a placeholder query. Please create a query using the @Query annotation.', $resolve()); + + $fields = $schema->getMutationType()->getFields(); + $this->assertArrayHasKey('dummyMutation', $fields); + $resolve = $fields['dummyMutation']->resolveFn; + $this->assertSame('This is a placeholder mutation. Please create a mutation using the @Mutation annotation.', $resolve()); + } +}