You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I am using custom middleware to mesure complexity of graphql query, but it throws an error FragmentSpread' object has no attribute 'selection_set' with custom Middleware when using fragments.
Query example
query{
getProfile(id:1){
...test
}
}
fragment test on ProfileType{
id
}
The middleware
fromgraphql.backend.coreimportGraphQLCoreBackenddefmeasure_depth(selection_set, level=1):
current_depth=levelforfieldinselection_set.selections:
iffield.selection_set:
new_depth=measure_depth(field.selection_set, level=level+1)
ifnew_depth>current_depth:
current_depth=new_depthifnew_depth>3:
raiseException('Query is too nested')
returncurrent_depthclassDepthAnalysisBackend(GraphQLCoreBackend):
defdocument_from_string(self, schema, document_string):
document=super().document_from_string(schema, document_string)
ast=document.document_astfordefinitioninast.definitions:
iflen(definition.selection_set.selections) >1:
raiseException("Query is too complex")
measure_depth(definition.selection_set)
returndocument
How to fix this, and what Fragments use instead of selection_set
The text was updated successfully, but these errors were encountered:
Hello, I am using custom middleware to mesure complexity of graphql query, but it throws an error
FragmentSpread' object has no attribute 'selection_set' with custom Middleware
when using fragments.Query example
The middleware
How to fix this, and what Fragments use instead of selection_set
The text was updated successfully, but these errors were encountered: