-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scaffold types and queries from DataObject #9
Comments
I've discussed this a bit more with @unclecheese, and here's some really rough drafts on how this could look like. Overall, we feel that YAML could provide a good result for most use cases, as long as you can write custom resolver classes. These would be injectable, and implement GraphQL:
Member:
operations:
- all: true # implies 'create', 'read', 'update', 'delete'
fields:
- Email
- Fullname
- Groups # Implicitly creates a "Group" GraphQL type
resolver: MyGraphQLMemberResolver
Group:
operations:
- read: true #only allow reads
fields:
Title class MyGraphQLMemberResolver extends GraphQLResolver {
public function resolve($args) {
$list = Member::get();
// Optional filtering (could be more succinct through SearchContext)
if($args['Email'])
$list = $list->filter('Email', $args['Email']);
return $list;
}
// Alternative to accessing DataObject getters
public function resolveFullname($obj) {
return $obj->FirstName . ' ' . $obj->LastName;
}
} Alternatively, a more fluent API: $scaffolder = (new GraphQLScaffolder())
->addDataObject('Member')
->addOperation('Member', GraphQLScaffolder::READ, [])
->addFieldResolver('Member', function($args) {
$list = Member::get();
// Optional filtering (could be more succinct through SearchContext)
if($args['Email'])
$list = $list->filter('Email', $args['Email']);
return $list;
})
->setFields('Group', ['Title']);
// Get a TypeCreator for further customisation
$memberType = $scaffolder->getType('Member');
// Add all created types, queries and mutations to a schema (through the Manager API)
$scaffolder->addToManager($manager); I've found an EZSystems configuration which takes a similar approach: https://github.com/bdunogier/ezplatform/blob/graphql/src/BD/EzPlatformGraphQLBundle/Resources/config/services.yml |
I've created some pseudo code for this. Deliberately rough around the edges, since, in all likelihood it's way off. :) Have a look and let me know if this is what you're thinking: https://gist.github.com/unclecheese/b56833232f521d9873781a4bc4827a2a |
Had a chance to work on this over the weekend. Have a look https://github.com/silverstripe/silverstripe-graphql/tree/feature/scaffolding |
At the moment this is limited to "read files" and "create folder". The remaining API endpoints will be successively moved over to GraphQL. The GraphQL type creators are likely temporary, to be replaced with a shorter scaffolding-based version: silverstripe/silverstripe-graphql#9 silverstripe/silverstripe-graphql#22 silverstripe/silverstripe-graphql#23 RFC at silverstripe/silverstripe-framework#6245
Is this done, now? It seems to be mostly done...? |
It would be hard to make the case that it isn't. :) |
…pdate-archive-warning-msg ENHANCEMENT Remove item from change sets when it's archived
Maybe you could infer types from class to reduce boilerplate. Something like https://github.com/prismake/typegql |
…odal-height FIX react modal height
…3/xss-hollywood CVE-2019-14272 Sanitise link text for insert modals
At the moment there's a lot of boilerplate involved in creating GraphQL types (example). Reduce this by inferring data from DataObjects (where types/queries are based on them).
DBField
(String, Text, Enum, etc)createPage
mutation which works with all subclasses ofPage
)SearchContext
definitionsDataExtension
)See https://github.com/chillu/silverstripe-graphql/issues/8 for a start on an API.
The text was updated successfully, but these errors were encountered: