-
Notifications
You must be signed in to change notification settings - Fork 423
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
refactor: remove ScalarValue type parameter #782
refactor: remove ScalarValue type parameter #782
Conversation
The type parameter S for ScalarValue is used to open up a degree of freedom in the parsing of leaf scalar types. However because of that it is threaded through the entire codebase. This commit removes the type parameter in all possible places with the following in mind: * Fix the S parameter to DefaultScalarValue where necessary (mainly in Value which occurs on the return path after resolution) * Remove the parameter everywhere else This commit effectively disables the feature. I'm committing here mainly because now it compiles so I want a safe point. Next we need to figure out how to re-add the ability to control the leaf value parsing
Now the idea is that we'll let users annotate their types with a ScalarValue, but we'll generate a converter rather than threading the type all through the codebase. To that end this commit restores some of the bookkeeping previously deleted.
I'm very much in favour of it. |
@tyranron @ccbrown guys, after working on this for over a week, I'm at a point where I could use some guidance. What I have done so far is to remove the My understanding of the problem is currently that we need an implementation of
The current approach achieves this by threading the What I wanted to do is to leave the InputVariables basically unparsed and late-bind something that can parse them only at resolution time. At the same time that something can perform the inverse conversion on the result of the resolver. In all likelihood that something needs to be passed to the validation too so we can be sure the type will convert at the time of resolution. I have attempted to do this by changing all The progress is slow also because there seems to be a circular dependency between Anyway, I thought I'd ask for opinions before spending another fruitless night fighting the borrow checker :) |
I think my best advice is to work on this with more of a bottom-up approach that can be merged piece-meal. I have a local branch where I started to remove |
Yeah, that's what I tried in the beginning, but since everything is interconnected, I ended up removing it everywhere at once. I guess what I'm asking is
|
The first places where In the AST, we should represent values with an enum that looks something like this: pub enum Value<'a, S> {
Null,
Bool(bool),
Scalar(ScalarToken<'a>),
Enum(String),
Variable(String),
List(Vec<Spanning<Value<'a, S>>>),
Object(Vec<(Spanning<String>, Spanning<Value<'a, S>>)>),
_ScalarValue(PhantomData<S>), // TODO: remove me
} Because just deleting all of the Once everything is updated to either use These will need to call some function that takes a Once we have those conversions done outside of the parser we can focus on deleting all of the template variables in a subsequent commit or PR. Hope that helps! |
@mirosval @ccbrown giving this a lot of thoughts and experiments before, I've found the following observations and conclusions: There are two purposes of using
Beside those I don't see any other use cases for using custom So, the whole Let's start with a simple one:
The parsing is not a big deal. Similarly to what @ccbrown has proposed above, we may just put the pub enum InputValue<'a, S> {
// ...
Scalar(ScalarToken<'a>),
// ...
} And allow to parse from However, keeping defaults in schema is a question: Now, move on to a harder problem: |
Yeah I don't expect |
@ccbrown and that's the problem: |
I don't think that prevents us from getting rid of the type parameter in all of the AST types, which personally is my main hope. I'm not even expecting to remove it from |
Thank you for the thoughtful advice. I see now that this PR is a little overzealous with removing it in too many places. I'd propose the following:
Let me restate the general problem again:
To me this looks a lot like the |
ack @LegNeato it would be nice to hear some thoughts from you on this topic. Getting rid of Actually, I still doubt that library users use custom |
Guys, I have re-started the work on this already 3x from different ends and it seems I can't figure out how to do this in small pieces. I'm giving up. |
I would have liked to use custom The need came from the fact that sometimes, one has a "json string" (coming from the database directly) and i would like to avoid a serialize/deserialize step I was looking at having something like
Then look into using serde's |
The type parameter S for ScalarValue is used to open up a degree of freedom in the parsing of leaf scalar types. However because of that it is threaded through the entire codebase. This commit removes the type parameter in all possible places with the following in mind:
This commit effectively disables the feature. I'm committing here mainly because now it compiles so I want a safe point.
Next we need to figure out how to re-add the ability to control the leaf value parsing. I figured that we can do that effectively from this point either by adding it from scratch or by un-removing it from this commit.