-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Extend Wrapping Types with additional primitive Tuple #904
Comments
an additional advantage is that: since |
that looks really problematic to me. You suggest essentially a syntactic sugar, a shortcut that allows you to skip explicitly declaring a type with fields. Benefits are tiny I think. Defining an extra explicit return type is done on server when you define model, once. Writing queries - does not change anything. It is a server-side syntactic sugar, for stuff that you write once. Seems questionable benefit to me. The auto-tuples work well in IDEs with intelli-sense, where editor and compiler infer the exact sub-type of tuple and follow thru with syntax checks down the line. But there is in fact an explicit type behind it, like in .net with generics: Tuple<string, int, int>; compiler follows thru as if you declared this type explicitly. Now, for graphql server. The number of args and arg types are part of tuple type in your proposal? so that |
Hi @rivantsov, thanks for you remark!
i don't got this part. could you explain it in details with an example? Generics and Complexity
I think we have generic types with only parameter(called wrapping types). type List<a> = [a]
type NonNull<a> = a! My proposal uses the same pattern and allows only one parameter, which should be used as the last element of tupple. All other parameters are stored in
i think checking input tupples would be less complicated then checking input object.
hypothetical. yes. but only as a last parameter of the tuple (like in example). (!ID, (Int!, User!)) however, I don't yet see a reason why someone would like to use it, since it becomes less readable at the certain level of nesting. To avoid cumbersome tuples, we can limit the number of elements (max 4) and the nesting level (max 3). Benefits
I disagree. Tuples and maps are a necessary feature and are supported in most languages, but GraphQL does not have them. Therefore, in languages that do support tuples, we have a problem representing them in a meaningful way. Take as example. my Haskell library generates API based on native types. if we have type input Input_Tuple_ID_Int = {
key: ID!,
value: Int!
}
type Tuple_ID_Int = {
key: ID!,
value: Int!
}
input Input_Tuple_ID_String = {
key: ID!,
value: Int!
}
type Tuple_ID_String = {
key: ID!,
value: Int!
} however, i think that these types are redundant and and makes the schema cumbersome to read. they could simply be written with just two expressions |
Note - as other language I use c# as 'other language' that has tuples and maps (dictionaries).
Maps and tuples are fundamentally different in the context of this discussion. GraphQL does need map type I agree. Map is not a syntactic sugar, it is an actual concept that cannot be modeled/substituted with existing facilities.
This restriction on first (n-1) types, and only last one being any type - seems quite cumbersome to me. People learning GraphQL would say 'wow, what a strange tuple limitation' - comparing it to tuples in 'other languages' they already know.
Wrapping types (list and non-null) - these are definitely not generics, like 'we already have simple generics'. Array in general is fundamental type in most languages, even those that do not have generics. And nonNull - well, technically speaking it's not type I think, this is a constraint on field containing type. For whatever reason, simplicity I guess, they decided to use a wrapping type to represent nonNull 'type'; but what I'm saying all this wrapping business has nothing to do with generics. Wrapping is a simple trick to represent a wrap type in introspection, and it does not reflect the 'nature' of the type I think. About complexity of type system with proposed tuples. Let's say you list SDL doc for an API. It currently lists all custom types plus a few standard types, and it is only these types that you will meet in arguments and return types of functions. So to sum it up, my suggestion - let's talk about Map, not tuples. |
Parametrised Types
The term NonNull
data Maybe a = Just a | Nothing there is also equivalent of type NonNull<T> = T extends null ? never : T; Type Declaration and Naming
actually lookup function for types will have following interface: lookupType:: TypeName -> [TypeParameter] -> Type resulting type will already return the type where all type variables are resolved.
name of the type will include its parameters like: Conversion rules
input validation is actually no problem. it is has same complexity as validating input input MyType {
__0: Float
__1: String
} Real problemthe real problem is output types. how we determine which fields are selected. for example: type Query {
map: [(Type1!,Type2!)!]!
} how we can determine their fields?
this is one restriction to solve this problem. however you are right. it is cumbersome! i tried different approaches in my GQL like language iris. two of them are. option1: select as a system fields
|
Supporting Mapsrequirements
Solution 1: custom type Map
type Query {
users: Map<ID,User>
} in this expression advantages:
disadvantages:
Solution 2: named ListsThis proposal is actually independent of the tuples or maps, but could be seen as a lightweight solution to this particular problem (see #914). actual implementation is already tested in my language iris we could use named lists to define list Map
type Query {
users: Map<Users>
} pros: is lightweight cons: we can't support maps |
P.S. Actually we could use JS destruction for tuples or maps (inspired by #888). for schema below we could use type Query {
users: [(Key,User!)!]!
} then we don't need limitation that first element should be a scalar or enum. |
Related: #534. |
GraphQL Tuples
At this stage, GraphQL does not provide tuples. This issue proposes to extend the GraphQL specification with an additional primitive type
Tuple
(of kindWRAPPER
).a GraphQL tuple
(a₁,...,aₙ₋₁, type)
is a list of fixed sizen
, where the firstn-1
arguments can be eitherenum
,scalar
, orwrapper
types, but the last argument can take any possible type.accordingly, the selection will be applied only to the last argument.
For example a API with the following schema for query
{ users { name } }
will produce the response:
this way we can support a
Map
in GraphQL.Additional considerations of syntax, semantics, and introspection are presented in the morpheus-graphql-proposals
The text was updated successfully, but these errors were encountered: