Skip to content

Commit

Permalink
DOC Document storing gql schema in cache dir (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Jun 27, 2023
1 parent f7d15f8 commit cd758f5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions en/00_Getting_Started/00_Server_Requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ also needs write access for the webserver user to the following locations:
and [Partial Template Caching](/developer_guides/templates/partial_template_caching).
See [Environment Management](/getting_started/environment_management).
* `.graphql-generated`: silverstripe/graphql uses this directory. This is where your schema is
stored once it [has been built](/developer_guides/graphql/getting_started/building_the_schema). Best practice
stored once it [has been built](/developer_guides/graphql/getting_started/building_the_schema/). Best practice
is to create it ahead of time, but if the directory doesn't exist and your project root is writable, the graphql
module will create it for you.
module will create it for you. Note that you can configure this to be stored elsewhere - see [building the schema](/developer_guides/graphql/getting_started/building_the_schema/#cache-location)
* `public/_graphql`: silverstripe/graphql uses this directory. It's used for
[schema introspection](/developer_guides/graphql/tips_and_tricks#schema-introspection). You should treat this folder
the same way you treat the `.graphql-generated` folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ slow things down.
To mitigate this, the generated code for each type is cached against a signature.
If the type hasn't changed, it doesn't get re-built. This reduces build times to **under one second** for incremental changes.

#### Choosing where the cache is stored {#cache-location}

By default, the generated PHP code is placed in the `.graphql-generated/` directory in the root of your project.

If you want to store this in another directory, you can configure this using the following yaml configuration. Note that the path is relative to your project root.

```yml
SilverStripe\GraphQL\Schema\Storage\CodeGenerationStore:
dirName: 'some/other/directory'
```

If you set the `dirName` configuration property to be blank, the schema will be stored in the `silverstripe-cache` (i.e. `TEMP_PATH`) directory. This can be useful
if you have a mechanism that clear this folder on each deployment, or if you share this folder between servers in a multi-server setup, etc.

```yml
SilverStripe\GraphQL\Schema\Storage\CodeGenerationStore:
dirName: ''
```

[notice]
Your schema will not be cleared on a normal system `flush`, even if you store it in the `silverstripe-cache` directory. See below to learn how to clear the schema.
[/notice]

#### Clearing the schema cache

If you want to completely re-generate your schema from scratch, you can add `clear=1` to the `dev/graphql/build` command.
Expand All @@ -98,8 +121,8 @@ tangential changes such as:

### Viewing the generated code

By default, the generated PHP code is placed in the `.graphql-generated/` directory in the root of your project.
It is not meant to be accessible through your webserver, Which is ensured by keeping it outside of the
If you want to view your generated code, you can find it in the directory it has been configured to build in. See [choosing where the cache is stored](#cache-location) above.
It is not meant to be accessible through your webserver, which is ensured by keeping it outside of the
`public/` webroot and the inclusion of a `.htaccess` file in each schema folder.

Additional files are generated for CMS operation in `public/_graphql/`, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ icon: rocket

## Deploying the schema

[info]
For simplicity, this documentation assumes you are using the default `.graphql-generated/` to store your generated schema - but note that this can be configured to be any path relative to your project root. See [choosing where the cache is stored](/developer_guides/graphql/getting_started/building_the_schema/#cache-location) for more information.
[/info]

One way or another, you must get the `.graphql-generated/` and `public/_graphql/` folders into your test and production environments for Silverstripe CMS (and your own custom queries) to work as expected. There are many ways to do so. The options below are listed in order of complexity.

### Single-server hosting solutions with simple deployments {#simple-single-server}
Expand Down
9 changes: 9 additions & 0 deletions en/04_Changelogs/5.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ title: 5.1.0 (unreleased)

- [Features and enhancements](#features-and-enhancements)
- [Eager loading](#eager-loading)
- [GraphQL schema can be stored in `silverstripe-cache`](#gql-schema-is-cache)
- [Other new features](#other-features)
- [API changes](#api-changes)
- [Dependency changes](#dependency-changes)
Expand Down Expand Up @@ -39,6 +40,14 @@ foreach ($teams as $team) {

Read more about [eager loading](/developer_guides/model/relations/#eager-loading) in the developer docs.

### GraphQL schema can be stored in `silverstripe-cache` {#gql-schema-is-cache}

By default, the graphql schema is stored in a `.graphql-generated/` directory in your project root. It is now possible to configure this to be stored in the `silverstripe-cache` (i.e. `TEMP_PATH`) directory.

Note that even if you store the schema in the cache directory, the schema still won't be invalidated when you flush the cache. See [what triggers a GraphQL code build](/developer_guides/graphql/getting_started/building_the_schema/#what-triggers-a-graphql-code-build) for details about how to build the schema.

See [choosing where the cache is stored](/developer_guides/graphql/getting_started/building_the_schema/#cache-location) for more information about configuring the schema storage directory.

### Other new features

- You can now exclude specific `DataObject` models from the check and repair step of `dev/build` - see [ORM Performance](/developer_guides/performance/orm/#skip-check-and-repair) for more information.
Expand Down

0 comments on commit cd758f5

Please sign in to comment.