Change Key param on Field to SourceAtKey
#26
Merged
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.
The
Keytype parameter onFieldhas been replaced with a new type parameter (SourceAtKey) and represents essentiallySource[Key]instead ofKey. For example, a field like this can be written:and
fieldwill be usable like this:The field is usable at
namesince the source type has an object with anameproperty that's astringbut using it atotherwill result in a type error since the source type doesn't have aotherproperty.Previously, using
g.fieldoutside ag.object/g.fieldscall would require specifying a resolver and fields written withing.fieldswould be bound to be used at a specific key rather than the new behaviour of any key with the right type.This also reduces the need for
g.fields. For example, the example given in the previous JSDoc forg.fields:Now the
g.fieldscall is unnecessary and writingnodeFieldswill no longer error at theg.fieldcall and will instead work as expected.There is still some use to
g.fieldsfor when you want to define a number of shared fields with resolvers and specify the source type just once in theg.fieldscall rathe than in every resolver.This change is unlikely to break existing code except where you explicitly use the
Fieldtype or explicitly pass type parameters tog.field(the latter of which you likely shouldn't do) but since it changes the meaning of a type parameter ofField, it's regarded as a breaking change.