Comments (9)
My name is Khan
from graphql-spec.
KHHHHHHHHHAAAAANNNNN
from graphql-spec.
@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
from graphql-spec.
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 (Page
, Search
, List
) and then there are specific named collections at the top level (e.g. Editor's picks). Some of those named collections have a url
associated to go to the collection specific page and that depends on a) the type of collection it is b) the specific collection (top stories for instance don't have a URL).
So what I'd like to do is have a Collection
interface, which defines a collection has a title
and items
, and a Linkable
interface that says there is an url
field. Then I could say
queryType {
top: Collection
editors: Collection + Linkable
}
Without needing two specific interfaces for Collection
and LinkableCollection
(which is ok now, but I could imagine adding other "traits" later and things getting out of control). The other reason is I don't really want to leak the specific types up to the top level, because they may change based on where content gets fetched from, but the interface will likely stay the same.
Hope that helps to provide some more context around the idea.
from graphql-spec.
Thanks for the more concrete example, this is really interesting.
from graphql-spec.
Hi, @leebyron,
I have a couple of questions of GraphQL "interfaces".
(1)
I am wondering whether GraphQL allows a single Type implements Multiple Interfaces.
Using the example above, a related Type definition document would look like the following:
type ProfilePicture implements Linkable, Image {
# skipping field declaration details here
}
Based on Schema for Schema Introspection result in the RFC under "4.2 Schema Introspection",
https://facebook.github.io/graphql/#sec-Schema-Introspection
it looks like a single Type can implement multiple interfaces.
# OBJECT only
interfaces: [__Type!]
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.
"B.3 Query Document"
https://facebook.github.io/graphql/#sec-Appendix-Grammar-Summary.Query-Document
So, it did not help me to confirm whether this is a supported semantic or not.
(2)
Also, can an Interface "extend" from a bunch of other interfaces?
Based on the current comments under "4.2 Schema Introspection", it seems to imply "no".
Background Note :
Under JSON Schema, there is a construct of "allOf".
http://json-schema.org/latest/json-schema-validation.html#anchor82
We have used "allOf" in JSON Schema in a number of projects quite extensively.
From a technology migration viewpoint, it would be nice to allow:
(1) a single "type" "implements" multiple interfaces, and,
(2) a single "interface" "extends" multiple interfaces.
Alex Yiu
https://www.linkedin.com/in/alexyiu
from graphql-spec.
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.
from graphql-spec.
@leebyron .... thank you for confirming this feature and quick turnaround time of answering my questions.
from graphql-spec.
@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?
interface IHaveGPS {
someSetting: String
someOtherSetting: String
}
interface IHaveCellular {
cellSetting: String
}
type GenericGPS implements IHaveGPS {
someSetting: String
someOtherSetting: String
}
type SmartPhone implements [IHaveGPS, IHaveCellular] {
someSetting: String
someOtherSetting: String
cellSetting: String
}
type Query {
findAll: [IHaveGPS, IHaveCellular]
}
from graphql-spec.
Related Issues (20)
- (Graphql-schema) Cannot query field "closeDiscussion" on type "Mutation" HOT 1
- GraphQL spec is contradictory: can selection sets be empty or not? HOT 1
- Allow to return Input Object types HOT 1
- Formalize Global Object Identification.
- Grammar should have single root node HOT 2
- [Feature request]: Support non-list variables for list arguments HOT 9
- Redundant field aliases identical to field names
- Document Level Directives HOT 7
- Coercing Variable Values when hasValue is not true and defaultValue does NOT exist HOT 7
- Strawman: mention of non-self-describing responses
- why not allow directive on field argument ? HOT 2
- On specifying ordered vs unordered enum definitions HOT 5
- Casting Error in GraphQL C# Library HOT 2
- Is there a reason graphql floats do not support Infinity and NaN? HOT 3
- Composite types is not clearly defined HOT 1
- Unclear spec for array with fragments HOT 1
- What must be the result of executing only one fragment on a list of union or interface type? HOT 3
- Interface conditions fragments may not be used across spreads, discouraging reusability HOT 2
- Hey HOT 1
- Really
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-spec.