File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
main/kotlin/com/apurebase/kgraphql/schema/structure
test/kotlin/com/apurebase/kgraphql/specification/language Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -72,10 +72,16 @@ class RequestInterpreter(val schemaModel: SchemaModel) {
7272 OperationTypeNode .SUBSCRIPTION -> schemaModel.subscription ? : throw GraphQLError (" Subscriptions are not supported on this schema" )
7373 }
7474
75- val fragmentDefinitions = test.filterIsInstance<FragmentDefinitionNode >().map { fragmentDef ->
75+ val fragmentDefinitionNode = test.filterIsInstance<FragmentDefinitionNode >()
76+ val fragmentDefinitions = fragmentDefinitionNode.map { fragmentDef ->
7677 val type = schemaModel.allTypesByName.getValue(fragmentDef.typeCondition.name.value)
78+ val name = fragmentDef.name!! .value
7779
78- fragmentDef.name!! .value to (type to fragmentDef.selectionSet)
80+ if (fragmentDefinitionNode.count { it.name!! .value == name } > 1 ) {
81+ throw GraphQLError (" There can be only one fragment named $name ." , fragmentDef )
82+ }
83+
84+ name to (type to fragmentDef.selectionSet)
7985 }.toMap()
8086
8187 val ctx = InterpreterContext (fragmentDefinitions)
Original file line number Diff line number Diff line change @@ -145,4 +145,28 @@ class FragmentsSpecificationTest {
145145 """ )
146146 } shouldThrow GraphQLError ::class withMessage "Fragment spread circular references are not allowed"
147147 }
148+
149+ @Test
150+ fun `queries with duplicated fragments are denied` () {
151+ invoking {
152+ BaseTestSchema .execute("""
153+ {
154+ film {
155+ ...film_title
156+ }
157+ }
158+
159+ fragment film_title on Film {
160+ title
161+ }
162+
163+ fragment film_title on Film {
164+ director {
165+ name
166+ age
167+ }
168+ }
169+ """ )
170+ } shouldThrow GraphQLError ::class withMessage "There can be only one fragment named film_title."
171+ }
148172}
You can’t perform that action at this time.
0 commit comments