-
Notifications
You must be signed in to change notification settings - Fork 65
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
feat(server): add a subscriptions server #1397
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,11 @@ export type PlaygroundLonghandInput = { | |
} | ||
|
||
export type SettingsInput = { | ||
subscriptions?: | ||
| boolean | ||
| { | ||
enabled?: boolean | ||
} | ||
/** | ||
* Port the server should be listening on. | ||
* | ||
|
@@ -212,6 +217,20 @@ export type SettingsData = Setset.InferDataFromInput<Omit<SettingsInput, 'host' | |
export const createServerSettingsManager = () => | ||
Setset.create<SettingsInput, SettingsData>({ | ||
fields: { | ||
subscriptions: { | ||
shorthand(enabled) { | ||
return { enabled } | ||
}, | ||
fields: { | ||
enabled: { | ||
initial() { | ||
// This is not accurate. The default is actually dynamic depending | ||
// on if the user has defined any subscription type or not. | ||
return true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See large design comment about Setset |
||
}, | ||
}, | ||
}, | ||
}, | ||
apollo: { | ||
fields: { | ||
engine: { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following comment is really reflection on the Setset library.
It would be great if Setset could have initializers that depend upon external data.
This would require initializers to not run at construction time but at "assembly" time. External data would be passed at this time. And initializers would then run.
This would mean it would not be possible for users to access settings data and metadata before assembly. At least those that depend on assembly.
We could call these settings "assembled settings".
Maybe assembled settings would have a special initialized state before assembly. Like a constant
"__PENDING_ASSEMBLY__"
. That could work from a runtime point of view.What about from a static point of view? Firstly, like
Setset.Leaf
we would need a new typeSetset.Assembled
.Then we would need the new
.assemble
method to return a statically transformed version of the settings wherein"__PENDING_ASSEMBLY__"
would be stripped as a type.Example:
This static behaviour looks NTH at best for Nexus b/c end users wouldn't be seeing this static transformation b/c it happens internally within Nexus.
What would be user facing though is this case:
Assembled initializers don't matter once the user has explicitly set the setting.
Like before we could capture the transformation in the return value of
.change()
(maybe...) however the mutative quality of Setset is currently an important DX aspect of it so it can be used as an e.g. singleton. ... This looks like an impossible problem to solve not withstanding new features from TS itself.Typegen doesn't help because the effect lives between LOC.
One solution could be a utility to strip the pending assembly type:
Statically this would strip the
"__PENDING_ASSEMBLY__"
type. Dynamically it would check that the value isn't"__PENDING_ASSEMBLY__"
. Those dynamic checks could be disabled in production.If most settings were assembled and the user often accessed those settings having to wield this utility function often could get very annoying.
But frankly it is totally unclear if that is the case. For example in Nexus the number of users that are going to be checking the
settings.data.server.subscriptions.enabled
option seems to be near zero.So overall my conclusion is:
settings.data.server.subscriptions.enabled // false
when its actually true because they defined subscription type in this schema.change
effects mutatively so the utility functionnotPendingAssembly
can come to the rescue in rare (?) occasions when user needs to deal with the assembled setting explicitly