-
-
Notifications
You must be signed in to change notification settings - Fork 267
Fix class based schemas within routes #724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
920b7e9
Fix class based schemas within routes
jasonvarga 8ba89aa
normalize and avoid booting
jasonvarga 1373349
stan
jasonvarga 0f153e3
fix stan and tests. arrays wont always be returned
jasonvarga 0ebd6ea
put it back to protected
jasonvarga 367acae
Arr::get() supports anything as the first argument. Docblock is incor…
jasonvarga 05384b3
Specify the key
jasonvarga 6f78a4d
resolve through container
jasonvarga 0407632
Test for routes being generated appropriately
jasonvarga 4b40115
Changelog
jasonvarga e2c3781
test for methods
jasonvarga 52ff159
Make public
jasonvarga 76d4276
Merge branch 'master' into class-based-schema-routes
mfn 474626a
chore: clarify changelog
mfn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rebing\GraphQL\Tests\Support\Objects; | ||
|
||
class ExampleSchemaWithMethod extends ExampleSchema | ||
{ | ||
public function toConfig(): array | ||
{ | ||
return array_merge(parent::toConfig(), ['method' => ['post']]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rebing\GraphQL\Tests\Unit; | ||
|
||
use GraphQL\Utils\BuildSchema; | ||
use Illuminate\Routing\Route; | ||
use Illuminate\Support\Collection; | ||
use Rebing\GraphQL\Tests\Support\Objects\ExampleMiddleware; | ||
use Rebing\GraphQL\Tests\Support\Objects\ExampleSchema; | ||
use Rebing\GraphQL\Tests\Support\Objects\ExampleSchemaWithMethod; | ||
use Rebing\GraphQL\Tests\TestCase; | ||
|
||
class RoutesTest extends TestCase | ||
{ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('graphql', [ | ||
|
||
'prefix' => 'graphql_test', | ||
|
||
'graphiql' => [ | ||
'display' => false, | ||
], | ||
|
||
'schemas' => [ | ||
'default' => [ | ||
'middleware' => [ExampleMiddleware::class] | ||
], | ||
'custom' => [ | ||
'middleware' => [ExampleMiddleware::class] | ||
], | ||
'with_methods' => [ | ||
'method' => ['post'], | ||
'middleware' => [ExampleMiddleware::class] | ||
], | ||
'class_based' => ExampleSchema::class, | ||
'class_based_with_methods' => ExampleSchemaWithMethod::class, | ||
'shorthand' => BuildSchema::build(' | ||
schema { | ||
query: ShorthandExample | ||
} | ||
|
||
type ShorthandExample { | ||
echo(message: String!): String! | ||
} | ||
'), | ||
] | ||
|
||
]); | ||
} | ||
|
||
public function testRoutes(): void | ||
{ | ||
$expected = [ | ||
'graphql.query' => [ | ||
'methods' => ['GET', 'HEAD'], | ||
'uri' => 'graphql_test', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.query.post' => [ | ||
'methods' => ['POST'], | ||
'uri' => 'graphql_test', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.default' => [ | ||
'methods' => ['GET', 'HEAD'], | ||
'uri' => 'graphql_test/{default}', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.default.post' => [ | ||
'methods' => ['POST'], | ||
'uri' => 'graphql_test/{default}', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.custom' => [ | ||
'methods' => ['GET', 'HEAD'], | ||
'uri' => 'graphql_test/{custom}', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.custom.post' => [ | ||
'methods' => ['POST'], | ||
'uri' => 'graphql_test/{custom}', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.with_methods.post' => [ | ||
'methods' => ['POST'], | ||
'uri' => 'graphql_test/{with_methods}', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.class_based' => [ | ||
'methods' => ['GET', 'HEAD'], | ||
'uri' => 'graphql_test/{class_based}', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.class_based.post' => [ | ||
'methods' => ['POST'], | ||
'uri' => 'graphql_test/{class_based}', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.class_based_with_methods.post' => [ | ||
'methods' => ['POST'], | ||
'uri' => 'graphql_test/{class_based_with_methods}', | ||
'middleware' => [ExampleMiddleware::class], | ||
], | ||
'graphql.shorthand' => [ | ||
'methods' => ['GET', 'HEAD'], | ||
'uri' => 'graphql_test/{shorthand}', | ||
'middleware' => [], | ||
], | ||
'graphql.shorthand.post' => [ | ||
'methods' => ['POST'], | ||
'uri' => 'graphql_test/{shorthand}', | ||
'middleware' => [], | ||
], | ||
]; | ||
|
||
$this->assertEquals($expected, Collection::make( | ||
app('router')->getRoutes()->getRoutesByName() | ||
)->map(function (Route $route) { | ||
return [ | ||
'methods' => $route->methods(), | ||
'uri' => $route->uri(), | ||
'middleware' => $route->middleware(), | ||
]; | ||
})->all()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasonvarga do you remember why you added this here?
I was playing around with some refactoring in other parts when I saw this and I wondered: if a schema is broken, aka not found, why would I silence the schema here?
Aka: a broken schema throws an exception for a purpose, it should crash the app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. 😬
In 6.2.0, if you had an invalid class (or just a string, really, since class names weren't supported yet) it would not throw an exception. I think I just made it continue to not throw an exception to keep the behavior consistent and not a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I decided to change it (#766) because somehow it didn't make sense to have an invalid configuration being silently skipped (as this is used for generated the routes, you're suddenly left in the dark why a certain schema simply "isn't there").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No arguments here!