Ejemplo n.º 1
0
    def get_graphql_params(request, data):
        content_type = GraphQLView.get_content_type(request)

        # Only check multipart/form-data if content_type is not None (this is
        # not checked in the original version from `graphene-file-upload`).
        if content_type and 'multipart/form-data' in content_type:
            query, variables, operation_name, id = super(
                FileUploadGraphQLView, FileUploadGraphQLView).get_graphql_params(
                    request, data)
            operations = data.get('operations')
            files_map = data.get('map')
            try:
                operations = json.loads(operations)
                files_map = json.loads(files_map)
                variables = operations.get('variables')
                for file_key in files_map:
                    # file key is which file it is in the form-data
                    file_instances = files_map[file_key]
                    for file_instance in file_instances:
                        test = obj_set(operations, file_instance, file_key, False)
                query = operations.get('query')
                variables = operations.get('variables')
            except Exception as e:
                raise e
        else:
            query, variables, operation_name, id = super(
                FileUploadGraphQLView, FileUploadGraphQLView).get_graphql_params(
                    request, data)
        return query, variables, operation_name, id
Ejemplo n.º 2
0
Archivo: views.py Proyecto: yzqt/saleor
    def get_graphql_params(request, data):
        content_type = GraphQLView.get_content_type(request)

        # Only check multipart/form-data if content_type is not None (this is
        # not checked in the original version from `graphene-file-upload`).
        if content_type and 'multipart/form-data' in content_type:
            query, variables, operation_name, id = super(
                FileUploadGraphQLView,
                FileUploadGraphQLView).get_graphql_params(request, data)
            operations = data.get('operations')
            files_map = data.get('map')
            try:
                operations = json.loads(operations)
                files_map = json.loads(files_map)
                variables = operations.get('variables')
                for file_key in files_map:
                    # file key is which file it is in the form-data
                    file_instances = files_map[file_key]
                    for file_instance in file_instances:
                        test = obj_set(operations, file_instance, file_key,
                                       False)
                query = operations.get('query')
                variables = operations.get('variables')
            except Exception as e:
                raise e
        else:
            query, variables, operation_name, id = super(
                FileUploadGraphQLView,
                FileUploadGraphQLView).get_graphql_params(request, data)
        return query, variables, operation_name, id
Ejemplo n.º 3
0
    def get_graphql_params(request, data):
        query, variables, operation_name, id_ = _GraphQLView.get_graphql_params(
            request,
            data,
        )

        content_type = _GraphQLView.get_content_type(request)
        if content_type == "multipart/form-data":
            operations = json.loads(data.get("operations", "{}"))
            files_map = json.loads(data.get("map", "{}"))
            for k, v in files_map.items():
                for f in v:
                    _obj_set(operations, f, k)
            query = operations.get("query")
            variables = operations.get("variables")

        return query, variables, operation_name, id_
Ejemplo n.º 4
0
    def parse_body(self, request):
        """Analyze the request and based on the content type,
        extract the query from the body as a string or as a JSON payload.

        Args:
            request (HttpRequest): Request object from Django

        Returns:
            dict: GraphQL query
        """
        content_type = GraphQLView.get_content_type(request)

        if content_type == "application/graphql":
            return {"query": request.body.decode()}

        elif content_type == "application/json":
            try:
                return request.data
            except ParseError:
                raise HttpError(HttpResponseBadRequest("Request body contained Invalid JSON."))

        return {}