-
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 input type inheritance #23
Comments
Why would If you're expecting |
More generally, it seems like a mutation would either be designed for specific subclass, or if it were generic it would only make use of the fields provided by a parent class. For operations that aren't "create" or "update" — e.g. "delete or publish" — I'd expect that we use something narrower, like and ID or a BaseClass + ID pair, to identify objects. |
If you wanted something truly generic I would probably just admit the type weakness and go for something of the form:
|
I've added @sminnee feedback as "option 3", and agree that this is the best way forward. |
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
Aaron's done this in #20 now, hooray! |
Related to Scaffold object type inheritance
Overview
Object types in queries should represent the SilverStripe inheritance structure, in order to make it clear which fields a developer can expect to be returned from a query, and to which part of the PHP class inheritance chain they belong (e.g.
Page
vs.RedirectorPage
).The same rationale applies to "input types" used for mutations. But as opposed to "object types", they don't support polymorphism through unions. While there's a graphql-js plugin we could port to graphql-php for this, we'd be going outside of the GraphQL spec for this. It's unlikely that this would be accepted into the graphql-php project.
Option 1: One mutation, separate fields for input types
Input types can be nested. One solution would be creating a field for each possible subclass, and then create a specific input type for it. This allows us to retain strong typeing, e.g. making fields mandatory on certain subclasses. One downside here is that we can't enforce that any of these fields is passed through GraphQL, and have to raise an exception in our own resolvers instead.
Option 2: One mutation, flattened input type
Alternatively, we could flatten the structure, and indicate the desired class through a
className
field. This isn't ideal because we can't enforce non-null fields through GraphQL, and have to use exceptions in our own logic instead. It also makes it less clear which fields belong to which subclass to developers navigating the GraphQL API surface. Given that we split up object types by subclass, that's a relevant concern for this target group.Option 3: Multiple mutations, each with one input type
Using the same types as above, we could create specialised mutations for each subclass. This increases the API surface, but makes the input and return arguments much clearer (1:1 mapping with types).
The text was updated successfully, but these errors were encountered: