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
Per the GQL spec, more than one operation may be contained in the body of a request as long as a specific operation is specified using operationName. ExtraGraphQLView#get_operation_ast returns None in this case and results in the cache not being busted when a mutation does occur.
And I introduced this new method to get a list of all operations included in the payload and bust the cache if any contained a mutation. Having just written this out, I realize this approach is greedy and the specified operationName should be used to determine whether or not that operation is a mutation. But the following does address the broken behavior, if in a heavy handed way.
def get_operations(self, request):
"""
Return list of all operations -- regardless of type -- found in query
"""
data = self.parse_body(request)
query = request.GET.get("query") or data.get("query")
if not query:
return []
source = Source(query, name="GraphQL request")
document_ast = parse(source)
operations = [
definition
for definition in document_ast.definitions
if hasattr(definition, "operation")
]
for operation in operations:
logger.debug(f"operation: {str(operation)} - {operation.operation}")
return operations
# ...
def dispatch(self, request, *args, **kwargs):
operations = self.get_operations(request)
if operations and any(op.operation == OperationType.MUTATION for op in operations):
The text was updated successfully, but these errors were encountered:
Per the GQL spec, more than one operation may be contained in the body of a request as long as a specific operation is specified using
operationName
.ExtraGraphQLView#get_operation_ast
returnsNone
in this case and results in the cache not being busted when a mutation does occur.Here is the test I used to reproduce this:
And I introduced this new method to get a list of all operations included in the payload and bust the cache if any contained a mutation. Having just written this out, I realize this approach is greedy and the specified
operationName
should be used to determine whether or not that operation is a mutation. But the following does address the broken behavior, if in a heavy handed way.The text was updated successfully, but these errors were encountered: