-
Notifications
You must be signed in to change notification settings - Fork 63
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: Sync codegen behavior implementation - modify and integrate #892
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
84df35c
feat: Add vendor version of @graphql-codegen/core
stocaaro f85e86c
feat: Sync codegen behavior implementation - modify and integrate
stocaaro 7bbb583
Minor edits to maintenance instructions
stocaaro e5c11a1
Regenerate API and license to fix build issues
stocaaro a6e846b
Use sync behavior in comparison test
stocaaro b0073d2
simplify equality comparison
stocaaro 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Types, PluginFunction as PluginFunctionAsync, CodegenPlugin as CodegenPluginAsync } from "@graphql-codegen/plugin-helpers"; | ||
|
||
type PluginMapContainer = Pick<Types.GenerateOptions, 'pluginMap'>; | ||
type CacheContainer = Pick<Types.GenerateOptions, 'cache'>; | ||
|
||
export type SyncPluginMap<Obj extends PluginMapContainer> = Omit<Obj, 'pluginMap'> & { | ||
pluginMap: { | ||
[name: string]: Omit<Obj['pluginMap'][string], 'plugin'> & { | ||
plugin: ( | ||
...args: Parameters<Obj['pluginMap'][string]['plugin']> | ||
) => Awaited<ReturnType<Obj['pluginMap'][string]['plugin']>>; | ||
}; | ||
}; | ||
}; | ||
|
||
export type SyncCache<Obj extends CacheContainer> = Omit<Obj, 'cache'> & { | ||
cache?: (<T>(namespace: string, key: string, factory: () => T) => T) | undefined | ||
}; | ||
Comment on lines
+6
to
+18
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. These two helper types do most of the lifting here. They unwrap the Promise/Await type expectations so that the types can be used for sync versions of the target behavior. Awaited behavior is used/allowed for:
|
||
|
||
export declare namespace SyncTypes { | ||
type GenerateOptions = SyncCache<SyncPluginMap<Types.GenerateOptions>>; | ||
|
||
type PresetFnArgs< | ||
Config = any, | ||
PluginConfig = { | ||
[key: string]: any; | ||
} | ||
> = SyncCache<SyncPluginMap<Types.PresetFnArgs<Config, PluginConfig>>>; | ||
|
||
type OutputPreset<TPresetConfig = any> = { | ||
buildGeneratesSection: (options: PresetFnArgs<TPresetConfig>) => GenerateOptions[]; | ||
}; | ||
|
||
type PluginFunction<T> = (...args: Parameters<PluginFunctionAsync<T>>) => Awaited<ReturnType<PluginFunctionAsync<T>>>; | ||
|
||
type CodegenPlugin<T = any> = Omit<CodegenPluginAsync<T>, 'plugin'> & { | ||
plugin: PluginFunction<T>; | ||
} | ||
|
||
// Reiterating these types so that SyncTypes is a drop in replacement for Types | ||
type DocumentFile = Types.DocumentFile; | ||
type PluginConfig = Types.PluginConfig; | ||
type ConfiguredPlugin = Types.ConfiguredPlugin; | ||
type SkipDocumentsValidationOptions = Types.SkipDocumentsValidationOptions; | ||
type PluginOutput = Types.PluginOutput | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
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.
We had multiple versions in our node_modules, this consolidates down to a single version which makes it easier to detect if we upgrade.