Insert the arguments into the compiled Gremlin query to form a complete query.

    The GraphQL compiler attempts to use single-quoted string literals ('abc') in Gremlin output.
    Double-quoted strings allow inline interpolation with the $ symbol, see here for details:
    http://www.groovy-lang.org/syntax.html#all-strings

    If the compiler needs to emit a literal '$' character as part of the Gremlin query,
    it must be doubled ('$$') to avoid being interpreted as a query parameter.

    Args:
        compilation_result: a CompilationResult object derived from the GraphQL compiler
        arguments: dict, mapping argument name to its value, for every parameter the query expects.

    Returns:
        string, a Gremlin query with inserted argument data

def insert_arguments_into_gremlin_query(compilation_result, arguments):
    """Insert the arguments into the compiled Gremlin query to form a complete query.

    The GraphQL compiler attempts to use single-quoted string literals ('abc') in Gremlin output.
    Double-quoted strings allow inline interpolation with the $ symbol, see here for details:
    http://www.groovy-lang.org/syntax.html#all-strings

    If the compiler needs to emit a literal '$' character as part of the Gremlin query,
    it must be doubled ('$$') to avoid being interpreted as a query parameter.

    Args:
        compilation_result: a CompilationResult object derived from the GraphQL compiler
        arguments: dict, mapping argument name to its value, for every parameter the query expects.

    Returns:
        string, a Gremlin query with inserted argument data
    """
    if compilation_result.language != GREMLIN_LANGUAGE:
        raise AssertionError(u'Unexpected query output language: {}'.format(compilation_result))

    base_query = compilation_result.query
    argument_types = compilation_result.input_metadata

    # The arguments are assumed to have already been validated against the query.
    sanitized_arguments = {
        key: _safe_gremlin_argument(argument_types[key], value)
        for key, value in six.iteritems(arguments)
    }

    return Template(base_query).substitute(sanitized_arguments)