Skip to content
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

Allow configuring multiple routes that point to different endpoints #8

Closed
leonardocustodio opened this issue Mar 28, 2023 · 4 comments · Fixed by #14
Closed

Allow configuring multiple routes that point to different endpoints #8

leonardocustodio opened this issue Mar 28, 2023 · 4 comments · Fixed by #14
Labels
enhancement New feature or request

Comments

@leonardocustodio
Copy link
Contributor

It seems that using this package we are not able to load different schemas in different endpoints, is that correct?
/~https://github.com/rebing/graphql-laravel/pull/986/files

@mfn
Copy link
Contributor

mfn commented Mar 28, 2023

I noticed this too; even my own projects based on rebing/graphql-laravel suffer this 😬

I was meant to look into for graphql-laravel but haven't found time yet.

@spawnia spawnia changed the title Different endpoints for each schema Allow configuring multiple routes that point to different endpoints Mar 30, 2023
@spawnia spawnia added the enhancement New feature or request label Mar 30, 2023
@spawnia
Copy link
Member

spawnia commented Mar 30, 2023

In order to make this happen, I think we would essentially need to switch the configuration from the current format into one that returns configurations for multiple routes.

-return ['route' => ['uri' => '/graphiql', ...], 'endpoint' => '/graphql', ...];
+return [
+    ['route' => ['uri' => '/graphiql/admin', ...]], 'endpoint' => '/graphql/admin', ...],
+    ['route' => [['uri' => '/graphiql/app', ...], 'endpoint' => '/graphql/app', ...],
+];

Then, the routes configuration file would need to iterate over those multiple routes and pass their config to the controller, which in turn passes the configuration values to the view.

I am not looking to implement this change myself. but am open to pull requests.

@v16Studios
Copy link

I adapted our fork to support multiple schemas dynamically in the routes.php, this works for us 😄 :

/**
 * Get the schema from the request and append to the configured endpoints.
 */
if ($schema = Str::afterLast(trim(Request::capture()->getPathInfo(), '/'), '/')) {
    $schema = '/' . $schema;
    if ($config->get('graphiql.route.uri') != $schema) {
        $config->set('graphiql.route.uri', $config->get('graphiql.route.uri') . $schema);
        $config->set('graphiql.endpoint', $config->get('graphiql.endpoint') . $schema);
    }
}

@mfn
Copy link
Contributor

mfn commented Apr 4, 2023

#11 gives a good idea of peoples expectations in this regard. Obviously, this package can't query random other packages config files.

I wonder what we could do here, i.e. have package A (graphql-laravel) provide package B (laravel-graphiql) the information automatically to generate the appropriate routes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants