Skip to content

Commit

Permalink
API Migrate code and docs from other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 15, 2024
1 parent 58efda3 commit ca71747
Show file tree
Hide file tree
Showing 76 changed files with 8,685 additions and 1 deletion.
25 changes: 25 additions & 0 deletions _config/_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\Versioned\GraphQL\Operations\CopyToStageCreator
publish:
class: SilverStripe\Versioned\GraphQL\Operations\PublishCreator
unpublish:
class: SilverStripe\Versioned\GraphQL\Operations\UnpublishCreator
rollback:
class: SilverStripe\Versioned\GraphQL\Operations\RollbackCreator
read:
plugins:
readVersion:
before: paginateList
readOne:
plugins:
readVersion:
before: firstResult
delete:
plugins:
unpublishOnDelete: true
50 changes: 50 additions & 0 deletions _config/_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 _config/_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
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: _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'
62 changes: 62 additions & 0 deletions docs/en/01_getting_started/01_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 ca71747

Please sign in to comment.