Skip to content

Commit

Permalink
Merge pull request #596 from creative-commoners/pulls/6/standalone
Browse files Browse the repository at this point in the history
API Migrate code and docs from other modules
  • Loading branch information
GuySartorelli committed Sep 2, 2024
2 parents 68bfbb9 + a8c7591 commit ef4cbfe
Show file tree
Hide file tree
Showing 101 changed files with 9,595 additions and 1 deletion.
10 changes: 10 additions & 0 deletions _config/asset-admin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
Name: graphql-asset-admin-schema
Only:
moduleexists: 'silverstripe/asset-admin'
---
SilverStripe\Core\Injector\Injector:
SilverStripe\AssetAdmin\Model\ThumbnailGenerator.graphql:
class: SilverStripe\AssetAdmin\Model\ThumbnailGenerator
properties:
Generates: false
21 changes: 21 additions & 0 deletions _config/versioned.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
Name: graphql-versioned-schema
Only:
moduleexists: 'silverstripe/versioned'
---
SilverStripe\GraphQL\Schema\Schema:
schemas:
'*':
src:
versionedSrc: 'silverstripe/graphql: _graphql/versioned'
---
Name: graphql-versioned-plugins
Only:
moduleexists: 'silverstripe/versioned'
---
SilverStripe\Core\Injector\Injector:
SilverStripe\GraphQL\Schema\Registry\PluginRegistry:
constructor:
- 'SilverStripe\GraphQL\Modules\Versioned\Plugins\VersionedDataObject'
- 'SilverStripe\GraphQL\Modules\Versioned\Plugins\UnpublishOnDelete'
- 'SilverStripe\GraphQL\Modules\Versioned\Plugins\VersionedRead'
25 changes: 25 additions & 0 deletions _graphql/versioned/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
modelConfig:
DataObject:
plugins:
versioning:
before: inheritance
operations:
copyToStage:
class: SilverStripe\GraphQL\Modules\Versioned\Operations\CopyToStageCreator
publish:
class: SilverStripe\GraphQL\Modules\Versioned\Operations\PublishCreator
unpublish:
class: SilverStripe\GraphQL\Modules\Versioned\Operations\UnpublishCreator
rollback:
class: SilverStripe\GraphQL\Modules\Versioned\Operations\RollbackCreator
read:
plugins:
readVersion:
before: paginateList
readOne:
plugins:
readVersion:
before: firstResult
delete:
plugins:
unpublishOnDelete: true
50 changes: 50 additions & 0 deletions _graphql/versioned/enums.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
VersionedStage:
description: The stage to read from or write to
values:
DRAFT:
value: Stage
description: The draft stage
LIVE:
value: Live
description: The live stage

VersionedQueryMode:
description: The versioned mode to use
values:
ARCHIVE:
value: archive
description: Read from a specific date of the archive
LATEST:
value: latest_versions
description: Read the latest version
ALL_VERSIONS:
value: all_versions
description: Reads all versionse
DRAFT:
value: Stage
description: Read from the draft stage
LIVE:
value: Live
description: Read from the live stage
STATUS:
value: status
description: Read only records with a specific status
VERSION:
value: version
description: Read a specific version

VersionedStatus:
description: The stage to read from or write to
values:
PUBLISHED:
value: published
description: Only published records
DRAFT:
value: draft
description: Only draft records
ARCHIVED:
value: archived
description: Only records that have been archived
MODIFIED:
value: modified
description: Only records that have unpublished changes
27 changes: 27 additions & 0 deletions _graphql/versioned/types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CopyToStageInputType:
input: true
fields:
id:
type: ID!
description: The ID of the record to copy
fromVersion:
type: Int
description: The source version number to copy
fromStage:
type: VersionedStage
description: The source stage to copy
toStage:
type: VersionedStage
description: The destination state to copy to

VersionedInputType:
input: true
fields:
mode: VersionedQueryMode = Stage
archiveDate:
type: String
description: The date to use for archive
status:
type: '[VersionedStatus]'
description: If mode is STATUS, specify which versioned statuses
version: Int
17 changes: 17 additions & 0 deletions docs/en/01_getting_started/01_server_requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Server Requirements
icon: server
summary: What you will need to run GraphQL on a web server
---

### Filesystem permissions

During runtime, Silverstripe CMS needs read access for the webserver user to your webroot. When the GraphQL module is installed it also needs write access for the webserver user to the following locations:

- `.graphql-generated`: This directory is where your schema is
stored once it [has been built](../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.
- `public/_graphql`: This directory is used for
[schema introspection](../tips_and_tricks#schema-introspection). You should treat this folder
the same way you treat the `.graphql-generated` folder.
62 changes: 62 additions & 0 deletions docs/en/01_getting_started/02_activating_the_server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: Activating the default server
summary: Open up the default server that comes pre-configured with the module
icon: rocket
---

# Getting started

[CHILDREN asList]

## Activating the default GraphQL server

GraphQL is used through a single route, typically `/graphql`. You need
to define *types* and *queries* to expose your data via this endpoint.

These separate endpoints have their own identifiers. `default` refers to the GraphQL server
in the user space (e.g. `/graphql`) - i.e. your custom schema. You can also [set up a new schema server](#setting-up-a-custom-graphql-server)
if you wish.

> [!NOTE]
> The word "server" here refers to a route with its own isolated GraphQL schema. It does
> not refer to a web server.
By default, `silverstripe/graphql` does not route any GraphQL servers. To activate the default,
public-facing GraphQL server that ships with the module, just add a rule to [`Director`](api:SilverStripe\Control\Director).

```yml
SilverStripe\Control\Director:
rules:
'graphql': '%$SilverStripe\GraphQL\Controller.default'
```
## Setting up a custom GraphQL server
In addition to the default `/graphql` endpoint provided by this module by default,
you may want to set up another GraphQL server running on the same installation of Silverstripe CMS.

Let's set up a new controller to handle the requests.

```yml
SilverStripe\Core\Injector\Injector:
# ...
SilverStripe\GraphQL\Controller.myNewSchema:
class: SilverStripe\GraphQL\Controller
constructor:
schemaKey: myNewSchema
```

We'll now need to route the controller.

```yml
SilverStripe\Control\Director:
rules:
'my-graphql': '%$SilverStripe\GraphQL\Controller.myNewSchema'
```

Now, once you have [configured](configuring_your_schema) and [built](building_the_schema) your schema, you
can access it at `/my-graphql`.

### Further reading

[CHILDREN]
Loading

0 comments on commit ef4cbfe

Please sign in to comment.