Skip to content

Commit

Permalink
API GraphQL v4: Schemageddon (#266)
Browse files Browse the repository at this point in the history
Co-authored-by: Ingo Schommer <[email protected]>
Co-authored-by: Gene Dower <[email protected]>
Co-authored-by: Maxime Rainville <[email protected]>
Co-authored-by: Andre Kiste <[email protected]>
  • Loading branch information
5 people authored Oct 7, 2020
1 parent 78f081a commit 1c4e623
Show file tree
Hide file tree
Showing 240 changed files with 11,338 additions and 14,285 deletions.
2,606 changes: 2 additions & 2,604 deletions README.md

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions _config/assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ Name: graphqlassets
Only:
moduleexists: 'silverstripe/assets'
---
## Assign the type to DBFile as a dependency
SilverStripe\GraphQL\Schema\Schema:
schemas:
'*':
types:
DBFile:
fields:
filename: String
hash: String
variant: String
url: String

SilverStripe\Assets\Storage\DBFile:
graphql_type:
Filename: String
Hash: String
Variant: String
URL: String
Width: Int
Height: Int
graphql_type: DBFile

## Register the types to the manager
SilverStripe\GraphQL\Scaffolding\Scaffolders\SchemaScaffolder:
fixed_types:
- SilverStripe\Assets\Storage\DBFile
SilverStripe\Assets\File:
allowed_extensions:
- graphql
Expand Down
69 changes: 17 additions & 52 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,39 @@ Name: graphqlconfig
---
# Define the type parsers
SilverStripe\Core\Injector\Injector:
SilverStripe\GraphQL\Scaffolding\Interfaces\TypeParserInterface.string:
class: SilverStripe\GraphQL\Scaffolding\Util\StringTypeParser
SilverStripe\GraphQL\Scaffolding\Interfaces\TypeParserInterface.array:
class: SilverStripe\GraphQL\Scaffolding\Util\ArrayTypeParser

SilverStripe\GraphQL\QueryHandler\QueryHandlerInterface:
class: SilverStripe\GraphQL\QueryHandler\QueryHandler

SilverStripe\GraphQL\Middleware\QueryMiddleware.csrf:
class: SilverStripe\GraphQL\Middleware\CSRFMiddleware

SilverStripe\GraphQL\Middleware\QueryMiddleware.httpMethod:
class: SilverStripe\GraphQL\Middleware\HTTPMethodMiddleware

SilverStripe\GraphQL\PersistedQuery\PersistedQueryMappingProvider:
class: SilverStripe\GraphQL\PersistedQuery\JSONStringProvider

SilverStripe\GraphQL\PersistedQuery\HTTPProvider:
constructor:
httpClient: '%$SilverStripe\GraphQL\PersistedQuery\GuzzleHTTPClient'
SilverStripe\GraphQL\Permission\QueryPermissionChecker.default:
class: SilverStripe\GraphQL\Permission\CanViewPermissionChecker
SilverStripe\GraphQL\Scaffolding\Scaffolders\ItemQueryScaffolder:
properties:
permissionChecker: '%$SilverStripe\GraphQL\Permission\QueryPermissionChecker.default'
SilverStripe\GraphQL\Scaffolding\Scaffolders\ListQueryScaffolder:
properties:
permissionChecker: '%$SilverStripe\GraphQL\Permission\QueryPermissionChecker.default'
SilverStripe\GraphQL\Pagination\Connection:
properties:
permissionChecker: '%$SilverStripe\GraphQL\Permission\QueryPermissionChecker.default'

# Set up a default endpoint that can be activated with a Director rule
SilverStripe\GraphQL\Manager.default:
class: SilverStripe\GraphQL\Manager
constructor:
schemaKey: default
properties:
Middlewares:
CSRFMiddleware: '%$SilverStripe\GraphQL\Middleware\QueryMiddleware.csrf'
HTTPMethodMiddleware: '%$SilverStripe\GraphQL\Middleware\QueryMiddleware.httpMethod'
SilverStripe\GraphQL\Controller.default:
class: SilverStripe\GraphQL\Controller
constructor:
manager: '%$SilverStripe\GraphQL\Manager.default'
SilverStripe\GraphQL\Schema\Interfaces\SchemaStorageCreator:
class: 'SilverStripe\GraphQL\Schema\Storage\CodeGenerationStoreCreator'

# Assign each DBField subclass with an associated internal type
SilverStripe\ORM\FieldType\DBField:
extensions:
- SilverStripe\GraphQL\Scaffolding\Extensions\TypeCreatorExtension
graphql_type: String
SilverStripe\ORM\FieldType\DBInt:
graphql_type: Int
SilverStripe\ORM\FieldType\DBBoolean:
graphql_type: Boolean
SilverStripe\ORM\FieldType\DBFloat:
graphql_type: Float
SilverStripe\ORM\FieldType\DBPrimaryKey:
graphql_type: ID
SilverStripe\ORM\FieldType\DBForeignKey:
graphql_type: ID
Psr\SimpleCache\CacheInterface.FileSchemaStore:
factory: SilverStripe\Core\Cache\CacheFactory
constructor:
namespace: "GraphQLSchema"

# Register the CRUD
SilverStripe\GraphQL\Scaffolding\Scaffolders\OperationScaffolder:
operations:
create: SilverStripe\GraphQL\Scaffolding\Scaffolders\CRUD\Create
read: SilverStripe\GraphQL\Scaffolding\Scaffolders\CRUD\Read
readOne: SilverStripe\GraphQL\Scaffolding\Scaffolders\CRUD\ReadOne
update: SilverStripe\GraphQL\Scaffolding\Scaffolders\CRUD\Update
delete: SilverStripe\GraphQL\Scaffolding\Scaffolders\CRUD\Delete
SilverStripe\GraphQL\Schema\Storage\CodeGenerationStore:
properties:
rootDir: '`BASE_PATH`'

SilverStripe\GraphQL\Controller:
extensions:
- SilverStripe\GraphQL\Extensions\IntrospectionProvider
SilverStripe\GraphQL\Manager:
SilverStripe\GraphQL\Schema\Schema:
schemas: []
---
Only:
Expand Down
18 changes: 18 additions & 0 deletions _config/dataobject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
Name: silverstripe-graphql-dataobject
---
SilverStripe\GraphQL\Schema\DataObject\DataObjectModel:
operations:
read: 'SilverStripe\GraphQL\Schema\DataObject\ReadCreator'
readOne: 'SilverStripe\GraphQL\Schema\DataObject\ReadOneCreator'
delete: 'SilverStripe\GraphQL\Schema\DataObject\DeleteCreator'
update: 'SilverStripe\GraphQL\Schema\DataObject\UpdateCreator'
create: 'SilverStripe\GraphQL\Schema\DataObject\CreateCreator'
SilverStripe\ORM\DataObject:
graphql_blacklisted_fields:
ClassName: true
LinkTracking: true
FileTracking: true
extensions:
- SilverStripe\GraphQL\Extensions\DevBuildExtension

18 changes: 18 additions & 0 deletions _config/dbtypes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
Name: graphql-dbtypes
---
# Assign each DBField subclass with an associated internal type
SilverStripe\ORM\FieldType\DBField:
graphql_type: String
SilverStripe\ORM\FieldType\DBInt:
graphql_type: Int
SilverStripe\ORM\FieldType\DBBoolean:
graphql_type: Boolean
SilverStripe\ORM\FieldType\DBFloat:
graphql_type: Float
SilverStripe\ORM\FieldType\DBDecimal:
graphql_type: Float
SilverStripe\ORM\FieldType\DBPrimaryKey:
graphql_type: ID
SilverStripe\ORM\FieldType\DBForeignKey:
graphql_type: ID
12 changes: 12 additions & 0 deletions _config/default-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
Name: 'graphql-default-schema'
---
SilverStripe\Core\Injector\Injector:
# Set up a default endpoint that can be activated with a Director rule
SilverStripe\GraphQL\Controller.default:
class: SilverStripe\GraphQL\Controller
constructor:
schema: default
# use a custom handler so it's easy to override/add middlewares in the default schema
handler: '%$SilverStripe\GraphQL\QueryHandler\QueryHandlerInterface.default'

19 changes: 11 additions & 8 deletions _config/dev.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---
Name: graphqltest
Before:
- '#sapphiretest'
Name: graphql-dev
---
SilverStripe\Core\Injector\Injector:
SilverStripe\Dev\State\SapphireTestState:
properties:
States:
disabletypecaching: '%$SilverStripe\GraphQL\Dev\State\DisableTypeCacheState'
SilverStripe\Dev\DevelopmentAdmin:
registered_controllers:
graphql:
controller: SilverStripe\GraphQL\Dev\DevelopmentAdmin
links:
build: 'Build/rebuild the GraphQL schema'
SilverStripe\GraphQL\Dev\DevelopmentAdmin:
registered_controllers:
build:
controller: SilverStripe\GraphQL\Dev\Build
39 changes: 13 additions & 26 deletions _config/filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,17 @@
Name: graphql-filters
---
SilverStripe\Core\Injector\Injector:
SilverStripe\GraphQL\QueryFilter\FilterRegistryInterface:
class: SilverStripe\GraphQL\QueryFilter\FieldFilterRegistry
SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FilterRegistryInterface:
class: SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterRegistry
constructor:
contains: '%$SilverStripe\GraphQL\QueryFilter\Filters\ContainsFilter'
eq: '%$SilverStripe\GraphQL\QueryFilter\Filters\EqualToFilter'
gt: '%$SilverStripe\GraphQL\QueryFilter\Filters\GreaterThanFilter'
lt: '%$SilverStripe\GraphQL\QueryFilter\Filters\LessThanFilter'
gte: '%$SilverStripe\GraphQL\QueryFilter\Filters\GreaterThanOrEqualFilter'
lte: '%$SilverStripe\GraphQL\QueryFilter\Filters\LessThanOrEqualFilter'
in: '%$SilverStripe\GraphQL\QueryFilter\Filters\InFilter'
endswith: '%$SilverStripe\GraphQL\QueryFilter\Filters\EndsWithFilter'
startswith: '%$SilverStripe\GraphQL\QueryFilter\Filters\StartsWithFilter'
SilverStripe\GraphQL\QueryFilter\DataObjectQueryFilter:
properties:
filterRegistry: '%$SilverStripe\GraphQL\QueryFilter\FilterRegistryInterface'
SilverStripe\ORM\FieldType\DBField:
graphql_default_filters: [ eq, in ]
SilverStripe\ORM\FieldType\DBInt:
graphql_default_filters: [ gt, lt, gte, lte ]
SilverStripe\ORM\FieldType\DBDate:
graphql_default_filters: [ gt, lt, gte, lte ]
SilverStripe\ORM\FieldType\DBTime:
graphql_default_filters: [ gt, lt, gte, lte ]
SilverStripe\ORM\FieldType\DBFloat:
graphql_default_filters: [ gt, lt, gte, lte ]
SilverStripe\ORM\FieldType\DBString:
graphql_default_filters: [ contains ]
contains: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\ContainsFilter'
eq: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\EqualToFilter'
ne: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\EqualToFilter'
gt: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\GreaterThanFilter'
lt: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\LessThanFilter'
gte: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\GreaterThanOrEqualFilter'
lte: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\LessThanOrEqualFilter'
in: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\InFilter'
endswith: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\EndsWithFilter'
startswith: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\StartsWithFilter'

30 changes: 30 additions & 0 deletions _config/middlewares.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
Name: 'graphql-middlewares'
---
SilverStripe\Core\Injector\Injector:
# default implementation
SilverStripe\GraphQL\QueryHandler\QueryHandlerInterface:
class: SilverStripe\GraphQL\QueryHandler\QueryHandler
properties:
Middlewares:
csrf: '%$SilverStripe\GraphQL\Middleware\CSRFMiddleware'
httpMethod: '%$SilverStripe\GraphQL\Middleware\HTTPMethodMiddleware'

# duplicate implementation do that the default schema has its own instance to
# configure without affecting other schemas
SilverStripe\GraphQL\QueryHandler\QueryHandlerInterface.default:
class: SilverStripe\GraphQL\QueryHandler\QueryHandler
properties:
Middlewares:
csrf: '%$SilverStripe\GraphQL\Middleware\CSRFMiddleware'
httpMethod: '%$SilverStripe\GraphQL\Middleware\HTTPMethodMiddleware'

Psr\SimpleCache\CacheInterface.graphql:
factory: SilverStripe\Core\Cache\CacheFactory
constructor:
namespace: "graphql"
defaultLifetime: 600

SilverStripe\GraphQL\Middleware\QueryCachingMiddleware:
properties:
Cache: '%$Psr\SimpleCache\CacheInterface.graphql'
16 changes: 16 additions & 0 deletions _config/model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
Name: silverstripe-graphql-model
---
SilverStripe\Core\Injector\Injector:
SilverStripe\GraphQL\Schema\Registry\SchemaModelCreatorRegistry:
constructor:
dataobject: '%$SilverStripe\GraphQL\Schema\DataObject\ModelCreator'
SilverStripe\GraphQL\Schema\Schema:
schemas:
'*':
modelConfig:
DataObject:
type_formatter: [ 'SilverStripe\Core\ClassInfo', 'shortName' ]
type_prefix: ''
type_mapping: []
nested_query_plugins: []
14 changes: 14 additions & 0 deletions _config/plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
Name: graphql-plugins
---
SilverStripe\Core\Injector\Injector:
SilverStripe\GraphQL\Schema\Registry\PluginRegistry:
constructor:
paginator: '%$SilverStripe\GraphQL\Schema\Plugin\PaginationPlugin'
dataobjectPaginator: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\Paginator'
dataobjectQueryFilter: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\QueryFilter'
dataobjectQuerySort: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\QuerySort'
dataobjectInheritance: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\Inheritance'
canViewPermission: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\CanViewPermission'
firstResult: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\FirstResult'
inheritedPlugins: '%$SilverStripe\GraphQL\Schema\DataObject\Plugin\InheritedPlugins'
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"type": "silverstripe-vendormodule",
"license": "BSD-3-Clause",
"require": {
"silverstripe/framework": "^5",
"silverstripe/framework": "^4",
"silverstripe/vendor-plugin": "^1.0",
"webonyx/graphql-php": "~0.12.6"
"webonyx/graphql-php": "^14.0"
},
"require-dev": {
"phpunit/phpunit": "^8 || ^9",
Expand Down
7 changes: 3 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
This folder contains a "pseudo-module" for SilverStripe
with some runnable code examples. In order to try them out yourself,
move the `examples` folder to the top level of your SilverStripe
project and remove the `_manifest_exclude` file.
## COMING SOON ##

The v4 release of this module does not yet have any example code.
59 changes: 0 additions & 59 deletions examples/_config/config.yml

This file was deleted.

Loading

0 comments on commit 1c4e623

Please sign in to comment.