-
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
Typed Scalars #990
Comments
@nalchevanidze How well do you feel the https://github.com/graphql/graphql-wg/blob/main/rfcs/Struct.md |
thanks @benjie! i agree all of the points described in the post. about syntax and semantics i would use slightly different approach.
|
instead of polymorphism i would rather go for record Person {
name: String!
lastName: String!
}
type User {
...Person
id: String!
}
input Application {
...Person
jobPosition: String!
}
data Contact
= Employe {
...Person,
employeID: String
}
| Client {
...Person,
email: String
} but it is different topic |
Sounds like you are indeed after a different solution. To get a feature like this into the GraphQL Spec requires advancing it through the 4 RFC stages which normally will take at least 4 working groups. You can read more about the stages here: https://github.com/graphql/graphql-spec/blob/main/CONTRIBUTING.md#rfc-contribution-stages. You should start by focussing on the problem that needs to be solved - share the concrete (not generic) use cases. Then you write up your solution with a proposal, gather feedback and more use cases, then write this up into concrete spec edits and it's often beneficial (but not mandatory) to maintain an RFC document in the RFCs folder with details of what's being proposed, why, and what decisions have been made. Later you'll also push forward an implementation of it in graphql-js (you don't have to write it yourself) and hopefully convince another implementation to adopt it too; this gives implementors a chance to find any issues. Then we discuss it some more and if we get consensus, in it goes! Before embarking on this quest, I recommend you read the guiding principles: https://github.com/graphql/graphql-spec/blob/main/CONTRIBUTING.md#guiding-principles because you'll have to come up with convincing reasons why this change should be made. Should you wish to just gather current opinions, I recommend that you add yourself and this as a short (10-15m) agenda item to the next WG you can attend; see: https://github.com/graphql/graphql-wg/blob/main/agendas/2022. Adding yourself to the agenda will guide you through the process of signing the spec membership agreement. You may also choose to make some spec edits via a PR and propose elevating this to RFC1 at the WG. If you need any more guidance, you can reach out to me either here or via the GraphQL Discord https://discord.graphql.org/ in the #wg channel. |
I think you can write up an RFC for your solution and reference the relevant parts of the struct document w.r.t. the problems (try and call out specific ones rather than "all of them", and I suggest you use permalinks - you can press |
@benjie I don't see there's an issue in the GitHub repo concerning I think a compelling case for But the properties contained in the block are pure data (blocks can also contain "nested blocks", which need a type, but that can be retrieved via a different field I guess when fetching the struct data in wildcard mode (i.e. without specifying what properties to fetch) on a struct union, then also sending I also like Concerning fetching data from external endpoints, I currently have this field: type Query {
getJSON(url: String!): JSONObject
} I wonder if it would be possible to assign the returned (Creating a field for each endpoint, i.e. |
Thanks for the pointer! I'd already envisioned it being used for ProseMirror documents, but Wordpress documents would be a great addition!
That's the idea behind type Query {
getJSON(url: String!): GetJSONResponse
}
struct union GetJSONResponse = PostsStruct | UsersStruct
struct PostsStruct { ... }
struct UsersStruct { ... }
It's perfectly acceptable to file pull requests against RFC documents, adding your use cases into the relevant places. These kind of PRs help to advance the RFC by showing it's not just one person's need! |
My idea is different: to be able to use a random endpoint, without having to modify the schema. That's because the schema for WordPress is predefined (all the resolvers are provided by the plugin), but the endpoints to access via |
That's definitely well out of scope of what the struct type is trying to achieve; if you'd like to propose a solution to that I'd be very interested to read the RFC. |
Typed Scalars
Some time before i started writing subset language of GQL (with name iris) which would take best parts of GQL and simplify and generalize it. although it made a lot of fun writing it, i think best way to solve problems would be to introduce this features directly in GQL, one of which is typed scalars (with name
data
).motivation
server-to-server
requests (likeRPC
)hypothetically it can make
enums/inputObjects
redundant and reduce schema complexity.I know the requirement for new features in the language is high, but I think this feature can be beneficial and removes unnecessary limitations for the language. for now, instead of modeling tree types in GQL, people either go to another language or model them with untyped JSON objects, which is not such a good option. same problem is with input unions.
definition
core idea of typed scalars is to extend GQL type system with typed JSON objects. this new kind of
data
types will not resolve any value (no dedicated type resolvers) but only check their validity.in my opinion use of algebraic data types for their definitions would be most suitable (syntax is described in language definition iris).
since there is already implementation for this feature in iris, i could freely open PR for that.
non breaking
client with old GQL version will read it as scalar types with type definition as JSDoc annotations (PR in apollo) in description. however for new clients it will provide field
dataVariants
: which will include description of variant definitions for the type.The text was updated successfully, but these errors were encountered: