Skip to content

Commit 08e9c94

Browse files
authored
Add GraphQL definitions for the Apollo Kotlin library (#609)
1 parent 9b36b81 commit 08e9c94

File tree

7 files changed

+61
-1
lines changed

7 files changed

+61
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Marks a field or variable definition as optional or required
2+
# By default Apollo Kotlin generates all variables of nullable types as optional, in compliance with the GraphQL specification,
3+
# but this can be configured with this directive, because if the variable was added in the first place, it's usually to pass a value
4+
directive @optional(if: Boolean = true) on FIELD | VARIABLE_DEFINITION
5+
6+
# Marks a field as non-null. The corresponding Kotlin property will be made non-nullable even if the GraphQL type is nullable.
7+
# When used on an object definition in a schema document, `fields` must be non-empty and contain a selection set of fields that should be non-null
8+
# When used on a field from an executable document, `fields` must always be empty
9+
#
10+
# Setting the directive at the schema level is usually easier as there is little reason that a field would be non-null in one place
11+
# and null in the other
12+
directive @nonnull(fields: String! = "") on OBJECT | FIELD
13+
14+
# Marks fields as key fields. Key fields are used to compute the cache key of an object
15+
# `keyFields` should contain a selection set. Composite fields are not supported yet.
16+
directive @typePolicy(keyFields: String!) on OBJECT | INTERFACE | UNION
17+
18+
# Indicates how to compute a key from a field arguments.
19+
# `keyArgs` should contain a selection set. Composite args are not supported yet.
20+
directive @fieldPolicy(forField: String!, keyArgs: String!) repeatable on OBJECT
21+
22+
# Indicates that the given field or enum value is still experimental and might be changed
23+
# in a backward incompatible manner
24+
directive @experimental(
25+
reason: String! = "Experimental"
26+
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE
27+

resources/messages/GraphQLMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ graphql.library.prefix=GraphQL:
9292
graphql.library.built.in=Specification
9393
graphql.library.relay=Relay
9494
graphql.library.federation=Federation
95+
graphql.library.apollokotlin=Apollo Kotlin

src/main/com/intellij/lang/jsgraphql/GraphQLSettings.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ public void setFederationSupportEnabled(boolean enableFederationSupport) {
114114
settingsChanged();
115115
}
116116

117+
public boolean isApolloKotlinSupportEnabled() {
118+
return myState.enableApolloKotlinSupport;
119+
}
120+
121+
public void setApolloKotlinSupportEnabled(boolean enableApolloKotlinSupport) {
122+
myState.enableApolloKotlinSupport = enableApolloKotlinSupport;
123+
settingsChanged();
124+
}
125+
117126
/**
118127
* The state class that is persisted as XML
119128
* NOTE!!!: 1. Class must be static, and 2. Fields must be public for settings serialization to work
@@ -126,6 +135,7 @@ public static class GraphQLSettingsState {
126135

127136
public boolean enableRelayModernFrameworkSupport;
128137
public boolean enableFederationSupport = false;
138+
public boolean enableApolloKotlinSupport = false;
129139
}
130140
}
131141

src/main/com/intellij/lang/jsgraphql/schema/library/GraphQLLibraryManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public final class GraphQLLibraryManager {
4040
private static final Map<GraphQLLibraryDescriptor, String> ourDefinitionResourcePaths = Map.of(
4141
GraphQLLibraryTypes.SPECIFICATION, "Specification.graphql",
4242
GraphQLLibraryTypes.RELAY, "Relay.graphql",
43-
GraphQLLibraryTypes.FEDERATION, "Federation.graphql"
43+
GraphQLLibraryTypes.FEDERATION, "Federation.graphql",
44+
GraphQLLibraryTypes.APOLLO_KOTLIN, "ApolloKotlin.graphql"
4445
);
4546

4647
private final Project myProject;

src/main/com/intellij/lang/jsgraphql/schema/library/GraphQLLibraryTypes.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public boolean isEnabled(@NotNull Project project) {
3737
}
3838
};
3939

40+
public static GraphQLLibraryDescriptor APOLLO_KOTLIN = new GraphQLLibraryDescriptor("APOLLO_KOTLIN") {
41+
@Override
42+
public boolean isEnabled(@NotNull Project project) {
43+
return GraphQLSettings.getSettings(project).isApolloKotlinSupportEnabled();
44+
}
45+
46+
@Override
47+
public @NotNull String getPresentableText() {
48+
return GraphQLBundle.message("graphql.library.apollokotlin");
49+
}
50+
};
51+
4052
private GraphQLLibraryTypes() {
4153
}
4254
}

src/main/com/intellij/lang/jsgraphql/ui/GraphQLSettingsConfigurable.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ class GraphQLSettingsConfigurable(private val project: Project) :
8989
settings::setFederationSupportEnabled
9090
).updateLibraries()
9191
}
92+
row {
93+
checkBox(
94+
message("graphql.library.apollokotlin"),
95+
settings::isApolloKotlinSupportEnabled,
96+
settings::setApolloKotlinSupportEnabled
97+
).updateLibraries()
98+
}
9299
}
93100
}
94101
}

src/test/com/intellij/lang/jsgraphql/GraphQLTestUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public static void withLibrary(@NotNull Project project,
5656
settings.setRelaySupportEnabled(true);
5757
} else if (libraryDescriptor == GraphQLLibraryTypes.FEDERATION) {
5858
settings.setFederationSupportEnabled(true);
59+
} else if (libraryDescriptor == GraphQLLibraryTypes.APOLLO_KOTLIN) {
60+
settings.setApolloKotlinSupportEnabled(true);
5961
} else {
6062
throw new IllegalArgumentException("Unexpected library: " + libraryDescriptor);
6163
}

0 commit comments

Comments
 (0)