-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Algebraic interface types #48
Comments
Following on the request for more real-world example: It is actually very similar to the one I used. It's a content fetching API and what I was trying to do were content collections. There are multiple types of collections ( So what I'd like to do is have a
Without needing two specific interfaces for Hope that helps to provide some more context around the idea. |
Thanks for the more concrete example, this is really interesting. |
Hi, @leebyron, I have a couple of questions of GraphQL "interfaces". (1)
Based on Schema for Schema Introspection result in the RFC under "4.2 Schema Introspection",
However, all the examples of Type definition document in RFC only show the case of implementing a single interface. While I can find Grammar for Query Document, I cannot find Grammar for Type Definition Document. (2) Background Note : We have used "allOf" in JSON Schema in a number of projects quite extensively. Alex Yiu |
Yes, Objects may implement multiple interfaces. The experimental grammar for defining types works exactly the way you assumed, and you're correct in assuming so based on the fact that introspection returns a list of interfaces for an object type. You can find the work-in-progress grammar for this at #90 Interfaces cannot extend other interfaces. There's no current plan to change this as it adds some avoidable complexity. |
@leebyron .... thank you for confirming this feature and quick turnaround time of answering my questions. |
@leebyron I don't suppose you have an expected ETA on when the multiple interface support is likely to be available? Also, will this allow me to change my schema to something similar to this?
|
@Cyberlane, you can currently have an Object type implement as many interfaces as you like (the SmartPhone example) however there are currently no plans to implement intersection types (your findAll example) - for those cases you could use either another Interface which includes both sets of fields, or a Union type |
As originally discussed in graphql/graphql-js#45, it would be useful to be able to declare a field type to be a combination of interfaces.
As an example use-case, let's say I have an interface
which represents an image I can display. Some images are stand-alone and I can link to them as a page, but other things share that capability (videos for instance). So I have another interface
Now let's say that all users have profile pictures which are linkable. I'd like to be able to declare something like this
When resolving such type, the only requirement is for the interfaces not to contain the same attributes. From there it should be possible to find the defining interface for each attribute and then the implementing type based on interface type resolution.
The text was updated successfully, but these errors were encountered: