Skip to content

Commit 510c37d

Browse files
committed
add secretBackstory as field in starWars test schema
1 parent 89763c6 commit 510c37d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

examples/starwars/__schema.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use GraphQL\Errors\ForbiddenError;
34
use GraphQL\Types\GraphQLObjectType;
45
use GraphQL\Types\GraphQLEnum;
56
use GraphQL\Types\GraphQLEnumValue;
@@ -30,6 +31,7 @@
3031
new GraphQLTypeField("name", new GraphQLString(), "The name of the character."),
3132
new GraphQLTypeField("friends", new GraphQLList($Character), "The friends of the character, or an empty list if they have none."),
3233
new GraphQLTypeField("appearsIn", new GraphQLList($Episode), "Which movies they appear in."),
34+
new GraphQLTypeField("secretBackstory", new GraphQLString(), "All secrets about their past."),
3335
];
3436
}, function ($character) {
3537
if ($character["type"] === "human") {
@@ -51,7 +53,10 @@
5153
}, $character["friends"]);
5254
}),
5355
new GraphQLTypeField("appearsIn", new GraphQLList($Episode), "Which movies they appear in."),
54-
new GraphQLTypeField("homePlanet", new GraphQLString(), "The home planet of the human, or null if unknown.")
56+
new GraphQLTypeField("homePlanet", new GraphQLString(), "The home planet of the human, or null if unknown."),
57+
new GraphQLTypeField("secretBackstory", new GraphQLString(), "Where are they from and how they came to be who they are.", function (){
58+
throw new ForbiddenError("secretBackstory is secret.");
59+
})
5560
];
5661
}, [
5762
$Character
@@ -70,7 +75,10 @@
7075
}, $character["friends"]);
7176
}),
7277
new GraphQLTypeField("appearsIn", new GraphQLList($Episode), "Which movies they appear in."),
73-
new GraphQLTypeField("primaryFunction", new GraphQLString(), "The primary function of the droid.")
78+
new GraphQLTypeField("primaryFunction", new GraphQLString(), "The primary function of the droid."),
79+
new GraphQLTypeField("secretBackstory", new GraphQLString(), "Construction date and the name of the designer.", function (){
80+
throw new ForbiddenError("secretBackstory is secret.");
81+
})
7482
];
7583
}, [
7684
$Character

src/Utilities/LocatedError.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ abstract class LocatedError
1818
*/
1919
public static function from(GraphQLError $originalError, $fieldNodes, $path): GraphQLError
2020
{
21-
return new GraphQLError(
21+
$errorClassName = get_class($originalError);
22+
return new $errorClassName(
2223
$originalError->getMessage(),
2324
$fieldNodes[0],
2425
$path

0 commit comments

Comments
 (0)