Skip to content

Commit 70e7de1

Browse files
authored
validate query/mutation/subscription directives (#5113)
1 parent 6a06344 commit 70e7de1

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo3/ast/internal/ExecutableValidationScope.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import com.apollographql.apollo3.ast.SourceLocation
3535
import com.apollographql.apollo3.ast.VariableUsage
3636
import com.apollographql.apollo3.ast.definitionFromScope
3737
import com.apollographql.apollo3.ast.findDeprecationReason
38-
import com.apollographql.apollo3.ast.rawType
3938
import com.apollographql.apollo3.ast.pretty
39+
import com.apollographql.apollo3.ast.rawType
4040
import com.apollographql.apollo3.ast.responseName
4141
import com.apollographql.apollo3.ast.rootTypeDefinition
4242
import com.apollographql.apollo3.ast.sharesPossibleTypesWith
@@ -336,6 +336,11 @@ internal class ExecutableValidationScope(
336336

337337
fieldsInSetCanMerge(selections.collectFields(rootTypeDefinition.name))
338338

339+
directives.forEach {
340+
validateDirective(it, this) {
341+
variableUsages.add(it)
342+
}
343+
}
339344
variableUsages.forEach {
340345
validateVariable(this, it)
341346
}

libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo3/ast/internal/ValidationCommon.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.apollographql.apollo3.ast.GQLNonNullType
1919
import com.apollographql.apollo3.ast.GQLNullValue
2020
import com.apollographql.apollo3.ast.GQLObjectTypeDefinition
2121
import com.apollographql.apollo3.ast.GQLOperationDefinition
22-
import com.apollographql.apollo3.ast.GQLOperationTypeDefinition
2322
import com.apollographql.apollo3.ast.GQLScalarTypeDefinition
2423
import com.apollographql.apollo3.ast.GQLSchemaDefinition
2524
import com.apollographql.apollo3.ast.GQLSchemaExtension
@@ -104,7 +103,7 @@ internal fun ValidationScope.validateDirective(
104103
is GQLInlineFragment -> GQLDirectiveLocation.INLINE_FRAGMENT
105104
is GQLFragmentSpread -> GQLDirectiveLocation.FRAGMENT_SPREAD
106105
is GQLObjectTypeDefinition -> GQLDirectiveLocation.OBJECT
107-
is GQLOperationTypeDefinition -> {
106+
is GQLOperationDefinition -> {
108107
when (directiveContext.operationType) {
109108
"query" -> GQLDirectiveLocation.QUERY
110109
"mutation" -> GQLDirectiveLocation.MUTATION

libraries/apollo-compiler/src/test/validation/operation/directive_variable/directive_variable.expected

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# See https://github.com/apollographql/apollo-kotlin/issues/5112
2+
query Collection($country: String) @inContext(country: $country) {
3+
random
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type Query {
2+
random: String
3+
}
4+
5+
directive @inContext(country: String) on QUERY

0 commit comments

Comments
 (0)