File tree Expand file tree Collapse file tree 4 files changed +61
-4
lines changed
Expand file tree Collapse file tree 4 files changed +61
-4
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ func DisallowExpirationFlag() Option {
9191
9292func DisallowDeprecationFlag () Option {
9393 return func (cfg * config ) {
94- cfg .allowedFlags = lo .Filter (cfg .allowedFlags , func (s string , _ int ) bool {
94+ cfg .allowedFlags = slicez .Filter (cfg .allowedFlags , func (s string ) bool {
9595 return s != deprecationFlag
9696 })
9797 }
Original file line number Diff line number Diff line change @@ -202,6 +202,20 @@ func (sg *sourceGenerator) emitNamespace(namespace *core.NamespaceDefinition) er
202202 sg .markNewScope ()
203203
204204 for _ , relation := range namespace .Relation {
205+ if relation .DeprecationType != core .DeprecationType_DEPRECATED_TYPE_UNSPECIFIED {
206+ sg .flags .Add ("deprecation" )
207+ sg .append ("@deprecated(" )
208+
209+ switch relation .DeprecationType {
210+ case core .DeprecationType_DEPRECATED_TYPE_WARNING :
211+ sg .append ("warn" )
212+ case core .DeprecationType_DEPRECATED_TYPE_ERROR :
213+ sg .append ("error" )
214+ }
215+ sg .append (")" )
216+ sg .appendLine ()
217+ }
218+
205219 err := sg .emitRelation (relation )
206220 if err != nil {
207221 return err
Original file line number Diff line number Diff line change @@ -395,6 +395,38 @@ definition document {
395395 relation viewer: user
396396}` ,
397397 },
398+ {
399+ "deprecation test" ,
400+ `use deprecation
401+
402+ definition document {
403+
404+ @deprecated(warn)
405+ relation viewer: user
406+
407+ @deprecated(error)
408+ relation editor: user
409+ }` ,
410+ `use deprecation
411+
412+ definition document {
413+ @deprecated(warn)
414+ relation viewer: user
415+ @deprecated(error)
416+ relation editor: user
417+ }` ,
418+ },
419+ {
420+ "unused deprecation flag" ,
421+ `use deprecation
422+
423+ definition document{
424+ relation viewer: user
425+ }` ,
426+ `definition document {
427+ relation viewer: user
428+ }` ,
429+ },
398430 }
399431
400432 for _ , test := range tests {
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ const (
1313 // FlagTypeChecking indicates that `typechecking` is supported as a first-class
1414 // feature in the schema.
1515 FlagTypeChecking = "typechecking"
16+
17+ // FlagDeprecation indicates that `deprecation` is supported as a first-class
18+ // feature in the schema.
19+ FlagDeprecation = "deprecation"
1620)
1721
1822var AllUseFlags []string
@@ -22,9 +26,6 @@ func init() {
2226 slices .Sort (AllUseFlags )
2327}
2428
25- // Deprecation Flag
26- const FlagDeprecation = "deprecation"
27-
2829type transformer func (lexeme Lexeme ) (Lexeme , bool )
2930
3031// Flags is a map of flag names to their corresponding transformers.
@@ -44,6 +45,16 @@ var Flags = map[string]transformer{
4445
4546 return lexeme , false
4647 },
48+
49+ FlagDeprecation : func (lexeme Lexeme ) (Lexeme , bool ) {
50+ if lexeme .Kind == TokenTypeIdentifier && lexeme .Value == "deprecation" {
51+ lexeme .Kind = TokenTypeKeyword
52+ return lexeme , true
53+ }
54+
55+ return lexeme , false
56+ },
57+
4758 FlagTypeChecking : func (lexeme Lexeme ) (Lexeme , bool ) {
4859 // `typechecking` becomes a keyword.
4960 if lexeme .Kind == TokenTypeIdentifier && lexeme .Value == "typechecking" {
You can’t perform that action at this time.
0 commit comments