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

[FR] Look for default .graphql cached schema file #4896

Closed
khalwat opened this issue Sep 7, 2019 · 3 comments
Closed

[FR] Look for default .graphql cached schema file #4896

khalwat opened this issue Sep 7, 2019 · 3 comments
Assignees
Labels
enhancement improvements to existing features graphql ⚙️ features related to the GraphQL API

Comments

@khalwat
Copy link
Contributor

khalwat commented Sep 7, 2019

Many editors with GraphQL plugins (PhpStorm, VS Code ) and GraphQL "playgrounds" allow you to give them a default .graphql schema file for auto-completion purposes. It's just a shortcut to having to rebuild the entire schema.

Since right now the Craft CMS GraphQL implementation doesn't build the full schema unless devMode is on, having such a default file would be useful:

        try {
            $devMode = Craft::$app->getConfig()->getGeneral()->devMode;
            $schemaDef = $gqlService->getSchemaDef($schema, $devMode);
            $result = GraphQL::executeQuery($schemaDef, $query, null, null, $variables, $operationName)
                ->toArray(true);
        } catch (\Throwable $e) {
            throw new GqlException('Something went wrong when processing the GraphQL query.', 0, $e);
        }

        return $this->asJson($result);
    }

The idea is that people could use the graphql console command to dump the schema, and then GraphiQL, various editors, etc. could then utilize it for auto-completion purposes without having to get the full schema back from Craft for the API.

In addition, support for graphql-config would be wonderful.

As @pauloelias said:

In addition to the 👍 I would also like to say this will be a huge help to our workflow since our headless CMS does not have devMode enabled. We still need to be able to test queries with the most up-to-date schema and I'd prefer not to have to fork this (now) huge database to a staging environment every time we update content models.

When we run headless we only spin up temporary review apps for each release but we don't need a long-running staging server in between releases because we don't need to worry about any frontend twig templates breaking.

Related: #4834

@brandonkelly brandonkelly added graphql ⚙️ features related to the GraphQL API enhancement improvements to existing features labels Sep 8, 2019
@andris-sevcenko
Copy link
Contributor

Back when I toyed with this, building the schema from a .graphql file was incredibly slow.

But things should be good enough without this, as Craft now serves the full schema for introspection queries, right?

cc @khalwat @pauloelias

@khalwat
Copy link
Contributor Author

khalwat commented Jan 10, 2020

yep especially now that we can just do this:

https://nystudio107.com/blog/graphql-schema-auto-completion-with-phpstorm

@andris-sevcenko
Copy link
Contributor

Closing this, then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvements to existing features graphql ⚙️ features related to the GraphQL API
Projects
None yet
Development

No branches or pull requests

3 participants