Skip to content

[3.1] Opt into GraphQL resources/queries#3289

Merged
jasonvarga merged 8 commits intomasterfrom
feature/graphql-opt-into-queries
Mar 5, 2021
Merged

[3.1] Opt into GraphQL resources/queries#3289
jasonvarga merged 8 commits intomasterfrom
feature/graphql-opt-into-queries

Conversation

@jasonvarga
Copy link
Copy Markdown
Member

@jasonvarga jasonvarga commented Feb 21, 2021

Rather than exposing all data by default this PR forces developers to opt into queries by specifying which resources they want to allow.

Previously we went with the "if you enable it, you're aware you get it all" approach. It felt too easy to enable too much. This feels like a safer default.

This also allows us to add more queries later without them becoming automatically enabled without the developer realizing.

The exception is the ping query, which is always enabled.

You will need to add the following to your config/statamic/graphql.php file. (Either the whole array or just the ones you want to enable, and set them to true:

'resources' => [
    'collections' => false,   // enables collections, collection, entries, and entry queries
    'assets' => false,        // enables assetContainers, assetContainer, assets, and asset queries
    'taxonomies' => false,    // enables taxonomies, taxonomy, terms, and term queries
    'globals' => false,       // enables globalsSets and globalSet queries
    'navs' => false,          // enables navs and nav queries
    'sites' => false,         // enables sites and site queries
    'users' => false,         // enables users and user queries
],

There's a corresponding PR for the REST API #3318 to become opt-in per endpoint for 3.1.

Note that this PR only enables/disables entire queries. ie. you can query entries from zero collections or any collection. Unlike the REST API PR that lets you enable certain collections. We can add the finer control here later.

i misread the changelog. reduceWithKeys only appeared in 8.x
i could use reduce, but it doesn't accept the keys before 8.x
jasonvarga added a commit to statamic/docs that referenced this pull request Mar 5, 2021
@jasonvarga jasonvarga changed the title Opt into GraphQL queries [3.1] Opt into GraphQL resources/queries Mar 5, 2021
@jasonvarga jasonvarga merged commit 5871979 into master Mar 5, 2021
@jasonvarga jasonvarga deleted the feature/graphql-opt-into-queries branch March 5, 2021 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant