-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support message for deprecated directive (#471)
- Loading branch information
1 parent
4917c4b
commit 9ce4569
Showing
62 changed files
with
626 additions
and
120 deletions.
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/kobylynskyi/graphql/codegen/model/DeprecatedDefinition.java
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,39 @@ | ||
package com.kobylynskyi.graphql.codegen.model; | ||
|
||
/** | ||
* @author 梦境迷离 | ||
* @version 1.0, 2020/12/28 | ||
*/ | ||
public class DeprecatedDefinition { | ||
|
||
private final static String DEFAULT_MSG = "No longer supported"; | ||
|
||
// For different languages, real implementation. | ||
private final String annotation; | ||
private final String reason; | ||
|
||
public DeprecatedDefinition(String annotation) { | ||
this.annotation = annotation; | ||
this.reason = DEFAULT_MSG; | ||
} | ||
|
||
/** | ||
* field reason Only support in Scala/Kotlin. | ||
* | ||
* @param annotation Definitions in different languages | ||
* @param reason Description in graphql schema Directive | ||
*/ | ||
public DeprecatedDefinition(String annotation, String reason) { | ||
this.annotation = annotation; | ||
this.reason = reason == null ? DEFAULT_MSG : reason; | ||
} | ||
|
||
public String getAnnotation() { | ||
return annotation; | ||
} | ||
|
||
public String getReason() { | ||
return reason; | ||
} | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/kobylynskyi/graphql/codegen/model/MultiLanguageDeprecated.java
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,33 @@ | ||
package com.kobylynskyi.graphql.codegen.model; | ||
|
||
import graphql.language.Directive; | ||
import graphql.language.StringValue; | ||
|
||
/** | ||
* @author [email protected] | ||
* @version 1.0, 2020/12/28 | ||
*/ | ||
public class MultiLanguageDeprecated { | ||
|
||
private final static String REASON = "reason"; | ||
private final static String SCALA_ANNOTATION = "deprecated"; | ||
private final static String JAVA_ANNOTATION = "Deprecated"; | ||
private final static String KOTLIN_ANNOTATION = "Deprecated"; | ||
|
||
public static DeprecatedDefinition getLanguageDeprecated(GeneratedLanguage generatedLanguage, Directive directive) { | ||
String msg = null; | ||
if (directive.getArguments().stream().anyMatch(argument -> argument.getName().equals(REASON))) { | ||
msg = ((StringValue) directive.getArgument(REASON).getValue()).getValue(); | ||
} | ||
switch (generatedLanguage) { | ||
case KOTLIN: | ||
return new DeprecatedDefinition(KOTLIN_ANNOTATION, msg); | ||
case SCALA: | ||
return new DeprecatedDefinition(SCALA_ANNOTATION, msg); | ||
//ignore msg | ||
case JAVA: | ||
default: | ||
return new DeprecatedDefinition(JAVA_ANNOTATION); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.